|
8 | 8 | import org.eclipse.lsp4j.CompletionItem;
|
9 | 9 | import org.eclipse.lsp4j.CompletionList;
|
10 | 10 | import org.eclipse.lsp4j.jsonrpc.CompletableFutures;
|
| 11 | +import org.eclipse.lsp4j.DeclarationParams; |
11 | 12 | import org.eclipse.lsp4j.DidOpenTextDocumentParams;
|
12 | 13 | import org.eclipse.lsp4j.DidSaveTextDocumentParams;
|
13 | 14 | import org.eclipse.lsp4j.DidCloseTextDocumentParams;
|
14 | 15 | import org.eclipse.lsp4j.DidChangeTextDocumentParams;
|
15 | 16 | import org.eclipse.lsp4j.DocumentFormattingParams;
|
16 | 17 | import org.eclipse.lsp4j.TextEdit;
|
| 18 | +import org.eclipse.lsp4j.Location; |
| 19 | +import org.eclipse.lsp4j.LocationLink; |
17 | 20 |
|
18 | 21 | import java.util.Collections;
|
19 | 22 | import java.net.URI;
|
| 23 | +import java.util.Optional; |
| 24 | + |
| 25 | +import processing.mode.java.PreprocSketch; |
| 26 | + |
| 27 | +import static org.eclipse.lsp4j.jsonrpc.CompletableFutures.computeAsync; |
| 28 | +import static org.eclipse.lsp4j.jsonrpc.messages.Either.forLeft; |
| 29 | + |
20 | 30 |
|
21 | 31 | class PdeTextDocumentService implements TextDocumentService {
|
22 | 32 | PdeLanguageServer pls;
|
@@ -82,4 +92,49 @@ public CompletableFuture<List<? extends TextEdit>> formatting(DocumentFormatting
|
82 | 92 | })
|
83 | 93 | .orElse(CompletableFuture.completedFuture(Collections.emptyList()));
|
84 | 94 | }
|
| 95 | + |
| 96 | + |
| 97 | + @Override |
| 98 | + public CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> declaration(DeclarationParams params) { |
| 99 | + System.out.println("searching for declaration"); |
| 100 | + |
| 101 | + java.net.URI uri = java.net.URI.create(params.getTextDocument().getUri()); |
| 102 | + int lineNumber = params.getPosition().getLine(); |
| 103 | + int colNumber = params.getPosition().getCharacter(); |
| 104 | + |
| 105 | + Optional<PdeAdapter> adapterOptional = |
| 106 | + pls.getAdapter(uri); |
| 107 | + |
| 108 | + if(adapterOptional.isEmpty()){ |
| 109 | + System.out.println("pde adapter not found"); |
| 110 | + return CompletableFutures.computeAsync(_x -> Either |
| 111 | + .forLeft(Collections.emptyList())); |
| 112 | + } |
| 113 | + |
| 114 | + PdeAdapter adapter = adapterOptional.get(); |
| 115 | + PreprocSketch preprocSketch = adapter.ps; |
| 116 | + Optional<Integer> optionalJavaOffset = adapter.findJavaOffset(uri, |
| 117 | + lineNumber, colNumber); |
| 118 | + |
| 119 | + if(optionalJavaOffset.isEmpty()){ |
| 120 | + System.out.println("javaOffset not found"); |
| 121 | + return CompletableFutures.computeAsync(_x -> Either |
| 122 | + .forLeft(Collections.emptyList())); |
| 123 | + } |
| 124 | + int javaOffset = optionalJavaOffset.get(); |
| 125 | + |
| 126 | + List<? extends Location> locations; |
| 127 | + locations = PdeSymbolFinder.searchDeclaration(preprocSketch, javaOffset); |
| 128 | + |
| 129 | + Optional<CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>>> |
| 130 | + OptCompFutEit = Optional.ofNullable(CompletableFutures |
| 131 | + .computeAsync(_x -> locations)) |
| 132 | + .map(_x -> _x.thenApply(Either::forLeft) |
| 133 | + ); |
| 134 | + |
| 135 | + return OptCompFutEit.orElse( |
| 136 | + computeAsync(_x -> forLeft(Collections.emptyList())) |
| 137 | + ); |
| 138 | + } |
| 139 | + |
85 | 140 | }
|
0 commit comments