From d5ba9854e1d248ee4ab20459b68ffea06aa18a3b Mon Sep 17 00:00:00 2001 From: akosyakov Date: Thu, 26 May 2016 13:39:12 +0200 Subject: [PATCH] [lsi] Extracted an extension class for URI conversion Change-Id: I859efde7f070e871b8be8203fd2a634560c7bac3 Signed-off-by: akosyakov --- .../META-INF/MANIFEST.MF | 2 +- .../xtext/ide/server/LanguageServerImpl.xtend | 18 +++------- .../xtext/ide/server/UriExtensions.xtend | 33 +++++++++++++++++++ .../server/AbstractLanguageServerTest.xtend | 14 ++++---- 4 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend diff --git a/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF b/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF index 7c9806591..8ceab6aee 100644 --- a/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.xtext.ide/META-INF/MANIFEST.MF @@ -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, 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 0f325b996..e092b717f 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 @@ -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 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> diagnosticListeners = newArrayList() diff --git a/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend new file mode 100644 index 000000000..5fff70c87 --- /dev/null +++ b/plugins/org.eclipse.xtext.ide/src/org/eclipse/xtext/ide/server/UriExtensions.xtend @@ -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 + } + +} 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 5971c9520..29022b761 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 @@ -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> diagnostics = newHashMap() @@ -63,12 +65,12 @@ class AbstractLanguageServerTest implements NotificationCallback [ - 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) {