-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Starting the LSP server locally inside the JVM (second take) #7
Merged
angelozerr
merged 9 commits into
angelozerr:master
from
ddekany:pr-embedded-lsp-server-2
Apr 8, 2018
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a17eca
Better .gitignore (copied from FM3, but it was written by me on the f…
ddekany cff6cd9
Extracted Tycho version to a common property (also increased it to 1.…
ddekany f717242
Fixed target-platform name
ddekany 6718cf4
Added short guide to development in Eclipse... which is certainly tot…
ddekany ae37cc1
README.md improvement
ddekany 3d2a4f7
Starting the LSP locally inside the JVM, instead of from as a separat…
ddekany cb96f43
Updated copyright header
ddekany ad1f837
Fixed target platform name typo
ddekany c042e9e
Updated server/freemarker-languageserver-all.jar to use up to date fr…
ddekany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
.settings | ||
/bin | ||
/.project | ||
target | ||
build/ | ||
.out/ | ||
bin/ | ||
.bin/ | ||
target/ | ||
|
||
/gradle.properties | ||
/archive/ | ||
/META-INF | ||
|
||
.classpath | ||
.project | ||
.settings | ||
|
||
.idea/ | ||
*.iml | ||
*.iws | ||
*.ipr | ||
.idea_modules/ | ||
**/out/ | ||
|
||
*.tmp | ||
*.bak | ||
*.swp | ||
*~ | ||
|
||
.gradle | ||
|
||
.DS_Store* | ||
.AppleDouble | ||
.LSOverride | ||
|
||
.directory | ||
.Trash* | ||
|
||
**/adhoctest/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-30.1 KB
(99%)
org.eclipse.lsp4e.freemarker/server/freemarker-languageserver-all.jar
Binary file not shown.
179 changes: 0 additions & 179 deletions
179
org.eclipse.lsp4e.freemarker/src/org/eclipse/lsp4e/freemarker/FreemarkerLanguageServer.java
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
...lsp4e.freemarker/src/org/eclipse/lsp4e/freemarker/FreemarkerStreamConnectionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR, Daniel Dekany. | ||
* 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 | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4e.freemarker; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.Arrays; | ||
import java.util.concurrent.Future; | ||
|
||
import org.eclipse.core.runtime.Platform; | ||
import org.osgi.framework.Bundle; | ||
|
||
/** | ||
* Starts the FreeMarker LSP server inside the current JVM, and connects to it. | ||
*/ | ||
public class FreemarkerStreamConnectionProvider extends LocalStreamConnectionProvider { | ||
|
||
public FreemarkerStreamConnectionProvider() { | ||
super(FreemarkerPlugin.getDefault().getLog(), FreemarkerPlugin.getPluginId()); | ||
} | ||
|
||
private static final String LANGUAGE_SERVER_JAR_ENTRY_NAME = "server/freemarker-languageserver-all.jar"; //$NON-NLS-1$ | ||
private static final String LANGUAGE_SERVER_LAUNCHER_CLASS_NAME = "freemarker.ext.languageserver.FreemarkerServerLauncher"; //$NON-NLS-1$ | ||
|
||
@Override | ||
protected LocalServer launchServer(InputStream clientToServerStream, OutputStream serverToClientStream) | ||
throws IOException { | ||
URL[] classPath = getFreemarkerLanguageServerClassPath(); | ||
logInfo("Using class path: " + Arrays.toString(classPath)); | ||
|
||
URLClassLoader dynamicJarClassLoader = new URLClassLoader(classPath); | ||
|
||
Method launcherMethod; | ||
try { | ||
Class<?> launcherClass = dynamicJarClassLoader.loadClass(LANGUAGE_SERVER_LAUNCHER_CLASS_NAME); | ||
launcherMethod = launcherClass.getMethod("launch", //$NON-NLS-1$ | ||
new Class<?>[] { InputStream.class, OutputStream.class }); | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
"Couldn't get launcher class and method via Java reflection (using class path: " | ||
+ Arrays.toString(classPath) + "); see cause exception", e); //$NON-NLS-2$ | ||
} | ||
Future<?> launchedFuture; | ||
try { | ||
launchedFuture = (Future<?>) launcherMethod.invoke(null, clientToServerStream, serverToClientStream); | ||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { | ||
throw new RuntimeException("Error when calling launcher method; see cause exception", e); //$NON-NLS-1$ | ||
} | ||
|
||
return new LocalServer(launchedFuture) { | ||
@Override | ||
public void stop() { | ||
super.stop(); | ||
try { | ||
dynamicJarClassLoader.close(); | ||
} catch (IOException e) { | ||
logError("Error when closing the dynamic jar class-loader", e); //$NON-NLS-1$ | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private URL[] getFreemarkerLanguageServerClassPath() { | ||
Bundle bundle = Platform.getBundle(FreemarkerPlugin.PLUGIN_ID); | ||
if (bundle == null) { | ||
throw new RuntimeException("Bundle " + FreemarkerPlugin.PLUGIN_ID + " not found"); //$NON-NLS-1$ | ||
} | ||
|
||
URL languageServerJarURL = bundle.getEntry(LANGUAGE_SERVER_JAR_ENTRY_NAME); | ||
if (languageServerJarURL == null) { | ||
throw new RuntimeException( | ||
"Entity " + LANGUAGE_SERVER_JAR_ENTRY_NAME + " not found in bundle " + FreemarkerPlugin.PLUGIN_ID); //$NON-NLS-1$ | ||
} | ||
|
||
// TODO: Add freemarker.jar from the user project here, if it's found and has | ||
// high enough version, otherwise add freemarker.jar from this plugin. | ||
// (Currently, freemarker.jar is bundled into the language server jar.) | ||
|
||
return new URL[] { languageServerJarURL }; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add your name