/** * Creates a location from the given URI with an undefined range. */ public static Location createLocation(URI uri) { return new Location(uri.toString(), Ranges.UNDEFINED_RANGE); }
/** * Creates a default location for the uri. * * @param classFile * @return location * @throws JavaModelException */ public static Location toLocation(String uri) { return new Location(ResourceUtils.toClientUri(uri), newRange()); }
private Collection<? extends SymbolInformationDto> convertDocumentSymbol( DocumentSymbol symbol, String uri) { ArrayList<SymbolInformationDto> result = new ArrayList<>(); result.add( new SymbolInformationDto( new SymbolInformation( symbol.getName(), symbol.getKind(), new Location(uri, symbol.getRange())))); for (DocumentSymbol child : symbol.getChildren()) { result.addAll(convertDocumentSymbol(child, uri)); } return result; } },
private static Location createLocation(Path path, Range range) { return new Location(path.toUri().toString(), range); }
/** * Creates location to the given offset and length for the class file. * * @param unit * @param offset * @param length * @return location * @throws JavaModelException */ public static Location toLocation(IClassFile classFile, int offset, int length) throws JavaModelException { String uriString = toUri(classFile); if (uriString != null) { Range range = toRange(classFile, offset, length); return new Location(uriString, range); } return null; }
/** * Creates location to the given offset and length for the compilation unit * * @param unit * @param offset * @param length * @return location or null * @throws JavaModelException */ public static Location toLocation(ICompilationUnit unit, int offset, int length) throws JavaModelException { return new Location(ResourceUtils.toClientUri(toURI(unit)), toRange(unit, offset, length)); }
public Location newLocation(final Resource resource, final ITextRegion textRegion) { final Range range = this.newRange(resource, textRegion); if ((range == null)) { return null; } final String uri = this._uriExtensions.toUriString(resource.getURI()); return new Location(uri, range); }
private void addSymbol(BLangNode node, BSymbol balSymbol, SymbolKind kind) { String symbolName = balSymbol.getName().getValue(); if (query != null && !query.isEmpty() && !symbolName.startsWith(query)) { return; } SymbolInformation lspSymbol = new SymbolInformation(); lspSymbol.setName(symbolName); lspSymbol.setKind(kind); lspSymbol.setLocation(new Location(this.uri, getRange(node))); this.symbols.add(lspSymbol); }
/** * Creates a location from the given URI and node's start and end positions. */ public static Location createLocation(URI uri, ASTNode node) { return new Location( uri.toString(), Ranges.createZeroBasedRange( node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber())); }
public void assertGotoDefinition(Position pos, Range expectedTarget) throws Exception { TextDocumentIdentifier textDocumentId = doc.getId(); TextDocumentPositionParams params = new TextDocumentPositionParams(textDocumentId, textDocumentId.getUri(), pos); List<? extends Location> defs = harness.getDefinitions(params); assertEquals(1, defs.size()); assertEquals(new Location(textDocumentId.getUri(), expectedTarget), defs.get(0)); }
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; }
/** * Creates a location which goes from the given node's starting position to at most one line after. */ public static Location createClassDefinitionLocation(URI uri, ClassNode node) { Range range; // This takes care of the edge case where the class is defined on one line. if (node.getLineNumber() == node.getLastLineNumber()) { range = Ranges.createZeroBasedRange(node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()); } else { range = Ranges.createZeroBasedRange(node.getLineNumber(), node.getColumnNumber(), Math.min(node.getLineNumber() + 1, node.getLastLineNumber()), Math.min(1, node.getLastColumnNumber())); } return new Location(uri.toString(), range); }
int def = text.indexOf(word); if (def>=0) { Location loc = new Location(params.getTextDocument().getUri(), doc.toRange(def, word.length()) );
@Before public void setup() throws IOException { MockitoAnnotations.initMocks(this); Diagnostic d1 = new Diagnostic(); d1.setMessage("Some message"); d1.setSeverity(DiagnosticSeverity.Error); Diagnostic d2 = new Diagnostic(); d2.setMessage("Some other message"); d2.setSeverity(DiagnosticSeverity.Warning); expectedDiagnostics = Sets.newHashSet(new PublishDiagnosticsParams("uri", ImmutableList.of(d1, d2))); expectedReferences.add(new SymbolInformation( "MyClassName", SymbolKind.Class, new Location("uri", Ranges.createRange(1, 1, 9, 9)), "Something")); expectedReferences.add(new SymbolInformation( "MyClassName2", SymbolKind.Class, new Location("uri", Ranges.createRange(1, 1, 9, 9)), "SomethingElse")); Set<SymbolInformation> allReferencesReturned = Sets.newHashSet(expectedReferences); // The reference that will be filtered out allReferencesReturned.add(new SymbolInformation( "MyClassName3", SymbolKind.Class, new Location("uri", Ranges.UNDEFINED_RANGE), "SomethingElse")); when(compilerWrapper.getWorkspaceRoot()).thenReturn(workspace.getRoot().toPath().toUri()); when(compilerWrapper.compile(any())).thenReturn(expectedDiagnostics); when(compilerWrapper.getFilteredSymbols(any())).thenReturn(allReferencesReturned); when(state.getCompilerWrapper()).thenReturn(compilerWrapper); service = new TestWorkspaceService(state); }
))); SymbolInformation symbol1 = new SymbolInformation("ThisIsASymbol", SymbolKind.Field, new Location()); SymbolInformation symbol2 = new SymbolInformation("methodA", SymbolKind.Method, new Location()); symbolsMap.put(filePath.toUri(), Sets.newHashSet(symbol1, symbol2)); expectedCompletionList = new CompletionList(false, Lists.newArrayList(thisIsASymbol, methodA)); expectedReferences.add(new Location("uri", Ranges.createRange(1, 1, 9, 9))); expectedReferences.add(new Location("uri", Ranges.createRange(1, 1, 9, 9))); Set<Location> allReferencesReturned = Sets.newHashSet(expectedReferences); allReferencesReturned.add(new Location("uri", Ranges.UNDEFINED_RANGE)); expectedDefinitionLocation = Optional.of(new Location("foo", Ranges.createRange(0, 1, 0, 1))); when(compilerWrapper.getWorkspaceRoot()).thenReturn(workspace.getRoot().toPath().toUri()); when(compilerWrapper.compile(any())).thenReturn(expectedDiagnostics);
@Test public void testGotoDefinition_multipleFiles() throws IOException { File dog = addFileToFolder(workspaceRoot, "mydogfolder", "Dog.groovy", "public class Dog {}\n"); File cat = addFileToFolder(workspaceRoot, "mycatfolder", "Cat.groovy", "public class Cat {\n" + " public static Dog dog = new Dog()\n" + " public static Dog foo() {\n" + " Dog newDog = new Dog()\n" + " foo()\n" + " return newDog\n" + " }\n" + "}\n"); parser.parseAllSymbols(); // Dog class Location expectedLocation = new Location(dog.toPath().toUri().toString(), Ranges.createRange(0, 0, 0, 19)); assertEquals(Optional.of(expectedLocation), parser.gotoDefinition(cat.toURI(), new Position(1, 18))); assertEquals(Optional.of(expectedLocation), parser.gotoDefinition(cat.toURI(), new Position(2, 18))); assertEquals(Optional.of(expectedLocation), parser.gotoDefinition(cat.toURI(), new Position(3, 8))); assertEquals(Optional.of(expectedLocation), parser.gotoDefinition(cat.toURI(), new Position(3, 25))); // newDog local variable expectedLocation = new Location(cat.toPath().toUri().toString(), Ranges.createRange(3, 11, 3, 17)); assertEquals(Optional.of(expectedLocation), parser.gotoDefinition(cat.toURI(), new Position(5, 18))); // foo method // TODO(#124): make this more accurate expectedLocation = new Location(cat.toPath().toUri().toString(), Ranges.createRange(2, 3, 6, 4)); assertEquals(Optional.of(expectedLocation), parser.gotoDefinition(cat.toURI(), new Position(4, 10))); }
Location expectedLocation = new Location(file.toPath().toUri().toString(), Ranges.createRange(2, 3, 3, 0)); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(1, 15)).get()); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(10, 10)).get()); expectedLocation = new Location(file.toPath().toUri().toString(), Ranges.createRange(1, 3, 1, 36)); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(11, 15)).get()); expectedLocation = new Location(file.toPath().toUri().toString(), Ranges.createRange(10, 17, 10, 27)); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(13, 10)).get()); expectedLocation = new Location(file.toPath().toUri().toString(), Ranges.createRange(3, 6, 3, 35)); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(11, 23)).get()); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(12, 23)).get()); expectedLocation = new Location(file.toPath().toUri().toString(), Ranges.createRange(4, 6, 4, 39)); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(14, 20)).get()); expectedLocation = new Location(file.toPath().toUri().toString(), Ranges.createRange(6, 3, 8, 4)); assertEquals(expectedLocation, parser.gotoDefinition(file.toURI(), new Position(15, 20)).get());
protected SymbolInformation createSymbol(TextDocument doc, Node node, YType type) throws BadLocationException { DocumentRegion region = NodeUtil.region(doc, node); Location location = new Location(doc.getUri(), doc.toRange(region.getStart(), region.getLength())); SymbolInformation symbol = new SymbolInformation(); symbol.setName(region.toString()); symbol.setKind(symbolKind(type)); symbol.setLocation(location); symbol.setContainerName(containerName(type)); return symbol; }
/** * Get the physical source location of the given package. * * @param bLangNode ballerina language node references are requested for * @param ownerPackageName list of name compositions of the node's package name * @param currentPackageName list of name compositions of the current package * @return location of the package of the given node */ private Location getLocation(BLangNode bLangNode, String ownerPackageName, String currentPackageName) { Location l = new Location(); Range r = new Range(); TextDocumentPositionParams position = this.context.get(DocumentServiceKeys.POSITION_KEY); String parentPath = new LSDocument(position.getTextDocument().getUri()).getSourceRoot(); if (parentPath != null) { String fileName = bLangNode.getPosition().getSource().getCompilationUnitName(); Path filePath = Paths.get(CommonUtil.getPackageURI(currentPackageName, parentPath, ownerPackageName), fileName); l.setUri(filePath.toUri().toString()); // Subtract 1 to convert the token lines and char positions to zero based indexing r.setStart(new Position(bLangNode.getPosition().getStartLine() - 1, bLangNode.getPosition().getStartColumn() - 1)); r.setEnd(new Position(bLangNode.getPosition().getEndLine() - 1, bLangNode.getPosition().getEndColumn() - 1)); l.setRange(r); } return l; }
/** * @since 2.16 */ protected SymbolInformation createSymbol(final String uri, final DocumentSymbol symbol, final Function1<? super DocumentSymbol, ? extends String> containerNameProvider) { SymbolInformation _symbolInformation = new SymbolInformation(); final Procedure1<SymbolInformation> _function = (SymbolInformation it) -> { it.setName(symbol.getName()); it.setKind(symbol.getKind()); it.setDeprecated(symbol.getDeprecated()); Location _location = new Location(); final Procedure1<Location> _function_1 = (Location it_1) -> { it_1.setUri(uri); it_1.setRange(symbol.getSelectionRange()); }; Location _doubleArrow = ObjectExtensions.<Location>operator_doubleArrow(_location, _function_1); it.setLocation(_doubleArrow); it.setContainerName(containerNameProvider.apply(symbol)); }; return ObjectExtensions.<SymbolInformation>operator_doubleArrow(_symbolInformation, _function); }