forked from spring-projects/sts4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix spring-projects#173 : Add support for filtering project symbols
Add new provider which will filter symbols for the current selected resource's project in GoTo Symbol dialog.
- Loading branch information
Showing
3 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...c/org/springframework/tooling/ls/eclipse/gotosymbol/dialogs/InProjectSymbolsProvider.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,56 @@ | ||
package org.springframework.tooling.ls.eclipse.gotosymbol.dialogs; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import org.eclipse.core.commands.ExecutionEvent; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.lsp4e.LSPEclipseUtils; | ||
import org.eclipse.lsp4e.LanguageServiceAccessor; | ||
import org.eclipse.lsp4j.DocumentSymbol; | ||
import org.eclipse.lsp4j.Location; | ||
import org.eclipse.lsp4j.SymbolInformation; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
|
||
@SuppressWarnings("restriction") | ||
public class InProjectSymbolsProvider extends InWorkspaceSymbolsProvider { | ||
|
||
private final Predicate<? super Either<SymbolInformation, DocumentSymbol>> FILTER_PREDICATE = e -> { | ||
if(e.isLeft()) { | ||
SymbolInformation symbolInformation = e.getLeft(); | ||
Location location = symbolInformation.getLocation(); | ||
IResource targetResource = LSPEclipseUtils.findResourceFor(location.getUri()); | ||
if (targetResource != null && targetResource.getFullPath() != null) { | ||
return targetResource.getFullPath().toString().startsWith("/" + getProject().getName() + "/"); | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
public InProjectSymbolsProvider(List<LanguageServer> languageServers, IProject project) { | ||
super(languageServers, project); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "Symbols in Project"; | ||
} | ||
|
||
public static InWorkspaceSymbolsProvider createFor(ExecutionEvent event) { | ||
final IProject project = InWorkspaceSymbolsProvider.projectFor(event); | ||
final List<LanguageServer> languageServers = LanguageServiceAccessor.getLanguageServers(project, | ||
capabilities -> Boolean.TRUE.equals(capabilities.getWorkspaceSymbolProvider()), true); | ||
if (!languageServers.isEmpty()) { | ||
return new InProjectSymbolsProvider(languageServers, project); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
protected Predicate<? super Either<SymbolInformation, DocumentSymbol>> symbolFilter() { | ||
return FILTER_PREDICATE; | ||
} | ||
|
||
} |
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