Skip to content

Commit

Permalink
✨ Adding package search functionality (#62)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Sep 7, 2023
1 parent 6e1ec1c commit ff460a2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ private static SearchPattern getPatternSingleQuery(int location, String query) t
return SearchPattern.createPattern(query, IJavaSearchConstants.TYPE, IJavaSearchConstants.ALL_OCCURRENCES, SearchPattern.R_PATTERN_MATCH);
case 9:
return SearchPattern.createPattern(query, IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, SearchPattern.R_PATTERN_MATCH);
case 11:
return SearchPattern.createPattern(query, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.ALL_OCCURRENCES, SearchPattern.R_PATTERN_MATCH);
}
throw new Exception("unable to create search pattern");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.konveyor.tackle.core.internal.symbol;

import static org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin.logInfo;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.search.ReferenceMatch;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;

public class ReferenceSymbolProvider implements SymbolProvider, WithQuery {
private String query;

@Override
public List<SymbolInformation> get(SearchMatch match) {
SymbolKind k = convertSymbolKind((IJavaElement) match.getElement());
List<SymbolInformation> symbols = new ArrayList<>();
// For Method Calls we will need to do the local variable trick
try {
ReferenceMatch m = (ReferenceMatch) match;

IJavaElement e = (IJavaElement) m.getElement();
SymbolInformation symbol = new SymbolInformation();
symbol.setName(e.getElementName());
symbol.setKind(convertSymbolKind(e));
symbol.setContainerName(e.getParent().getElementName());
symbol.setLocation(getLocation(e, match));
symbols.add(symbol);
} catch (Exception e) {
logInfo("unable to convert for variable: " + e);
}

return symbols;
}
@Override
public void setQuery(String query) {
this.query = query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SymbolProviderResolver {
map.put(8, new ImportSymbolProvider());
map.put(9, new VariableDeclarationSymbolProvider());
map.put(10, new TypeSymbolProvider());
map.put(11, new ReferenceSymbolProvider());
}

public static SymbolProvider resolve(Integer i, SearchMatch SearchMatch) {
Expand Down
2 changes: 1 addition & 1 deletion java-analyzer-bundle.tp/java-analyzer-bundle.target
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner"
includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.ls.core" version="0.0.0" />
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/latest/" />
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/1.26.0.202307271613" />
</location>


Expand Down

0 comments on commit ff460a2

Please sign in to comment.