From 4961f5995d8931ecb0fbca8b79f0187314094d21 Mon Sep 17 00:00:00 2001 From: akosyakov Date: Thu, 26 May 2016 11:20:04 +0200 Subject: [PATCH] [lsi] Fixed remote file's URI to emf's URI conversion Change-Id: I792a9fb29d1bdecaf97590d393be8cb5e7fda69a Signed-off-by: akosyakov --- .../xtext/ide/server/LanguageServerImpl.xtend | 53 +++++++++++-------- .../xtext/ide/server/ServerModule.xtend | 2 + .../xtext/ide/server/WorkspaceManager.xtend | 4 +- .../services/org.eclipse.xtext.ISetup | 1 - .../server/AbstractLanguageServerTest.xtend | 16 +++++- .../ide/tests/server/CompletionTest.xtend | 14 ++--- .../ide/tests/server/OpenDocumentTest.xtend | 19 +++---- .../xtext/ide/tests/server/ServerTest.xtend | 13 ++--- .../services/org.eclipse.xtext.ISetup | 0 9 files changed, 65 insertions(+), 57 deletions(-) delete mode 100644 tests/org.eclipse.xtext.ide.tests/src/META-INF/services/org.eclipse.xtext.ISetup rename tests/org.eclipse.xtext.ide.tests/{ => testlang-src}/META-INF/services/org.eclipse.xtext.ISetup (100%) diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend index 5b666ac0b..0f325b996 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/LanguageServerImpl.xtend @@ -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 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 callback) { + // TODO: auto-generated method stub + } + + override onShowMessageRequest(NotificationCallback callback) { + // TODO: auto-generated method stub + } + + override onLogMessage(NotificationCallback 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 callback) { - throw new UnsupportedOperationException("TODO: auto-generated method stub") - } - - override onShowMessageRequest(NotificationCallback callback) { - throw new UnsupportedOperationException("TODO: auto-generated method stub") - } - - override onLogMessage(NotificationCallback callback) { - throw new UnsupportedOperationException("TODO: auto-generated method stub") - } - override resolveCompletionItem(CompletionItem unresolved) { throw new UnsupportedOperationException("TODO: auto-generated method stub") } diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerModule.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerModule.xtend index 42b4cb71a..6c6e0b9e6 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerModule.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/ServerModule.xtend @@ -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) } diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend index 6b5b145c9..296f85395 100644 --- a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/WorkspaceManager.xtend @@ -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]) } } diff --git a/tests/org.eclipse.xtext.ide.tests/src/META-INF/services/org.eclipse.xtext.ISetup b/tests/org.eclipse.xtext.ide.tests/src/META-INF/services/org.eclipse.xtext.ISetup deleted file mode 100644 index 8a9160246..000000000 --- a/tests/org.eclipse.xtext.ide.tests/src/META-INF/services/org.eclipse.xtext.ISetup +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.xtext.ide.tests.testlanguage.TestLanguageStandaloneSetup \ No newline at end of file diff --git a/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/AbstractLanguageServerTest.xtend b/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/AbstractLanguageServerTest.xtend index 094a4fd70..5971c9520 100644 --- a/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/AbstractLanguageServerTest.xtend +++ b/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/AbstractLanguageServerTest.xtend @@ -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> 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 NotificationCallbackvoid 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 completionItems) ''' diff --git a/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/OpenDocumentTest.xtend b/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/OpenDocumentTest.xtend index 400ad4121..054ed96c4 100644 --- a/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/OpenDocumentTest.xtend +++ b/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/OpenDocumentTest.xtend @@ -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) diff --git a/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend b/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend index abcc0e891..01ea9d93e 100644 --- a/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend +++ b/tests/org.eclipse.xtext.ide.tests/src/org/eclipse/xtext/ide/tests/server/ServerTest.xtend @@ -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' -> ''' diff --git a/tests/org.eclipse.xtext.ide.tests/META-INF/services/org.eclipse.xtext.ISetup b/tests/org.eclipse.xtext.ide.tests/testlang-src/META-INF/services/org.eclipse.xtext.ISetup similarity index 100% rename from tests/org.eclipse.xtext.ide.tests/META-INF/services/org.eclipse.xtext.ISetup rename to tests/org.eclipse.xtext.ide.tests/testlang-src/META-INF/services/org.eclipse.xtext.ISetup