-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #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
95 additions
and
7 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...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,66 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Pivotal, Inc. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Gayan Perera <[email protected]> - In project symbol provider implementation | ||
*******************************************************************************/ | ||
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