Skip to content

Commit

Permalink
Fix eclipse#969 Add collecting of declarations in addition to definit…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
travkin79 committed Apr 17, 2024
1 parent 0d8fa0a commit 449103f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.eclipse.lsp4j.CompletionParams;
import org.eclipse.lsp4j.CompletionTriggerKind;
import org.eclipse.lsp4j.CreateFile;
import org.eclipse.lsp4j.DeclarationParams;
import org.eclipse.lsp4j.DefinitionParams;
import org.eclipse.lsp4j.DeleteFile;
import org.eclipse.lsp4j.DiagnosticSeverity;
Expand Down Expand Up @@ -315,6 +316,10 @@ public static DefinitionParams toDefinitionParams(TextDocumentPositionParams par
return toTextDocumentPositionParamsCommon(new DefinitionParams(), params);
}

public static DeclarationParams toDeclarationParams(TextDocumentPositionParams params) {
return toTextDocumentPositionParamsCommon(new DeclarationParams(), params);
}

public static TypeDefinitionParams toTypeDefinitionParams(TextDocumentPositionParams params) {
return toTextDocumentPositionParamsCommon(new TypeDefinitionParams(), params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boo
final var allLinks = new LinkedHashMap<Either<Location, LocationLink>,LSBasedHyperlink>();
try {
var definitions = LanguageServers.forDocument(document).withCapability(ServerCapabilities::getDefinitionProvider)
.collectAll(ls -> ls.getTextDocumentService().definition(LSPEclipseUtils.toDefinitionParams(params)).thenApply(l -> Pair.of(Messages.declarationHyperlinkLabel, l)));
.collectAll(ls -> ls.getTextDocumentService().definition(LSPEclipseUtils.toDefinitionParams(params)).thenApply(l -> Pair.of(Messages.definitionHyperlinkLabel, l)));
var declarations = LanguageServers.forDocument(document).withCapability(ServerCapabilities::getDeclarationProvider)
.collectAll(ls -> ls.getTextDocumentService().declaration(LSPEclipseUtils.toDeclarationParams(params)).thenApply(l -> Pair.of(Messages.declarationHyperlinkLabel, l)));
var typeDefinitions = LanguageServers.forDocument(document).withCapability(ServerCapabilities::getTypeDefinitionProvider)
.collectAll(ls -> ls.getTextDocumentService().typeDefinition(LSPEclipseUtils.toTypeDefinitionParams(params)).thenApply(l -> Pair.of(Messages.typeDefinitionHyperlinkLabel, l)));
var implementations = LanguageServers.forDocument(document).withCapability(ServerCapabilities::getImplementationProvider)
.collectAll(ls -> ls.getTextDocumentService().implementation(LSPEclipseUtils.toImplementationParams(params)).thenApply(l -> Pair.of(Messages.implementationHyperlinkLabel, l)));
LanguageServers.addAll(LanguageServers.addAll(definitions, typeDefinitions), implementations)
LanguageServers.addAll(LanguageServers.addAll(LanguageServers.addAll(definitions, declarations), typeDefinitions), implementations)
.get(800, TimeUnit.MILLISECONDS)
.stream().flatMap(locations -> toHyperlinks(document, region, locations.getFirst(), locations.getSecond()).stream())
.forEach(link -> allLinks.putIfAbsent(link.getLocation(), link));
Expand Down
1 change: 1 addition & 0 deletions org.eclipse.lsp4e/src/org/eclipse/lsp4e/ui/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public final class Messages extends NLS {

public static String definitionHyperlinkLabel;
public static String declarationHyperlinkLabel;
public static String typeDefinitionHyperlinkLabel;
public static String implementationHyperlinkLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# Jan Koehnlein (TypeFox) add rename empty message
# *******************************************************************************/
declarationHyperlinkLabel=Open Declaration
definitionHyperlinkLabel=Open Definition
typeDefinitionHyperlinkLabel=Open Type Definition
implementationHyperlinkLabel=Open Implementation

Expand Down

0 comments on commit 449103f

Please sign in to comment.