mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
[lsi] Extracted an extension class for URI conversion
Change-Id: I859efde7f070e871b8be8203fd2a634560c7bac3 Signed-off-by: akosyakov <anton.kosyakov@typefox.io>
This commit is contained in:
parent
4961f5995d
commit
d5ba9854e1
4 changed files with 47 additions and 20 deletions
|
@ -4,7 +4,7 @@ Bundle-Name: %pluginName
|
|||
Bundle-SymbolicName: org.eclipse.xtext.ide;singleton:=true
|
||||
Bundle-Version: 2.10.0.qualifier
|
||||
Bundle-Localization: plugin
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Vendor: %providerName
|
||||
Require-Bundle: org.eclipse.xtext;visibility:=reexport,
|
||||
|
|
|
@ -47,7 +47,6 @@ import io.typefox.lsapi.TextDocumentService
|
|||
import io.typefox.lsapi.WindowService
|
||||
import io.typefox.lsapi.WorkspaceService
|
||||
import io.typefox.lsapi.WorkspaceSymbolParams
|
||||
import java.nio.file.Paths
|
||||
import java.util.List
|
||||
import org.eclipse.emf.common.util.URI
|
||||
import org.eclipse.xtend.lib.annotations.Accessors
|
||||
|
@ -67,6 +66,7 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
InitializeParams params
|
||||
@Inject Provider<WorkspaceManager> workspaceManagerProvider
|
||||
WorkspaceManager workspaceManager
|
||||
@Inject extension UriExtensions
|
||||
@Inject extension IResourceServiceProvider.Registry languagesRegistry
|
||||
|
||||
override InitializeResult initialize(InitializeParams params) {
|
||||
|
@ -87,16 +87,18 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
|
||||
override exit() {
|
||||
}
|
||||
|
||||
|
||||
override void shutdown() {
|
||||
}
|
||||
|
||||
|
||||
override getTextDocumentService() {
|
||||
this
|
||||
}
|
||||
|
||||
override getWorkspaceService() {
|
||||
this
|
||||
}
|
||||
|
||||
override getWindowService() {
|
||||
this
|
||||
}
|
||||
|
@ -134,16 +136,6 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
}
|
||||
// end file/content change events
|
||||
|
||||
protected def URI toUri(String path) {
|
||||
return URI.createURI(Paths.get(path).toString)
|
||||
}
|
||||
|
||||
protected def String toPath(URI uri) {
|
||||
val javaURI = java.net.URI.create(uri.toString)
|
||||
val path = Paths.get(javaURI)
|
||||
return path.toUri.toString
|
||||
}
|
||||
|
||||
// validation stuff
|
||||
|
||||
private List<NotificationCallback<PublishDiagnosticsParams>> diagnosticListeners = newArrayList()
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2016 TypeFox GmbH (http://www.typefox.io) and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.server
|
||||
|
||||
import com.google.inject.Singleton
|
||||
import java.nio.file.Paths
|
||||
import org.eclipse.emf.common.util.URI
|
||||
|
||||
/**
|
||||
* @author kosyakov - Initial contribution and API
|
||||
*/
|
||||
@Singleton
|
||||
class UriExtensions {
|
||||
|
||||
def URI toUri(String path) {
|
||||
return URI.createURI(Paths.get(path).toString)
|
||||
}
|
||||
|
||||
def String toPath(URI uri) {
|
||||
return java.net.URI.create(uri.toString).toPath
|
||||
}
|
||||
|
||||
def String toPath(java.net.URI uri) {
|
||||
val path = Paths.get(uri)
|
||||
return path.toUri.toString
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@ import java.util.List
|
|||
import java.util.Map
|
||||
import org.eclipse.xtext.ide.server.LanguageServerImpl
|
||||
import org.eclipse.xtext.ide.server.ServerModule
|
||||
import org.eclipse.xtext.ide.server.UriExtensions
|
||||
import org.eclipse.xtext.util.Files
|
||||
import org.junit.Before
|
||||
|
||||
|
@ -43,6 +44,7 @@ class AbstractLanguageServerTest implements NotificationCallback<PublishDiagnost
|
|||
root.deleteOnExit
|
||||
}
|
||||
|
||||
@Inject extension UriExtensions
|
||||
@Inject protected LanguageServerImpl languageServer
|
||||
protected Map<String, List<? extends Diagnostic>> diagnostics = newHashMap()
|
||||
|
||||
|
@ -63,12 +65,12 @@ class AbstractLanguageServerTest implements NotificationCallback<PublishDiagnost
|
|||
val file = new File(root, path)
|
||||
file.parentFile.mkdirs
|
||||
file.createNewFile
|
||||
new FileWriter(file) => [
|
||||
write(contents.toString)
|
||||
close
|
||||
]
|
||||
val normalizedPath = file.toPath().normalize
|
||||
return normalizedPath.toUri.toString
|
||||
|
||||
val writer = new FileWriter(file)
|
||||
writer.write(contents.toString)
|
||||
writer.close
|
||||
|
||||
return file.toURI.normalize.toPath
|
||||
}
|
||||
|
||||
override call(PublishDiagnosticsParams t) {
|
||||
|
|
Loading…
Reference in a new issue