summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2017-03-18 01:14:37 -0700
committerGeorge Fraser <george@fivetran.com>2017-03-18 01:14:37 -0700
commit9b251a1e2ff52e82132427193d062ece48c266b2 (patch)
tree1a2b85f243b90a1893b5b77b1836da3af69f47c7
parent0ac0d9ea3667ab3f2b74f0ab05168a7a8ae7a08b (diff)
downloadjava-language-server-9b251a1e2ff52e82132427193d062ece48c266b2.zip
Update all versions, log output
-rw-r--r--.vscodeignore1
-rw-r--r--README.md3
-rw-r--r--lib/Main.ts10
-rw-r--r--package.json19
-rw-r--r--pom.xml16
-rwxr-xr-xscripts/install.sh2
-rw-r--r--src/main/java/org/javacs/AutocompleteVisitor.java33
-rw-r--r--src/main/java/org/javacs/JavaLanguageServer.java168
-rw-r--r--src/main/java/org/javacs/LoggingFormat.java17
-rw-r--r--src/main/java/org/javacs/Main.java76
-rw-r--r--src/main/java/org/javacs/ShowMessageException.java10
-rw-r--r--src/main/java/org/javacs/SymbolIndex.java19
-rw-r--r--src/test/java/org/javacs/AutocompleteTest.java9
-rw-r--r--src/test/java/org/javacs/Fixtures.java11
-rw-r--r--src/test/java/org/javacs/GotoTest.java19
-rw-r--r--src/test/resources/org/javacs/example/Bad.java4
-rw-r--r--tsd.json12
-rw-r--r--typings/portfinder.d.ts7
-rw-r--r--typings/tsd.d.ts2
19 files changed, 169 insertions, 269 deletions
diff --git a/.vscodeignore b/.vscodeignore
index 71d1478..100483a 100644
--- a/.vscodeignore
+++ b/.vscodeignore
@@ -12,7 +12,6 @@ tsd.json
*.log*
# Sources
-typings/**
src/**
test/**
lib/**
diff --git a/README.md b/README.md
index 7133c75..14b6546 100644
--- a/README.md
+++ b/README.md
@@ -273,8 +273,7 @@ the parent directory of each javaconfig.json will be treated as a separate java
## Logs
-The java service process will output a log file with a name like 'javac-services.0.log'
-in your project directory.
+The java service process will output a log file to stdout, which is visible using View / Output.
## Contributing
diff --git a/lib/Main.ts b/lib/Main.ts
index e7e580a..2e8e8ea 100644
--- a/lib/Main.ts
+++ b/lib/Main.ts
@@ -9,8 +9,6 @@ import * as Net from 'net';
import * as ChildProcess from 'child_process';
import {LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, StreamInfo} from 'vscode-languageclient';
-PortFinder.basePort = 55282;
-
/** Called when extension is activated */
export function activate(context: VSCode.ExtensionContext) {
let javaExecutablePath = findJavaExecutable('java');
@@ -41,12 +39,16 @@ export function activate(context: VSCode.ExtensionContext) {
VSCode.workspace.createFileSystemWatcher('**/javaconfig.json'),
VSCode.workspace.createFileSystemWatcher('**/*.java')
]
- }
+ },
+ outputChannelName: 'Java',
+ revealOutputChannelOn: 3
}
function createServer(): Promise<StreamInfo> {
return new Promise((resolve, reject) => {
- PortFinder.getPort((err, port) => {
+ PortFinder.getPort({port: 55282}, (err, port) => {
+ port = 55282;
+
let fatJar = Path.resolve(context.extensionPath, "out", "fat-jar.jar");
let args = [
diff --git a/package.json b/package.json
index cf291e3..6b771dd 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
},
"license": "MIT",
"engines": {
- "vscode": "^0.10.10"
+ "vscode": "^1.7.0"
},
"categories": [
"Languages",
@@ -54,18 +54,21 @@
},
"preview": "true",
"scripts": {
- "vscode:prepublish": "node ./node_modules/vscode/bin/compile",
- "compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
+ "vscode:prepublish": "tsc -p ./",
+ "compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "mocha out/test"
},
"dependencies": {
- "portfinder": "^0.4.0",
- "vscode-languageclient": "2.2.1"
+ "portfinder": "^1.0.13",
+ "vscode-languageclient": "3.2.0"
},
"devDependencies": {
- "typescript": "^1.8.5",
- "vscode": "^0.11.0",
- "mocha": "^2.4.5"
+ "typescript": "^2.2.1",
+ "vscode": "^1.1.0",
+ "mocha": "^2.4.5",
+ "@types/node": "^6.0.40",
+ "@types/mocha": "^2.2.32",
+ "@types/es6-promise": "^0.0.32"
}
} \ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 07c61e2..ed1bcfd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,19 +45,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</dependency>
<!-- Java implementation of VS Code language server protocol -->
<dependency>
- <groupId>io.typefox.lsapi</groupId>
- <artifactId>io.typefox.lsapi</artifactId>
- <version>${lsApiVersion}</version>
- </dependency>
- <dependency>
- <groupId>io.typefox.lsapi</groupId>
- <artifactId>io.typefox.lsapi.services</artifactId>
- <version>${lsApiVersion}</version>
- </dependency>
- <dependency>
- <groupId>io.typefox.lsapi</groupId>
- <artifactId>io.typefox.lsapi.annotations</artifactId>
- <version>${lsApiVersion}</version>
+ <groupId>org.eclipse.lsp4j</groupId>
+ <artifactId>org.eclipse.lsp4j</artifactId>
+ <version>0.1.2</version>
</dependency>
<!-- JSON -->
<dependency>
diff --git a/scripts/install.sh b/scripts/install.sh
index 112a845..7dfcaab 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -8,4 +8,4 @@ mvn package
vsce package -o build.vsix
# Install vsix
-code build.vsix \ No newline at end of file
+code --install-extension build.vsix \ No newline at end of file
diff --git a/src/main/java/org/javacs/AutocompleteVisitor.java b/src/main/java/org/javacs/AutocompleteVisitor.java
index aee1686..6c445ff 100644
--- a/src/main/java/org/javacs/AutocompleteVisitor.java
+++ b/src/main/java/org/javacs/AutocompleteVisitor.java
@@ -12,9 +12,8 @@ import com.sun.tools.javac.model.JavacElements;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.Name;
-import io.typefox.lsapi.CompletionItem;
-import io.typefox.lsapi.CompletionItemKind;
-import io.typefox.lsapi.impl.CompletionItemImpl;
+import org.eclipse.lsp4j.CompletionItem;
+import org.eclipse.lsp4j.CompletionItemKind;
import javax.lang.model.element.*;
import javax.lang.model.type.*;
@@ -26,7 +25,7 @@ import java.util.logging.Logger;
public class AutocompleteVisitor extends CursorScanner {
private static final Logger LOG = Logger.getLogger("main");
- public final List<CompletionItemImpl> suggestions = new ArrayList<>();
+ public final List<CompletionItem> suggestions = new ArrayList<>();
public AutocompleteVisitor(JavaFileObject file, long cursor, Context context) {
super(file, cursor, context);
@@ -48,7 +47,7 @@ public class AutocompleteVisitor extends CursorScanner {
if (type == null)
LOG.warning("No type for " + expression);
else if (isClassReference(expression)) {
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Property);
item.setLabel("class");
@@ -73,7 +72,7 @@ public class AutocompleteVisitor extends CursorScanner {
if (p.owner != null && p.owner.getQualifiedName().equals(prefix)) {
Name end = p.getSimpleName();
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Module);
item.setLabel(end.toString());
@@ -88,7 +87,7 @@ public class AutocompleteVisitor extends CursorScanner {
if (c.owner != null && c.owner.getQualifiedName().equals(prefix)) {
Name end = c.getSimpleName();
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Class);
item.setLabel(end.toString());
@@ -117,7 +116,7 @@ public class AutocompleteVisitor extends CursorScanner {
if (containsCursor(expression))
super.visitReference(node);
else if (isClassReference(expression)) {
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Method);
item.setLabel("new");
@@ -232,7 +231,7 @@ public class AutocompleteVisitor extends CursorScanner {
Name name = symbol.getSimpleName();
String insertText = name.toString();
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Constructor);
item.setLabel(name.toString());
@@ -409,7 +408,7 @@ public class AutocompleteVisitor extends CursorScanner {
case ANNOTATION_TYPE:
case INTERFACE:
case TYPE_PARAMETER: {
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
// TODO more kinds
item.setKind(CompletionItemKind.Class);
@@ -422,7 +421,7 @@ public class AutocompleteVisitor extends CursorScanner {
break;
}
case ENUM_CONSTANT: {
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Enum);
item.setLabel(name);
@@ -441,7 +440,7 @@ public class AutocompleteVisitor extends CursorScanner {
case PARAMETER:
case LOCAL_VARIABLE:
case EXCEPTION_PARAMETER: {
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Variable);
item.setLabel(name);
@@ -479,7 +478,7 @@ public class AutocompleteVisitor extends CursorScanner {
private void addEnumConstant(Symbol.VarSymbol e, int superRemoved) {
String label = e.getSimpleName().toString();
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Enum);
item.setLabel(label);
@@ -494,7 +493,7 @@ public class AutocompleteVisitor extends CursorScanner {
private void addClass(Symbol.ClassSymbol e, int superRemoved) {
String label = e.getSimpleName().toString();
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Class);
item.setLabel(label);
@@ -509,7 +508,7 @@ public class AutocompleteVisitor extends CursorScanner {
private void addMethod(Symbol.MethodSymbol e, int superRemoved) {
String label = methodSignature(e);
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Method);
item.setLabel(label);
@@ -587,7 +586,7 @@ public class AutocompleteVisitor extends CursorScanner {
private void addField(Symbol.VarSymbol e, int sortOrder) {
String name = e.getSimpleName().toString();
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setKind(CompletionItemKind.Property);
item.setLabel(name);
@@ -614,7 +613,7 @@ public class AutocompleteVisitor extends CursorScanner {
public void visitArray(ArrayType t) {
if (!isStatic) {
// Array types just have 'length'
- CompletionItemImpl item = new CompletionItemImpl();
+ CompletionItem item = new CompletionItem();
item.setLabel("length");
item.setInsertText("length");
diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java
index d5ac7d8..9f27d83 100644
--- a/src/main/java/org/javacs/JavaLanguageServer.java
+++ b/src/main/java/org/javacs/JavaLanguageServer.java
@@ -4,9 +4,9 @@ import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.tree.TreeScanner;
-import io.typefox.lsapi.services.*;
-import io.typefox.lsapi.*;
-import io.typefox.lsapi.impl.*;
+import org.eclipse.lsp4j.Diagnostic;
+import org.eclipse.lsp4j.services.*;
+import org.eclipse.lsp4j.*;
import javax.tools.*;
import java.io.*;
@@ -16,8 +16,9 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CompletableFuture;
-import java.util.function.Consumer;
+import java.util.logging.Handler;
import java.util.logging.Level;
+import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -31,9 +32,8 @@ import static org.javacs.Main.JSON;
class JavaLanguageServer implements LanguageServer {
private static final Logger LOG = Logger.getLogger("main");
private Path workspaceRoot;
- private Consumer<PublishDiagnosticsParams> publishDiagnostics = p -> {};
- private Consumer<MessageParams> showMessage = m -> {};
private Map<Path, String> activeDocuments = new HashMap<>();
+ private LanguageClient client;
public JavaLanguageServer() {
this.testJavac = Optional.empty();
@@ -45,7 +45,7 @@ class JavaLanguageServer implements LanguageServer {
public void onError(String message, Throwable error) {
if (error instanceof ShowMessageException)
- showMessage.accept(((ShowMessageException) error).message);
+ client.showMessage(((ShowMessageException) error).message);
else if (error instanceof NoJavaConfigException) {
// Swallow error
// If you want to show a message for no-java-config,
@@ -55,12 +55,12 @@ class JavaLanguageServer implements LanguageServer {
else {
LOG.log(Level.SEVERE, message, error);
- MessageParamsImpl m = new MessageParamsImpl();
+ MessageParams m = new MessageParams();
m.setMessage(message);
m.setType(MessageType.Error);
- showMessage.accept(m);
+ client.showMessage(m);
}
}
@@ -68,13 +68,13 @@ class JavaLanguageServer implements LanguageServer {
public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
workspaceRoot = Paths.get(params.getRootPath()).toAbsolutePath().normalize();
- InitializeResultImpl result = new InitializeResultImpl();
+ InitializeResult result = new InitializeResult();
- ServerCapabilitiesImpl c = new ServerCapabilitiesImpl();
+ ServerCapabilities c = new ServerCapabilities();
c.setTextDocumentSync(TextDocumentSyncKind.Incremental);
c.setDefinitionProvider(true);
- c.setCompletionProvider(new CompletionOptionsImpl());
+ c.setCompletionProvider(new CompletionOptions());
c.setHoverProvider(true);
c.setWorkspaceSymbolProvider(true);
c.setReferencesProvider(true);
@@ -86,8 +86,8 @@ class JavaLanguageServer implements LanguageServer {
}
@Override
- public void shutdown() {
-
+ public CompletableFuture<Object> shutdown() {
+ return CompletableFuture.completedFuture(null);
}
@Override
@@ -96,11 +96,6 @@ class JavaLanguageServer implements LanguageServer {
}
@Override
- public void onTelemetryEvent(Consumer<Object> consumer) {
- // Nothing to do
- }
-
- @Override
public TextDocumentService getTextDocumentService() {
return new TextDocumentService() {
@Override
@@ -246,11 +241,6 @@ class JavaLanguageServer implements LanguageServer {
if (maybePath.isPresent())
doLint(activeDocuments.keySet());
}
-
- @Override
- public void onPublishDiagnostics(Consumer<PublishDiagnosticsParams> callback) {
- publishDiagnostics = callback;
- }
};
}
@@ -387,39 +377,19 @@ class JavaLanguageServer implements LanguageServer {
}
};
}
-
- @Override
- public WindowService getWindowService() {
- return new WindowService() {
- @Override
- public void onShowMessage(Consumer<MessageParams> callback) {
- showMessage = callback;
- }
-
- @Override
- public void onShowMessageRequest(Consumer<ShowMessageRequestParams> callback) {
-
- }
-
- @Override
- public void onLogMessage(Consumer<MessageParams> callback) {
-
- }
- };
- }
private void publishDiagnostics(Collection<Path> paths, DiagnosticCollector<JavaFileObject> errors) {
- Map<URI, PublishDiagnosticsParamsImpl> files = new HashMap<>();
+ Map<URI, PublishDiagnosticsParams> files = new HashMap<>();
paths.forEach(p -> files.put(p.toUri(), newPublishDiagnostics(p.toUri())));
errors.getDiagnostics().forEach(error -> {
if (error.getStartPosition() != javax.tools.Diagnostic.NOPOS) {
URI uri = error.getSource().toUri();
- PublishDiagnosticsParamsImpl publish = files.computeIfAbsent(uri, this::newPublishDiagnostics);
+ PublishDiagnosticsParams publish = files.computeIfAbsent(uri, this::newPublishDiagnostics);
- RangeImpl range = position(error);
- DiagnosticImpl diagnostic = new DiagnosticImpl();
+ Range range = position(error);
+ Diagnostic diagnostic = new Diagnostic();
DiagnosticSeverity severity = severity(error.getKind());
diagnostic.setSeverity(severity);
@@ -431,7 +401,7 @@ class JavaLanguageServer implements LanguageServer {
}
});
- files.values().forEach(publishDiagnostics::accept);
+ files.values().forEach(d -> client.publishDiagnostics(d));
}
private DiagnosticSeverity severity(javax.tools.Diagnostic.Kind kind) {
@@ -448,8 +418,8 @@ class JavaLanguageServer implements LanguageServer {
}
}
- private PublishDiagnosticsParamsImpl newPublishDiagnostics(URI newUri) {
- PublishDiagnosticsParamsImpl p = new PublishDiagnosticsParamsImpl();
+ private PublishDiagnosticsParams newPublishDiagnostics(URI newUri) {
+ PublishDiagnosticsParams p = new PublishDiagnosticsParams();
p.setDiagnostics(new ArrayList<>());
p.setUri(newUri.toString());
@@ -658,7 +628,7 @@ class JavaLanguageServer implements LanguageServer {
try {
return JSON.readValue(configFile.toFile(), JavaConfigJson.class);
} catch (IOException e) {
- MessageParamsImpl message = new MessageParamsImpl();
+ MessageParams message = new MessageParams();
message.setMessage("Error reading " + configFile);
message.setType(MessageType.Error);
@@ -679,7 +649,7 @@ class JavaLanguageServer implements LanguageServer {
.map(dir::resolve)
.collect(Collectors.toSet());
} catch (IOException e) {
- MessageParamsImpl message = new MessageParamsImpl();
+ MessageParams message = new MessageParams();
message.setMessage("Error reading " + classPathFilePath);
message.setType(MessageType.Error);
@@ -695,18 +665,18 @@ class JavaLanguageServer implements LanguageServer {
return compiler.fileManager.getRegularFile(path.toFile());
}
- private RangeImpl position(javax.tools.Diagnostic<? extends JavaFileObject> error) {
+ private Range position(javax.tools.Diagnostic<? extends JavaFileObject> error) {
// Compute start position
- PositionImpl start = new PositionImpl();
+ Position start = new Position();
start.setLine((int) (error.getLineNumber() - 1));
start.setCharacter((int) (error.getColumnNumber() - 1));
// Compute end position
- PositionImpl end = endPosition(error);
+ Position end = endPosition(error);
// Combine into Range
- RangeImpl range = new RangeImpl();
+ Range range = new Range();
range.setStart(start);
range.setEnd(end);
@@ -714,7 +684,7 @@ class JavaLanguageServer implements LanguageServer {
return range;
}
- private PositionImpl endPosition(javax.tools.Diagnostic<? extends JavaFileObject> error) {
+ private Position endPosition(javax.tools.Diagnostic<? extends JavaFileObject> error) {
try (Reader reader = error.getSource().openReader(true)) {
long startOffset = error.getStartPosition();
long endOffset = error.getEndPosition();
@@ -735,7 +705,7 @@ class JavaLanguageServer implements LanguageServer {
column++;
}
- PositionImpl end = new PositionImpl();
+ Position end = new Position();
end.setLine(line);
end.setCharacter(column);
@@ -866,9 +836,9 @@ class JavaLanguageServer implements LanguageServer {
}
/**
- * Convert on offset-based range to a {@link io.typefox.lsapi.Range}
+ * Convert on offset-based range to a {@link Range}
*/
- public static RangeImpl findPosition(JavaFileObject file, long startOffset, long endOffset) {
+ public static Range findPosition(JavaFileObject file, long startOffset, long endOffset) {
try (Reader in = file.openReader(true)) {
long offset = 0;
int line = 0;
@@ -891,7 +861,7 @@ class JavaLanguageServer implements LanguageServer {
}
}
- PositionImpl start = createPosition(line, character);
+ Position start = createPosition(line, character);
// Find the end position
while (offset < endOffset) {
@@ -910,10 +880,10 @@ class JavaLanguageServer implements LanguageServer {
}
}
- PositionImpl end = createPosition(line, character);
+ Position end = createPosition(line, character);
// Combine into range
- RangeImpl range = new RangeImpl();
+ Range range = new Range();
range.setStart(start);
range.setEnd(end);
@@ -924,8 +894,8 @@ class JavaLanguageServer implements LanguageServer {
}
}
- private static PositionImpl createPosition(int line, int character) {
- PositionImpl p = new PositionImpl();
+ private static Position createPosition(int line, int character) {
+ Position p = new Position();
p.setLine(line);
p.setCharacter(character);
@@ -969,9 +939,9 @@ class JavaLanguageServer implements LanguageServer {
}
}
- private HoverImpl doHover(TextDocumentPositionParams position) {
- HoverImpl result = new HoverImpl();
- List<MarkedStringImpl> contents = new ArrayList<>();
+ private Hover doHover(TextDocumentPositionParams position) {
+ Hover result = new Hover();
+ List<String> contents = new ArrayList<>();
result.setContents(contents);
@@ -985,23 +955,23 @@ class JavaLanguageServer implements LanguageServer {
findSymbol(compilationUnit, line, character).ifPresent(symbol -> {
switch (symbol.getKind()) {
case PACKAGE:
- contents.add(markedString("package " + symbol.getQualifiedName()));
+ contents.add("package " + symbol.getQualifiedName());
break;
case ENUM:
- contents.add(markedString("enum " + symbol.getQualifiedName()));
+ contents.add("enum " + symbol.getQualifiedName());
break;
case CLASS:
- contents.add(markedString("class " + symbol.getQualifiedName()));
+ contents.add("class " + symbol.getQualifiedName());
break;
case ANNOTATION_TYPE:
- contents.add(markedString("@interface " + symbol.getQualifiedName()));
+ contents.add("@interface " + symbol.getQualifiedName());
break;
case INTERFACE:
- contents.add(markedString("interface " + symbol.getQualifiedName()));
+ contents.add("interface " + symbol.getQualifiedName());
break;
case METHOD:
@@ -1012,7 +982,7 @@ class JavaLanguageServer implements LanguageServer {
String signature = AutocompleteVisitor.methodSignature(method);
String returnType = ShortTypePrinter.print(method.getReturnType());
- contents.add(markedString(returnType + " " + signature));
+ contents.add(returnType + " " + signature);
break;
case PARAMETER:
@@ -1020,7 +990,7 @@ class JavaLanguageServer implements LanguageServer {
case EXCEPTION_PARAMETER:
case ENUM_CONSTANT:
case FIELD:
- contents.add(markedString(ShortTypePrinter.print(symbol.type)));
+ contents.add(ShortTypePrinter.print(symbol.type));
break;
case TYPE_PARAMETER:
@@ -1034,17 +1004,8 @@ class JavaLanguageServer implements LanguageServer {
return result;
}
- private MarkedStringImpl markedString(String value) {
- MarkedStringImpl result = new MarkedStringImpl();
-
- result.setLanguage("java");
- result.setValue(value);
-
- return result;
- }
-
public CompletionList autocomplete(TextDocumentPositionParams position) {
- CompletionListImpl result = new CompletionListImpl();
+ CompletionList result = new CompletionList();
result.setIsIncomplete(false);
result.setItems(new ArrayList<>());
@@ -1105,4 +1066,39 @@ class JavaLanguageServer implements LanguageServer {
throw ShowMessageException.error("Error reading " + file, e);
}
}
+
+ public void installClient(LanguageClient client) {
+ this.client = client;
+
+ Logger.getLogger("").addHandler(new Handler() {
+ @Override
+ public void publish(LogRecord record) {
+ client.logMessage(new MessageParams(
+ messageType(record.getLevel().intValue()),
+ record.getMessage()
+ ));
+ }
+
+ private MessageType messageType(int level) {
+ if (level >= Level.SEVERE.intValue())
+ return MessageType.Error;
+ else if (level >= Level.WARNING.intValue())
+ return MessageType.Warning;
+ else if (level >= Level.INFO.intValue())
+ return MessageType.Info;
+ else
+ return MessageType.Log;
+ }
+
+ @Override
+ public void flush() {
+
+ }
+
+ @Override
+ public void close() throws SecurityException {
+
+ }
+ });
+ }
}
diff --git a/src/main/java/org/javacs/LoggingFormat.java b/src/main/java/org/javacs/LoggingFormat.java
index de90580..a98b92d 100644
--- a/src/main/java/org/javacs/LoggingFormat.java
+++ b/src/main/java/org/javacs/LoggingFormat.java
@@ -47,21 +47,4 @@ public class LoggingFormat extends Formatter {
else
return Integer.toString(i);
}
-
- private static boolean started = false;
-
- public static void startLogging() throws IOException {
- if (!started) {
- started = true;
-
- Logger root = Logger.getLogger("");
-
- FileHandler file = new FileHandler("javac-services.%g.log", 100_000, 1, false);
-
- root.addHandler(file);
-
- for (Handler h : root.getHandlers())
- h.setFormatter(new LoggingFormat());
- }
- }
}
diff --git a/src/main/java/org/javacs/Main.java b/src/main/java/org/javacs/Main.java
index 456b716..fba3490 100644
--- a/src/main/java/org/javacs/Main.java
+++ b/src/main/java/org/javacs/Main.java
@@ -7,18 +7,12 @@ import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
-import io.typefox.lsapi.Message;
-import io.typefox.lsapi.services.json.LanguageServerToJsonAdapter;
-import io.typefox.lsapi.services.json.MessageJsonHandler;
-import io.typefox.lsapi.services.json.StreamMessageReader;
-import io.typefox.lsapi.services.json.StreamMessageWriter;
-import io.typefox.lsapi.services.launch.LanguageServerLauncher;
-import io.typefox.lsapi.services.transport.io.ConcurrentMessageReader;
-import io.typefox.lsapi.services.transport.io.MessageReader;
-import io.typefox.lsapi.services.transport.server.LanguageServerEndpoint;
-import io.typefox.lsapi.services.transport.trace.MessageTracer;
+import org.eclipse.lsp4j.jsonrpc.Launcher;
+import org.eclipse.lsp4j.launch.LSPLauncher;
+import org.eclipse.lsp4j.services.LanguageClient;
import java.net.InetSocketAddress;
+import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.io.*;
@@ -62,8 +56,6 @@ public class Main {
public static void main(String[] args) throws IOException {
try {
- LoggingFormat.startLogging();
-
Connection connection = connectToNode();
run(connection);
@@ -77,32 +69,26 @@ public class Main {
private static Connection connectToNode() throws IOException {
String port = System.getProperty("javacs.port");
- if (port != null) {
- Socket socket = new Socket("localhost", Integer.parseInt(port));
+ Objects.requireNonNull(port, "-Djavacs.port=? is required");
- InputStream in = socket.getInputStream();
- OutputStream out = socket.getOutputStream();
+ LOG.info("Connecting to " + port);
- OutputStream intercept = new OutputStream() {
+ Socket socket = new Socket("localhost", Integer.parseInt(port));
- @Override
- public void write(int b) throws IOException {
- out.write(b);
- }
- };
+ InputStream in = socket.getInputStream();
+ OutputStream out = socket.getOutputStream();
- LOG.info("Connected to parent using socket on port " + port);
+ OutputStream intercept = new OutputStream() {
- return new Connection(in, intercept);
- }
- else {
- InputStream in = System.in;
- PrintStream out = System.out;
+ @Override
+ public void write(int b) throws IOException {
+ out.write(b);
+ }
+ };
- LOG.info("Connected to parent using stdio");
+ LOG.info("Connected to parent using socket on port " + port);
- return new Connection(in, out);
- }
+ return new Connection(in, intercept);
}
private static class Connection {
@@ -121,33 +107,11 @@ public class Main {
* When the request stream is closed, wait for 5s for all outstanding responses to compute, then return.
*/
public static void run(Connection connection) {
- MessageJsonHandler handler = new MessageJsonHandler();
- StreamMessageReader reader = new StreamMessageReader(connection.in, handler);
- StreamMessageWriter writer = new StreamMessageWriter(connection.out, handler);
JavaLanguageServer server = new JavaLanguageServer();
- LanguageServerEndpoint endpoint = new LanguageServerEndpoint(server);
-
- endpoint.setMessageTracer(new MessageTracer() {
- @Override
- public void onError(String message, Throwable err) {
- LOG.log(Level.SEVERE, message, err);
- }
-
- @Override
- public void onRead(Message message, String s) {
-
- }
-
- @Override
- public void onWrite(Message message, String s) {
-
- }
- });
-
- reader.setOnError(err -> LOG.log(Level.SEVERE, err.getMessage(), err));
- writer.setOnError(err -> LOG.log(Level.SEVERE, err.getMessage(), err));
+ Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, connection.in, connection.out);
- endpoint.connect(reader, writer);
+ server.installClient(launcher.getRemoteProxy());
+ launcher.startListening();
LOG.info("Connection closed");
}
diff --git a/src/main/java/org/javacs/ShowMessageException.java b/src/main/java/org/javacs/ShowMessageException.java
index f749d86..81f526b 100644
--- a/src/main/java/org/javacs/ShowMessageException.java
+++ b/src/main/java/org/javacs/ShowMessageException.java
@@ -1,8 +1,7 @@
package org.javacs;
-import io.typefox.lsapi.MessageParams;
-import io.typefox.lsapi.MessageType;
-import io.typefox.lsapi.impl.MessageParamsImpl;
+import org.eclipse.lsp4j.services.*;
+import org.eclipse.lsp4j.*;
public class ShowMessageException extends RuntimeException {
public final MessageParams message;
@@ -22,10 +21,7 @@ public class ShowMessageException extends RuntimeException {
}
private static ShowMessageException create(MessageType type, String message, Exception cause) {
- MessageParamsImpl m = new MessageParamsImpl();
-
- m.setMessage(message);
- m.setType(type);
+ MessageParams m = new MessageParams(type, message);
return new ShowMessageException(m, cause);
}
diff --git a/src/main/java/org/javacs/SymbolIndex.java b/src/main/java/org/javacs/SymbolIndex.java
index aad5c43..56bc247 100644
--- a/src/main/java/org/javacs/SymbolIndex.java
+++ b/src/main/java/org/javacs/SymbolIndex.java
@@ -17,8 +17,7 @@ import com.sun.tools.javac.tree.*;
import com.sun.tools.javac.code.*;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Name;
-import io.typefox.lsapi.*;
-import io.typefox.lsapi.impl.*;
+import org.eclipse.lsp4j.*;
/**
* Global index of exported symbol declarations and references.
@@ -251,7 +250,7 @@ public class SymbolIndex {
private void addDeclaration(JCTree tree, Symbol symbol) {
if (symbol != null && onSourcePath(symbol) && shouldIndex(symbol)) {
String key = uniqueName(symbol);
- SymbolInformationImpl info = symbolInformation(tree, symbol, compilationUnit);
+ SymbolInformation info = symbolInformation(tree, symbol, compilationUnit);
Map<String, SymbolInformation> withKind = index.declarations.computeIfAbsent(symbol.getKind(), newKind -> new HashMap<>());
withKind.put(key, info);
@@ -263,7 +262,7 @@ public class SymbolIndex {
String key = uniqueName(symbol);
Map<String, Set<Location>> withKind = index.references.computeIfAbsent(symbol.getKind(), newKind -> new HashMap<>());
Set<Location> locations = withKind.computeIfAbsent(key, newName -> new HashSet<>());
- LocationImpl location = location(tree, compilationUnit);
+ Location location = location(tree, compilationUnit);
locations.add(location);
}
@@ -291,9 +290,9 @@ public class SymbolIndex {
}
}
- private static SymbolInformationImpl symbolInformation(JCTree tree, Symbol symbol, JCTree.JCCompilationUnit compilationUnit) {
- LocationImpl location = location(tree, compilationUnit);
- SymbolInformationImpl info = new SymbolInformationImpl();
+ private static SymbolInformation symbolInformation(JCTree tree, Symbol symbol, JCTree.JCCompilationUnit compilationUnit) {
+ Location location = location(tree, compilationUnit);
+ SymbolInformation info = new SymbolInformation();
info.setContainerName(symbol.getEnclosingElement().getQualifiedName().toString());
info.setKind(symbolInformationKind(symbol.getKind()));
@@ -309,7 +308,7 @@ public class SymbolIndex {
return info;
}
- public static LocationImpl location(JCTree tree, JCTree.JCCompilationUnit compilationUnit) {
+ public static Location location(JCTree tree, JCTree.JCCompilationUnit compilationUnit) {
try {
// Declaration should include offset
int offset = tree.pos;
@@ -333,10 +332,10 @@ public class SymbolIndex {
end = offset + symbol.name.length();
}
- RangeImpl position = JavaLanguageServer.findPosition(compilationUnit.getSourceFile(),
+ Range position = JavaLanguageServer.findPosition(compilationUnit.getSourceFile(),
offset,
end);
- LocationImpl location = new LocationImpl();
+ Location location = new Location();
location.setUri(compilationUnit.getSourceFile().toUri().toString());
location.setRange(position);
diff --git a/src/test/java/org/javacs/AutocompleteTest.java b/src/test/java/org/javacs/AutocompleteTest.java
index b06d72d..1f0a3eb 100644
--- a/src/test/java/org/javacs/AutocompleteTest.java
+++ b/src/test/java/org/javacs/AutocompleteTest.java
@@ -1,7 +1,6 @@
package org.javacs;
-import io.typefox.lsapi.*;
-import io.typefox.lsapi.impl.*;
+import org.eclipse.lsp4j.*;
import org.junit.Ignore;
import org.junit.Test;
@@ -419,12 +418,12 @@ public class AutocompleteTest extends Fixtures {
}
private List<? extends CompletionItem> items(String file, int row, int column) {
- TextDocumentPositionParamsImpl position = new TextDocumentPositionParamsImpl();
+ TextDocumentPositionParams position = new TextDocumentPositionParams();
- position.setPosition(new PositionImpl());
+ position.setPosition(new Position());
position.getPosition().setLine(row);
position.getPosition().setCharacter(column);
- position.setTextDocument(new TextDocumentIdentifierImpl());
+ position.setTextDocument(new TextDocumentIdentifier());
position.getTextDocument().setUri(uri(file).toString());
JavaLanguageServer server = getJavaLanguageServer();
diff --git a/src/test/java/org/javacs/Fixtures.java b/src/test/java/org/javacs/Fixtures.java
index 926ca68..f3c6db6 100644
--- a/src/test/java/org/javacs/Fixtures.java
+++ b/src/test/java/org/javacs/Fixtures.java
@@ -1,6 +1,6 @@
package org.javacs;
-import io.typefox.lsapi.impl.InitializeParamsImpl;
+import org.eclipse.lsp4j.InitializeParams;
import org.junit.BeforeClass;
import java.io.IOException;
@@ -10,13 +10,6 @@ import java.util.Collections;
import java.util.Set;
public class Fixtures {
- static {
- try {
- LoggingFormat.startLogging();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
public static void init() { }
@@ -27,7 +20,7 @@ public class Fixtures {
JavacHolder javac = new JavacHolder(classPath, sourcePath, outputDirectory);
JavaLanguageServer server = new JavaLanguageServer(javac);
- InitializeParamsImpl init = new InitializeParamsImpl();
+ InitializeParams init = new InitializeParams();
String workspaceRoot = Paths.get(".").toAbsolutePath().toString();
init.setRootPath(workspaceRoot);
diff --git a/src/test/java/org/javacs/GotoTest.java b/src/test/java/org/javacs/GotoTest.java
index 2566f45..afda170 100644
--- a/src/test/java/org/javacs/GotoTest.java
+++ b/src/test/java/org/javacs/GotoTest.java
@@ -1,7 +1,6 @@
package org.javacs;
-import io.typefox.lsapi.*;
-import io.typefox.lsapi.impl.*;
+import org.eclipse.lsp4j.*;
import org.junit.Ignore;
import org.junit.Test;
@@ -101,23 +100,23 @@ public class GotoTest extends Fixtures {
assertThat(suggestions, contains(location(uri, 2, 18, 2, 23)));
}
- private LocationImpl location(URI uri, int startRow, int startColumn, int endRow, int endColumn) {
- PositionImpl start = new PositionImpl();
+ private Location location(URI uri, int startRow, int startColumn, int endRow, int endColumn) {
+ Position start = new Position();
start.setLine(startRow);
start.setCharacter(startColumn);
- PositionImpl end = new PositionImpl();
+ Position end = new Position();
end.setLine(startRow);
end.setCharacter(endColumn);
- RangeImpl range = new RangeImpl();
+ Range range = new Range();
range.setStart(start);
range.setEnd(end);
- LocationImpl location = new LocationImpl();
+ Location location = new Location();
location.setUri(uri.toString());
location.setRange(range);
@@ -126,16 +125,16 @@ public class GotoTest extends Fixtures {
}
private List<? extends Location> doGoto(String file, int row, int column) throws IOException {
- TextDocumentIdentifierImpl document = new TextDocumentIdentifierImpl();
+ TextDocumentIdentifier document = new TextDocumentIdentifier();
document.setUri(uri(file).toString());
- PositionImpl position = new PositionImpl();
+ Position position = new Position();
position.setLine(row);
position.setCharacter(column);
- TextDocumentPositionParamsImpl p = new TextDocumentPositionParamsImpl();
+ TextDocumentPositionParams p = new TextDocumentPositionParams();
p.setTextDocument(document);
p.setPosition(position);
diff --git a/src/test/resources/org/javacs/example/Bad.java b/src/test/resources/org/javacs/example/Bad.java
index 8d876a9..eef4765 100644
--- a/src/test/resources/org/javacs/example/Bad.java
+++ b/src/test/resources/org/javacs/example/Bad.java
@@ -1,8 +1,8 @@
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeScanner;
-import io.typefox.lsapi.Location;
-import io.typefox.lsapi.LocationImpl;
+import org.eclipse.lsp4j.Location;
+import org.eclipse.lsp4j.LocationImpl;
import java.net.URI;
import java.util.ArrayList;
diff --git a/tsd.json b/tsd.json
deleted file mode 100644
index 50cd71d..0000000
--- a/tsd.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "version": "v4",
- "repo": "borisyankov/DefinitelyTyped",
- "ref": "master",
- "path": "typings",
- "bundle": "typings/tsd.d.ts",
- "installed": {
- "node/node.d.ts": {
- "commit": "d22516f9f089de107d7e7d5938566377370631f6"
- }
- }
-}
diff --git a/typings/portfinder.d.ts b/typings/portfinder.d.ts
deleted file mode 100644
index 554fa8d..0000000
--- a/typings/portfinder.d.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-declare module 'portfinder' {
- var basePort: number;
-
- function getPort(callback: (err: any, port: number) => void);
-} \ No newline at end of file
diff --git a/typings/tsd.d.ts b/typings/tsd.d.ts
deleted file mode 100644
index 2916e4c..0000000
--- a/typings/tsd.d.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-/// <reference path="portfinder.d.ts" />
-/// <reference path="../node_modules/vscode/typings/index.d.ts" /> \ No newline at end of file