diff options
author | George Fraser <george@fivetran.com> | 2019-01-02 21:44:31 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2019-01-02 21:44:31 -0800 |
commit | ad06e0d42d72160502790188d0a8c5fe3a09bdf3 (patch) | |
tree | 9767e3b26fb869efe761cfadd06a6ef8685fd9fe /src/main/java/org/javacs/JavaLanguageServer.java | |
parent | df3561c5d6f268711e184de0c30de0454ac40fd3 (diff) | |
download | java-language-server-ad06e0d42d72160502790188d0a8c5fe3a09bdf3.zip |
Cleanup
Diffstat (limited to 'src/main/java/org/javacs/JavaLanguageServer.java')
-rw-r--r-- | src/main/java/org/javacs/JavaLanguageServer.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java index 0a442ba..e9ebb18 100644 --- a/src/main/java/org/javacs/JavaLanguageServer.java +++ b/src/main/java/org/javacs/JavaLanguageServer.java @@ -774,6 +774,7 @@ class JavaLanguageServer extends LanguageServer { // Figure out what file toEl is declared in LOG.info(String.format("...looking for definition of `%s`", toEl.get())); + // TODO this should include overrides of toEl var toUri = hoverCache.declaringFile(toEl.get()); if (!toUri.isPresent()) { LOG.info(String.format("...couldn't find declaring file, giving up")); @@ -855,19 +856,30 @@ class JavaLanguageServer extends LanguageServer { public List<Location> findReferences(ReferenceParams position) { var toUri = position.textDocument.uri; if (!isJavaFile(toUri)) return List.of(); - var toContent = contents(toUri).content; - updateHoverCache(toUri, toContent); var toLine = position.position.line + 1; var toColumn = position.position.character + 1; + var toContent = contents(toUri).content; + + // Compile from-file and identify element under cursor + LOG.warning(String.format("Looking for references to %s(%d,%d)...", toUri.getPath(), toLine, toColumn)); + updateHoverCache(toUri, toContent); var toEl = hoverCache.element(toLine, toColumn); if (!toEl.isPresent()) { - LOG.warning(String.format("No element under cursor %s(%d,%d)", toUri.getPath(), toLine, toColumn)); + LOG.warning("...no element under cursor"); return List.of(); } + + // Compile all files that *might* contain references to toEl var fromFiles = compiler.potentialReferences(toEl.get()); if (fromFiles.isEmpty()) return List.of(); var batch = compiler.compileBatch(fromFiles); - var fromTreePaths = batch.references(toEl.get()); // Why does this work? These are two different batches + + // Find toEl again, so that we have an Element from the current batch + var toElAgain = batch.element(toUri, toLine, toColumn).get(); + + // Find all references to toElAgain + // TODO this should references to supers of toEl + var fromTreePaths = batch.references(toElAgain); var result = new ArrayList<Location>(); for (var path : fromTreePaths) { var fromUri = path.getCompilationUnit().getSourceFile().toUri(); @@ -1348,8 +1360,13 @@ class JavaLanguageServer extends LanguageServer { } @Override + public Optional<RenameResponse> prepareRename(TextDocumentPositionParams params) { + throw new RuntimeException("TODO"); + } + + @Override public WorkspaceEdit rename(RenameParams params) { - return null; // TODO + throw new RuntimeException("TODO"); } private boolean isJavaFile(URI uri) { |