mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
[lsi] Fixed remote file's URI to emf's URI conversion
Change-Id: I792a9fb29d1bdecaf97590d393be8cb5e7fda69a Signed-off-by: akosyakov <anton.kosyakov@typefox.io>
This commit is contained in:
parent
41be0aa99f
commit
4961f5995d
9 changed files with 65 additions and 57 deletions
|
@ -39,6 +39,7 @@ import io.typefox.lsapi.PublishDiagnosticsParamsImpl
|
|||
import io.typefox.lsapi.RangeImpl
|
||||
import io.typefox.lsapi.ReferenceParams
|
||||
import io.typefox.lsapi.RenameParams
|
||||
import io.typefox.lsapi.ServerCapabilities
|
||||
import io.typefox.lsapi.ServerCapabilitiesImpl
|
||||
import io.typefox.lsapi.ShowMessageRequestParams
|
||||
import io.typefox.lsapi.TextDocumentPositionParams
|
||||
|
@ -46,6 +47,7 @@ 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
|
||||
|
@ -65,16 +67,16 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
InitializeParams params
|
||||
@Inject Provider<WorkspaceManager> workspaceManagerProvider
|
||||
WorkspaceManager workspaceManager
|
||||
String rootPath
|
||||
@Inject extension IResourceServiceProvider.Registry languagesRegistry
|
||||
|
||||
override InitializeResult initialize(InitializeParams params) {
|
||||
this.params = params
|
||||
this.rootPath = URI.createFileURI(params.rootPath).toString
|
||||
workspaceManager = workspaceManagerProvider.get
|
||||
workspaceManager.initialize(URI.createFileURI(params.rootPath), [ this.publishDiagnostics($0, $1) ])
|
||||
val rootURI = URI.createFileURI(params.rootPath)
|
||||
workspaceManager.initialize(rootURI)[this.publishDiagnostics($0, $1)]
|
||||
return new InitializeResultImpl => [
|
||||
capabilities = new ServerCapabilitiesImpl => [
|
||||
textDocumentSync = ServerCapabilities.SYNC_INCREMENTAL
|
||||
completionProvider = new CompletionOptionsImpl => [
|
||||
resolveProvider = false
|
||||
triggerCharacters = #["."]
|
||||
|
@ -132,12 +134,14 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
}
|
||||
// end file/content change events
|
||||
|
||||
def URI toUri(String path) {
|
||||
URI.createURI(rootPath + path)
|
||||
protected def URI toUri(String path) {
|
||||
return URI.createURI(Paths.get(path).toString)
|
||||
}
|
||||
|
||||
def toPath(URI uri) {
|
||||
uri.toString.substring(rootPath.length)
|
||||
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
|
||||
|
@ -169,8 +173,8 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
}
|
||||
message = issue.message
|
||||
range = newRange(
|
||||
newPosition(issue.lineNumber,issue.column),
|
||||
newPosition(issue.lineNumber,issue.column + issue.length)
|
||||
newPosition(issue.lineNumber - 1, issue.column - 1),
|
||||
newPosition(issue.lineNumber - 1, issue.column - 1 + issue.length)
|
||||
)
|
||||
]
|
||||
}
|
||||
|
@ -180,7 +184,7 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
// completion stuff
|
||||
|
||||
override completion(TextDocumentPositionParams params) {
|
||||
val uri = toUri(params.textDocument?.uri ?: params.uri)
|
||||
val uri = params.textDocument.uri.toUri
|
||||
val resourceServiceProvider = uri.resourceServiceProvider
|
||||
val contentAssistService = resourceServiceProvider?.get(ContentAssistService)
|
||||
if (contentAssistService === null)
|
||||
|
@ -203,6 +207,22 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
|
||||
// end completion stuff
|
||||
|
||||
// notification callbacks
|
||||
|
||||
override onShowMessage(NotificationCallback<MessageParams> callback) {
|
||||
// TODO: auto-generated method stub
|
||||
}
|
||||
|
||||
override onShowMessageRequest(NotificationCallback<ShowMessageRequestParams> callback) {
|
||||
// TODO: auto-generated method stub
|
||||
}
|
||||
|
||||
override onLogMessage(NotificationCallback<MessageParams> callback) {
|
||||
// TODO: auto-generated method stub
|
||||
}
|
||||
|
||||
// end notification callbacks
|
||||
|
||||
override symbol(WorkspaceSymbolParams params) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
@ -211,19 +231,6 @@ import static io.typefox.lsapi.util.LsapiFactories.*
|
|||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
||||
|
||||
override onShowMessage(NotificationCallback<MessageParams> callback) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
||||
override onShowMessageRequest(NotificationCallback<ShowMessageRequestParams> callback) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
||||
override onLogMessage(NotificationCallback<MessageParams> callback) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
||||
override resolveCompletionItem(CompletionItem unresolved) {
|
||||
throw new UnsupportedOperationException("TODO: auto-generated method stub")
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
package org.eclipse.xtext.ide.server
|
||||
|
||||
import com.google.inject.AbstractModule
|
||||
import io.typefox.lsapi.LanguageServer
|
||||
import org.eclipse.xtext.resource.IResourceServiceProvider
|
||||
import org.eclipse.xtext.resource.ResourceServiceProviderServiceLoader
|
||||
|
||||
|
@ -17,6 +18,7 @@ import org.eclipse.xtext.resource.ResourceServiceProviderServiceLoader
|
|||
class ServerModule extends AbstractModule {
|
||||
|
||||
override protected configure() {
|
||||
bind(LanguageServer).to(LanguageServerImpl)
|
||||
bind(IResourceServiceProvider.Registry).toProvider(ResourceServiceProviderServiceLoader)
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,9 @@ class WorkspaceManager {
|
|||
//TODO sort projects by dependency
|
||||
val allDirty = new ArrayList(dirtyFiles)
|
||||
for (entry : baseDir2ProjectManager.entrySet) {
|
||||
val result = entry.value.doBuild(allDirty.filter[isPrefix(entry.key)].toList, deletedFiles.filter[isPrefix(entry.key)].toList)
|
||||
val projectDirtyFiles = allDirty.filter[isPrefix(entry.key)].toList
|
||||
val projectDeletedFiles = deletedFiles.filter[isPrefix(entry.key)].toList
|
||||
val result = entry.value.doBuild(projectDirtyFiles, projectDeletedFiles)
|
||||
allDirty.addAll(result.affectedResources.map[uri])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup
|
|
@ -10,6 +10,8 @@ package org.eclipse.xtext.ide.tests.server
|
|||
import com.google.inject.Guice
|
||||
import com.google.inject.Inject
|
||||
import io.typefox.lsapi.Diagnostic
|
||||
import io.typefox.lsapi.InitializeParamsImpl
|
||||
import io.typefox.lsapi.InitializeResult
|
||||
import io.typefox.lsapi.NotificationCallback
|
||||
import io.typefox.lsapi.PublishDiagnosticsParams
|
||||
import java.io.File
|
||||
|
@ -45,6 +47,17 @@ class AbstractLanguageServerTest implements NotificationCallback<PublishDiagnost
|
|||
protected Map<String, List<? extends Diagnostic>> diagnostics = newHashMap()
|
||||
|
||||
protected File root
|
||||
|
||||
protected def InitializeResult initialize() {
|
||||
return initialize(null)
|
||||
}
|
||||
|
||||
protected def InitializeResult initialize((InitializeParamsImpl)=>void initializer) {
|
||||
val params = new InitializeParamsImpl
|
||||
params.rootPath = root.toPath.toAbsolutePath.normalize.toString
|
||||
initializer?.apply(params)
|
||||
return languageServer.initialize(params)
|
||||
}
|
||||
|
||||
def String ->(String path, CharSequence contents) {
|
||||
val file = new File(root, path)
|
||||
|
@ -54,7 +67,8 @@ class AbstractLanguageServerTest implements NotificationCallback<PublishDiagnost
|
|||
write(contents.toString)
|
||||
close
|
||||
]
|
||||
return file.absolutePath.substring(root.absolutePath.length)
|
||||
val normalizedPath = file.toPath().normalize
|
||||
return normalizedPath.toUri.toString
|
||||
}
|
||||
|
||||
override call(PublishDiagnosticsParams t) {
|
||||
|
|
|
@ -9,7 +9,6 @@ package org.eclipse.xtext.ide.tests.server
|
|||
|
||||
import io.typefox.lsapi.CompletionItem
|
||||
import io.typefox.lsapi.DidOpenTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.InitializeParamsImpl
|
||||
import io.typefox.lsapi.PositionImpl
|
||||
import io.typefox.lsapi.TextDocumentIdentifierImpl
|
||||
import io.typefox.lsapi.TextDocumentItemImpl
|
||||
|
@ -27,7 +26,7 @@ class CompletionTest extends AbstractLanguageServerTest {
|
|||
|
||||
@Test
|
||||
def void testCompletion_01() {
|
||||
testComletion [
|
||||
testCompletion [
|
||||
expectedCompletionItems = '''
|
||||
type
|
||||
'''
|
||||
|
@ -36,7 +35,7 @@ class CompletionTest extends AbstractLanguageServerTest {
|
|||
|
||||
@Test
|
||||
def void testCompletion_02() {
|
||||
testComletion [
|
||||
testCompletion [
|
||||
model = 'type '
|
||||
caretColumn = 5
|
||||
expectedCompletionItems = '''
|
||||
|
@ -47,7 +46,7 @@ class CompletionTest extends AbstractLanguageServerTest {
|
|||
|
||||
@Test
|
||||
def void testCompletion_03() {
|
||||
testComletion [
|
||||
testCompletion [
|
||||
model = '''
|
||||
type Foo {}
|
||||
type Bar {}
|
||||
|
@ -66,14 +65,12 @@ class CompletionTest extends AbstractLanguageServerTest {
|
|||
]
|
||||
}
|
||||
|
||||
protected def testComletion((TestCompletionConfiguration)=>void configurator) {
|
||||
protected def testCompletion((TestCompletionConfiguration)=>void configurator) {
|
||||
val extension configuration = new TestCompletionConfiguration
|
||||
configurator.apply(configuration)
|
||||
val fileUri = filePath -> model
|
||||
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
initialize
|
||||
|
||||
languageServer.didOpen(new DidOpenTextDocumentParamsImpl => [
|
||||
textDocument = new TextDocumentItemImpl => [
|
||||
|
@ -95,7 +92,6 @@ class CompletionTest extends AbstractLanguageServerTest {
|
|||
|
||||
val actualCompletionItems = toExpectation(completionItems)
|
||||
assertEquals(expectedCompletionItems, actualCompletionItems)
|
||||
|
||||
}
|
||||
|
||||
protected def String toExpectation(List<? extends CompletionItem> completionItems) '''
|
||||
|
|
|
@ -7,22 +7,21 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.xtext.ide.tests.server
|
||||
|
||||
import io.typefox.lsapi.DidChangeTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.DidChangeWatchedFilesParamsImpl
|
||||
import io.typefox.lsapi.DidCloseTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.DidOpenTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.FileEvent
|
||||
import io.typefox.lsapi.FileEventImpl
|
||||
import io.typefox.lsapi.InitializeParamsImpl
|
||||
import io.typefox.lsapi.PositionImpl
|
||||
import io.typefox.lsapi.RangeImpl
|
||||
import io.typefox.lsapi.TextDocumentContentChangeEventImpl
|
||||
import io.typefox.lsapi.TextDocumentIdentifierImpl
|
||||
import io.typefox.lsapi.TextDocumentItemImpl
|
||||
import io.typefox.lsapi.VersionedTextDocumentIdentifierImpl
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import io.typefox.lsapi.DidChangeTextDocumentParamsImpl
|
||||
import io.typefox.lsapi.VersionedTextDocumentIdentifierImpl
|
||||
import io.typefox.lsapi.TextDocumentContentChangeEventImpl
|
||||
import io.typefox.lsapi.RangeImpl
|
||||
import io.typefox.lsapi.PositionImpl
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -36,9 +35,7 @@ class OpenDocumentTest extends AbstractLanguageServerTest {
|
|||
NonExisting foo
|
||||
}
|
||||
'''
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
initialize
|
||||
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.get(firstFile).head.message)
|
||||
|
||||
|
@ -86,9 +83,7 @@ class OpenDocumentTest extends AbstractLanguageServerTest {
|
|||
NonExisting foo
|
||||
}
|
||||
'''
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
initialize
|
||||
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.get(firstFile).head.message)
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ package org.eclipse.xtext.ide.tests.server
|
|||
import io.typefox.lsapi.DidChangeWatchedFilesParamsImpl
|
||||
import io.typefox.lsapi.FileEvent
|
||||
import io.typefox.lsapi.FileEventImpl
|
||||
import io.typefox.lsapi.InitializeParamsImpl
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
@ -27,9 +26,7 @@ class ServerTest extends AbstractLanguageServerTest {
|
|||
string foo
|
||||
}
|
||||
'''
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
initialize
|
||||
assertTrue(diagnostics.entrySet.join(','), diagnostics.values.head.empty)
|
||||
}
|
||||
|
||||
|
@ -40,9 +37,7 @@ class ServerTest extends AbstractLanguageServerTest {
|
|||
NonExisting foo
|
||||
}
|
||||
'''
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
initialize
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.values.head.head?.message)
|
||||
}
|
||||
|
||||
|
@ -53,9 +48,7 @@ class ServerTest extends AbstractLanguageServerTest {
|
|||
NonExisting foo
|
||||
}
|
||||
'''
|
||||
languageServer.initialize(new InitializeParamsImpl => [
|
||||
rootPath = root.absolutePath
|
||||
])
|
||||
initialize
|
||||
assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", diagnostics.values.head.head.message)
|
||||
|
||||
val path = 'MyType2.testlang' -> '''
|
||||
|
|
Loading…
Reference in a new issue