/** * The range enclosing this symbol not including leading/trailing whitespace but everything else * like comments. */ public Range getRange(final EObject object) { Location _newFullLocation = this._documentExtensions.newFullLocation(object); Range _range = null; if (_newFullLocation!=null) { _range=_newFullLocation.getRange(); } return _range; }
/** * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function. */ public Range getSelectionRange(final EObject object) { Location _newLocation = this._documentExtensions.newLocation(object); Range _range = null; if (_newLocation!=null) { _range=_newLocation.getRange(); } return _range; } }
private Range getRange(IJavaElement element) throws JavaModelException { Location location = JDTUtils.toLocation(element, FULL_RANGE); return location == null ? DEFAULT_RANGE : location.getRange(); }
private Range getSelectionRange(IJavaElement element) throws JavaModelException { Location location = JDTUtils.toLocation(element); return location == null ? DEFAULT_RANGE : location.getRange(); }
@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)); }
@Override public CompletableFuture<List<? extends Location>> references(ReferenceParams params) { return CompletableFuture.completedFuture( getState().getCompilerWrapper().findReferences(params).stream() .filter(location -> Ranges.isValid(location.getRange())) .collect(Collectors.toList())); }
@Override public final CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) { return CompletableFuture.completedFuture(getState().getCompilerWrapper().getFilteredSymbols(params.getQuery()) .stream() .filter(symbol -> Ranges.isValid(symbol.getLocation().getRange())) .collect(Collectors.toList())); }
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()); }
.filter(loc -> Ranges.isValid(loc.getRange()) && Ranges.contains(loc.getRange(), params.getPosition())) .map(loc -> new ReferenceLocation(loc, false)) .collect(Collectors.toList()); indexer.getGotoReferenced().keySet().stream() .filter(loc -> paramsUri.toString().equals(loc.getUri()) && Ranges.isValid(loc.getRange()) && Ranges.contains(loc.getRange(), params.getPosition()) && indexer.gotoReferenced(loc).isPresent()) .map(loc -> new ReferenceLocation(loc, true)) .sorted((l1, l2) -> Ranges.POSITION_COMPARATOR.compare(l1.getLocation().getRange().getEnd(), l2.getLocation().getRange().getEnd())) .sorted((l1, l2) -> Ranges.POSITION_COMPARATOR.reversed() .compare(l1.getLocation().getRange().getStart(), l2.getLocation().getRange().getStart())) .collect(Collectors.toList());
List<TextDocumentEdit> documentEdits = new ArrayList<>(); Comparator<Location> locationComparator = Comparator.comparingInt( location -> location.getRange().getStart().getCharacter()); Position start = location.getRange().getStart(); int line = start.getLine(); StringBuilder lineComponent = new StringBuilder(contentComponents[line]);
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 void visitVariableExpression(VariableExpression expression) { if (expression.getAccessedVariable() != null) { SymbolInformation symbol = getVariableSymbolInformation(expression.getAccessedVariable()); if (Ranges.isValid(symbol.getLocation().getRange())) { indexer.addReference(symbol.getLocation(), createLocation(expression)); } else if (classFields.containsKey(expression.getAccessedVariable().getName())) { Location location = createLocation(classFields.get(expression.getAccessedVariable().getName())); indexer.addReference(location, createLocation(expression)); } } super.visitVariableExpression(expression); }
private void parseMethod(Indexer newIndexer, URI sourceUri, ClassNode parent, Map<String, Location> classes, Map<String, FieldNode> classFields, MethodNode method) { SymbolInformation methodSymbol = createSymbolInformation(method.getName(), SymbolKind.Method, GroovyLocations.createLocation(sourceUri, method), Optional.of(parent.getName())); newIndexer.addSymbol(sourceUri, methodSymbol); // Method parameters method.getVariableScope().getDeclaredVariables().values().forEach(variable -> { SymbolInformation variableSymbol = getVariableSymbolInformation(method.getName(), sourceUri, variable); newIndexer.addSymbol(sourceUri, variableSymbol); if (classes.containsKey(variable.getType().getName())) { newIndexer.addReference(classes.get(variable.getType().getName()), GroovyLocations.createLocation(sourceUri, variable.getType())); } }); // Return type if (classes.containsKey(method.getReturnType().getName())) { newIndexer.addReference(classes.get(method.getReturnType().getName()), GroovyLocations.createLocation(sourceUri, method.getReturnType())); } // We only want to visit the method if its not generated if (Ranges.isValid(methodSymbol.getLocation().getRange())) { // Visit the method if (method.getCode() instanceof BlockStatement) { BlockStatement blockStatement = (BlockStatement) method.getCode(); blockStatement.visit(new MethodVisitor(newIndexer, sourceUri, parent, classes, classFields, Optional.of(method), workspaceUriSupplier)); } } }
.filter(symbol -> Ranges.isValid(symbol.getLocation().getRange())).collect(Collectors.toSet());