@Override public boolean handleResult( ExtendedLanguageServer element, List<? extends Location> locations) { locations.forEach( o -> { o.setUri(removePrefixUri(o.getUri())); result.add(new LocationDto(o)); }); return true; } },
@Override public boolean handleResult( ExtendedLanguageServer element, List<? extends Location> locations) { locations.forEach( o -> { o.setUri(removePrefixUri(o.getUri())); result.add(new LocationDto(o)); }); return true; } },
public static Location fixLocation(Location o) { o.setUri(removePrefixUri(o.getUri())); return o; }
@Override public Optional<Location> gotoDefinition(URI uri, Position position) { List<Location> possibleLocations = indexer.getGotoReferenced().keySet().stream() .filter(loc -> uri.equals(URI.create(loc.getUri())) && Ranges.contains(loc.getRange(), position)) // If there is more than one result, we want the symbol whose range starts the latest, with a secondary // sort of earliest end range. .sorted((l1, l2) -> Ranges.POSITION_COMPARATOR.compare(l1.getRange().getEnd(), l2.getRange().getEnd())) .sorted((l1, l2) -> Ranges.POSITION_COMPARATOR.reversed().compare(l1.getRange().getStart(), l2.getRange().getStart())) .collect(Collectors.toList()); if (possibleLocations.isEmpty()) { return Optional.absent(); } return indexer.gotoReferenced(possibleLocations.get(0)); }
Location locationToElement = JDTUtils.toLocation(linkTarget); if (locationToElement != null) { return locationToElement.getUri() + "#" + (locationToElement.getRange().getStart().getLine() + 1);
public void assertDocumentSymbols(String... symbolsAndContainers) throws Exception { Arrays.sort(symbolsAndContainers); StringBuilder expected = new StringBuilder(); for (String string : symbolsAndContainers) { expected.append(string+"\n"); } List<? extends SymbolInformation> actualSymbols = getDocumentSymbols(); List<String> actuals = new ArrayList<>(); for (SymbolInformation actualSymbol : actualSymbols) { assertEquals(doc.getUri(), actualSymbol.getLocation().getUri()); String coveredText = getText(actualSymbol.getLocation().getRange()); assertEquals(actualSymbol.getName(), coveredText); actuals.add(coveredText + "|" + actualSymbol.getContainerName()); } Collections.sort(actuals); StringBuilder actual = new StringBuilder(); for (String string : actuals) { actual.append(string+"\n"); } assertEquals(expected.toString(), actual.toString()); }
@Override public boolean handleResult( ExtendedLanguageServer server, List<? extends SymbolInformation> locations) { locations.forEach( location -> { String uri = location.getLocation().getUri(); String wsPath = languageServerPathTransformer.toWsPath(server.getId(), uri); location.getLocation().setUri(wsPath); result.add(new SymbolInformationDto(location)); }); return true; } },
private static Location fixLocation(IJavaElement element, Location location, IJavaProject javaProject) { if (!javaProject.equals(element.getJavaProject()) && element.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) { // see issue at: https://github.com/eclipse/eclipse.jdt.ls/issues/842 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=541573 // for jdk classes, jdt will reuse the java model by altering project to share the model between projects // so that sometimes the project for `element` is default project and the project is different from the project for `unit` // this fix is to replace the project name with non-default ones since default project should be transparent to users. if (location.getUri().contains(ProjectsManager.DEFAULT_PROJECT_NAME)) { String patched = StringUtils.replaceOnce(location.getUri(), ProjectsManager.DEFAULT_PROJECT_NAME, javaProject.getProject().getName()); try { IClassFile cf = (IClassFile) JavaCore.create(JDTUtils.toURI(patched).getQuery()); if (cf != null && cf.exists()) { location.setUri(patched); } } catch (Exception ex) { } } } return location; }
public LocationDto(org.eclipse.lsp4j.Location o) { if (o.getUri() == null) { setUri((java.lang.String)null); } else { java.lang.String uriVal = (java.lang.String)makeDto(o.getUri());; setUri((java.lang.String)uriVal); } if (o.getRange() == null) { setRange((org.eclipse.lsp4j.Range)null); } else { org.eclipse.lsp4j.Range rangeVal = new RangeDto(o.getRange()); setRange((org.eclipse.lsp4j.Range)rangeVal); } }
Location clone(Location location) { if (location == null) { return null; } Range range = location.getRange(); String uri = location.getUri(); Location cloned = new Location(); cloned.setRange(clone(range)); cloned.setUri(uri); return cloned; }
@Override public boolean handleResult( ExtendedLanguageServer element, List<Either<SymbolInformation, DocumentSymbol>> locations) { locations.forEach( o -> { // minimal fix for https://github.com/eclipse/che/issues/11139 when updating // lsp4j if (o.isLeft()) { SymbolInformation si = o.getLeft(); si.getLocation().setUri(removePrefixUri(si.getLocation().getUri())); result.add(new SymbolInformationDto(si)); } else { URI uri = languageServerPathTransformer.toFsURI(element.getId(), wsPath); result.addAll(convertDocumentSymbol(o.getRight(), uri.toString())); } }); return true; }
.filter(loc -> paramsUri.toString().equals(loc.getUri()) && Ranges.isValid(loc.getRange()) && Ranges.contains(loc.getRange(), params.getPosition())
@Override public void visitPropertyExpression(PropertyExpression expression) { if (expression.getObjectExpression() instanceof VariableExpression) { // This means it's a non static reference to a class variable VariableExpression var = (VariableExpression) expression.getObjectExpression(); FieldNode field = var.getType().getField(expression.getProperty().getText()); if (classes.containsKey(var.getType().getName())) { indexer.addReference(createLocation(URI.create(classes.get(var.getType().getName()).getUri()), field), createLocation(expression.getProperty())); } } else if (expression.getObjectExpression() instanceof ClassExpression) { // This means it's a static reference to a class variable ClassExpression classExpression = (ClassExpression) expression.getObjectExpression(); FieldNode field = classExpression.getType().getField(expression.getProperty().getText()); if (classes.containsKey(classExpression.getType().getName())) { indexer.addReference( createLocation(URI.create(classes.get(classExpression.getType().getName()).getUri()), field), createLocation(expression.getProperty())); } } super.visitPropertyExpression(expression); }
private SpanElement createTitleOfElement(SymbolInformation symbolInformation) { String path = symbolInformation.getLocation().getUri(); SpanElement texElement = Elements.createSpanElement(); SpanElement highlightElement = Elements.createSpanElement(javaResources.css().presentableTextContainer()); highlightElement.setInnerText(" - (" + path + ')'); texElement.setInnerText(symbolInformation.getName()); texElement.appendChild(highlightElement); return texElement; }
si.setContainerName(element.getParent().getElementName()); location.setUri(ResourceUtils.toClientUri(location.getUri())); si.setLocation(location); if (!symbols.contains(si)) {
.forEach(method -> { indexer.addReference( createLocation(URI.create(classes.get(parentClass.getName()).getUri()), method), createLocation(call)); });