org.eclipse.lsp4j.SymbolInformation Java Examples

The following examples show how to use org.eclipse.lsp4j.SymbolInformation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testSyntheticMember() throws Exception {
	String className = "org.apache.commons.lang3.text.StrTokenizer";
	List<? extends SymbolInformation> symbols = getSymbols(className);
	boolean overloadedMethod1Found = false;
	boolean overloadedMethod2Found = false;
	String overloadedMethod1 = "getCSVInstance(String)";
	String overloadedMethod2 = "reset()";
	for (SymbolInformation symbol : symbols) {
		Location loc = symbol.getLocation();
		assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.",
				loc != null && isValid(loc.getRange()));
		assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid name",
				symbol.getName().startsWith("access$"));
		assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + "- invalid name",
				symbol.getName().equals("<clinit>"));
		if (overloadedMethod1.equals(symbol.getName())) {
			overloadedMethod1Found = true;
		}
		if (overloadedMethod2.equals(symbol.getName())) {
			overloadedMethod2Found = true;
		}
	}
	assertTrue("The " + overloadedMethod1 + " method hasn't been found", overloadedMethod1Found);
	assertTrue("The " + overloadedMethod2 + " method hasn't been found", overloadedMethod2Found);
}
 
Example #2
Source File: XMLSymbolsProvider.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
private void findSymbolInformations(DOMNode node, String container, List<SymbolInformation> symbols,
		boolean ignoreNode, AtomicLong limit, CancelChecker cancelChecker) throws BadLocationException {
	if (!isNodeSymbol(node)) {
		return;
	}
	String name = "";
	if (!ignoreNode) {
		name = nodeToName(node);
		DOMDocument xmlDocument = node.getOwnerDocument();
		Range range = getSymbolRange(node);
		Location location = new Location(xmlDocument.getDocumentURI(), range);
		SymbolInformation symbol = new SymbolInformation(name, getSymbolKind(node), location, container);

		checkLimit(limit);
		symbols.add(symbol);
	}
	final String containerName = name;
	node.getChildren().forEach(child -> {
		try {
			findSymbolInformations(child, containerName, symbols, false, limit, cancelChecker);
		} catch (BadLocationException e) {
			LOGGER.log(Level.SEVERE, "XMLSymbolsProvider was given a BadLocation by the provided 'node' variable",
					e);
		}
	});
}
 
Example #3
Source File: SyntaxServerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testDocumentSymbol() throws Exception {
	when(preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()).thenReturn(Boolean.TRUE);

	URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
	DocumentSymbolParams params = new DocumentSymbolParams(identifier);
	List<Either<SymbolInformation, DocumentSymbol>> result = server.documentSymbol(params).join();
	assertNotNull(result);
	assertEquals(2, result.size());
	Either<SymbolInformation, DocumentSymbol> symbol = result.get(0);
	assertTrue(symbol.isRight());
	assertEquals("java", symbol.getRight().getName());
	assertEquals(SymbolKind.Package, symbol.getRight().getKind());
	symbol = result.get(1);
	assertTrue(symbol.isRight());
	assertEquals("Foo", symbol.getRight().getName());
	assertEquals(SymbolKind.Class, symbol.getRight().getKind());
	List<DocumentSymbol> children = symbol.getRight().getChildren();
	assertNotNull(children);
	assertEquals(1, children.size());
	assertEquals("main(String[])", children.get(0).getName());
	assertEquals(SymbolKind.Method, children.get(0).getKind());
}
 
Example #4
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource,
		CancelIndicator cancelIndicator) {
	String uri = uriExtensions.toUriString(resource.getURI());
	ArrayList<SymbolInformation> infos = new ArrayList<>();
	List<DocumentSymbol> rootSymbols = Lists
			.transform(hierarchicalDocumentSymbolService.getSymbols(resource, cancelIndicator), Either::getRight);
	for (DocumentSymbol rootSymbol : rootSymbols) {
		Iterable<DocumentSymbol> symbols = Traverser.forTree(DocumentSymbol::getChildren)
				.depthFirstPreOrder(rootSymbol);
		Function1<? super DocumentSymbol, ? extends String> containerNameProvider = (DocumentSymbol symbol) -> {
			DocumentSymbol firstSymbol = IterableExtensions.findFirst(symbols, (DocumentSymbol it) -> {
				return it != symbol && !IterableExtensions.isNullOrEmpty(it.getChildren())
						&& it.getChildren().contains(symbol);
			});
			if (firstSymbol != null) {
				return firstSymbol.getName();
			}
			return null;
		};
		for (DocumentSymbol s : symbols) {
			infos.add(createSymbol(uri, s, containerNameProvider));
		}
	}
	return Lists.transform(infos, Either::forLeft);
}
 
Example #5
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
    JavaSource js = getSource(params.getTextDocument().getUri());
    List<Either<SymbolInformation, DocumentSymbol>> result = new ArrayList<>();
    try {
        js.runUserActionTask(cc -> {
            cc.toPhase(JavaSource.Phase.RESOLVED);
            for (Element tel : cc.getTopLevelElements()) {
                DocumentSymbol ds = element2DocumentSymbol(cc, tel);
                if (ds != null)
                    result.add(Either.forRight(ds));
            }
        }, true);
    } catch (IOException ex) {
        //TODO: include stack trace:
        client.logMessage(new MessageParams(MessageType.Error, ex.getMessage()));
    }

    return CompletableFuture.completedFuture(result);
}
 
Example #6
Source File: WorkspaceSymbolProvider.java    From lsp4intellij with Apache License 2.0 6 votes vote down vote up
private LSPNavigationItem createNavigationItem(LSPSymbolResult result, Project project) {
  final SymbolInformation information = result.getSymbolInformation();
  final Location location = information.getLocation();
  final VirtualFile file = FileUtils.URIToVFS(location.getUri());

  if (file != null) {
    final LSPIconProvider iconProviderFor = GUIUtils.getIconProviderFor(result.getDefinition());
    final LSPLabelProvider labelProvider = GUIUtils.getLabelProviderFor(result.getDefinition());
    return new LSPNavigationItem(labelProvider.symbolNameFor(information, project),
            labelProvider.symbolLocationFor(information, project), iconProviderFor.getSymbolIcon(information.getKind()),
            project, file,
            location.getRange().getStart().getLine(),
            location.getRange().getStart().getCharacter());
  } else {
    return null;
  }
}
 
Example #7
Source File: XMLSymbolInformationsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedSymbol() {
	String xmlText = "<project><inside></inside></project>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 36, xmlDocument);
	currentSymbolInfo = createSymbolInformation("project", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 9, 26, xmlDocument);
	currentSymbolInfo = createSymbolInformation("inside", SymbolKind.Field, currentLocation, "project");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
Example #8
Source File: WorkspaceSymbolService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public List<? extends SymbolInformation> getSymbols(
	String query,
	IResourceAccess resourceAccess,
	IResourceDescriptions indexData,
	CancelIndicator cancelIndicator
) {
	List<SymbolInformation> result = new LinkedList<>();
	for (IResourceDescription resourceDescription : indexData.getAllResourceDescriptions()) {
		operationCanceledManager.checkCanceled(cancelIndicator);
		IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(resourceDescription.getURI());
		if (resourceServiceProvider != null) {
			DocumentSymbolService documentSymbolService = resourceServiceProvider.get(DocumentSymbolService.class);
			if (documentSymbolService != null) {
				result.addAll(documentSymbolService.getSymbols(resourceDescription, query, resourceAccess, cancelIndicator));
			}
		}
	}
	return result;
}
 
Example #9
Source File: XMLSymbolInformationsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedTwice() {
	String xmlText = "<a><b><c></c></b></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 21, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 17, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 6, 13, xmlDocument);
	currentSymbolInfo = createSymbolInformation("c", SymbolKind.Field, currentLocation, "b");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
Example #10
Source File: XMLSymbolInformationsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedSelfClosingTag() {
	String xmlText = "<a><b/></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 11, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 7, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
Example #11
Source File: XMLSymbolInformationsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testNestedUnclosedTag() {
	String xmlText = "<a><b></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 10, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
Example #12
Source File: XMLSymbolInformationsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testAllTagsUnclosed() {
	String xmlText = "<a><b>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
Example #13
Source File: DocumentSymbolProcessorTest.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
@Test
void testNoExceptionWithJavaFile() throws Exception {
	final TestLogAppender appender = new TestLogAppender();
	final Logger logger = Logger.getRootLogger();
	logger.addAppender(appender);
	File f = new File("src/test/resources/workspace/camel.java");
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer camelLanguageServer = initializeLanguageServer(fis, ".java");
		CompletableFuture<List<Either<SymbolInformation,DocumentSymbol>>> documentSymbolFor = getDocumentSymbolFor(camelLanguageServer);
		List<Either<SymbolInformation, DocumentSymbol>> symbolsInformation = documentSymbolFor.get();
		assertThat(symbolsInformation).isEmpty();
		for (LoggingEvent loggingEvent : appender.getLog()) {
			if (loggingEvent.getMessage() != null) {
				assertThat((String)loggingEvent.getMessage()).doesNotContain(DocumentSymbolProcessor.CANNOT_DETERMINE_DOCUMENT_SYMBOLS);
			}
		}
	}
}
 
Example #14
Source File: XMLSymbolInformationsTest.java    From lemminx with Eclipse Public License 2.0 6 votes vote down vote up
private void assertSymbols(List<SymbolInformation> expectedSymbolList, List<SymbolInformation> actualSymbolList) {
	assertEquals(expectedSymbolList.size(), actualSymbolList.size());

	SymbolInformation currentExpectedSymbol;
	SymbolInformation currentActualSymbol;

	for (int i = 0; i < expectedSymbolList.size(); i++) {
		currentExpectedSymbol = expectedSymbolList.get(i);
		currentActualSymbol = actualSymbolList.get(i);
		assertEquals(currentExpectedSymbol.getName(), currentActualSymbol.getName(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getKind(), currentActualSymbol.getKind(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getContainerName(),
				currentActualSymbol.getContainerName(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getLocation(), currentActualSymbol.getLocation(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getDeprecated(),
				currentActualSymbol.getDeprecated(),"Symbol index " + i);
	}
}
 
Example #15
Source File: SymbolInformationTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
public void write(final JsonWriter out, final SymbolInformation value) throws IOException {
  if (value == null) {
  	out.nullValue();
  	return;
  }
  
  out.beginObject();
  out.name("name");
  writeName(out, value.getName());
  out.name("kind");
  writeKind(out, value.getKind());
  out.name("deprecated");
  writeDeprecated(out, value.getDeprecated());
  out.name("location");
  writeLocation(out, value.getLocation());
  out.name("containerName");
  writeContainerName(out, value.getContainerName());
  out.endObject();
}
 
Example #16
Source File: DocumentSymbolProcessor.java    From camel-language-server with Apache License 2.0 6 votes vote down vote up
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> getDocumentSymbols() {
	return CompletableFuture.supplyAsync(() -> {
		if (textDocumentItem.getUri().endsWith(".xml")) {
			try {
				List<Either<SymbolInformation, DocumentSymbol>> symbolInformations = new ArrayList<>();
				NodeList routeNodes = parserFileHelper.getRouteNodes(textDocumentItem);
				if (routeNodes != null) {
					symbolInformations.addAll(convertToSymbolInformation(routeNodes));
				}
				NodeList camelContextNodes = parserFileHelper.getCamelContextNodes(textDocumentItem);
				if (camelContextNodes != null) {
					symbolInformations.addAll(convertToSymbolInformation(camelContextNodes));
				}
				return symbolInformations;
			} catch (Exception e) {
				LOGGER.error(CANNOT_DETERMINE_DOCUMENT_SYMBOLS, e);
			}
		}
		return Collections.emptyList();
	});
}
 
Example #17
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public List<? extends SymbolInformation> getSymbols(IResourceDescription resourceDescription, String query,
		IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) {
	List<SymbolInformation> symbols = new LinkedList<>();
	for (IEObjectDescription description : resourceDescription.getExportedObjects()) {
		operationCanceledManager.checkCanceled(cancelIndicator);
		if (filter(description, query)) {
			createSymbol(description, resourceAccess, (SymbolInformation symbol) -> {
				symbols.add(symbol);
			});
		}
	}
	return symbols;
}
 
Example #18
Source File: WorkspaceSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSearchWithEmptyResults() {
	List<SymbolInformation> results = handler.search(null, monitor);
	assertNotNull(results);
	assertEquals(0, results.size());

	results = handler.search("  ", monitor);
	assertNotNull(results);
	assertEquals(0, results.size());

	results = handler.search("Abracadabra", monitor);
	assertNotNull(results);
	assertEquals(0, results.size());
}
 
Example #19
Source File: WorkspaceSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testWorkspaceSearchNoClassContentSupport() {
	when(preferenceManager.isClientSupportsClassFileContent()).thenReturn(false);
	//No classes from binaries can be found
	List<SymbolInformation> results = handler.search("Array", monitor);
	assertNotNull(results);
	assertEquals("Unexpected results", 0, results.size());

	//... but workspace classes can still be found
	testWorkspaceSearchOnFileInWorkspace();
}
 
Example #20
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
	logInfo(">> document/documentSymbol");
	boolean hierarchicalDocumentSymbolSupported = preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported();
	DocumentSymbolHandler handler = new DocumentSymbolHandler(hierarchicalDocumentSymbolSupported);
	return computeAsync((monitor) -> {
		waitForLifecycleJobs(monitor);
		return handler.documentSymbol(params, monitor);
	});
}
 
Example #21
Source File: JSONHierarchicalSymbolService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource,
		CancelIndicator cancelIndicator) {
	List<Either<SymbolInformation, DocumentSymbol>> result = new ArrayList<>();
	for (EObject content : resource.getContents()) {
		if (content instanceof JSONDocument) {
			JSONDocument document = (JSONDocument) content;
			JSONValue rootValue = document.getContent();
			getSymbols(rootValue, symbol -> result.add(Either.forRight(symbol)), cancelIndicator);
		}
	}
	return result;
}
 
Example #22
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.16
 */
protected SymbolInformation createSymbol(String uri, DocumentSymbol symbol,
		Function1<? super DocumentSymbol, ? extends String> containerNameProvider) {
	SymbolInformation symbolInformation = new SymbolInformation();
	symbolInformation.setName(symbol.getName());
	symbolInformation.setKind(symbol.getKind());
	symbolInformation.setDeprecated(symbol.getDeprecated());
	Location location = new Location();
	location.setUri(uri);
	location.setRange(symbol.getSelectionRange());
	symbolInformation.setLocation(location);
	symbolInformation.setContainerName(containerNameProvider.apply(symbol));
	return symbolInformation;
}
 
Example #23
Source File: SyntaxLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
	logInfo(">> document/documentSymbol");
	boolean hierarchicalDocumentSymbolSupported = preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported();
	DocumentSymbolHandler handler = new DocumentSymbolHandler(hierarchicalDocumentSymbolSupported);
	return computeAsync((monitor) -> {
		waitForLifecycleJobs(monitor);
		return handler.documentSymbol(params, monitor);
	});
}
 
Example #24
Source File: DocumentSymbolProcessorTest.java    From camel-language-server with Apache License 2.0 5 votes vote down vote up
private List<Either<SymbolInformation, DocumentSymbol>> testRetrieveDocumentSymbol(String textTotest, int expectedSize) throws URISyntaxException, InterruptedException, ExecutionException {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer(textTotest);
	CompletableFuture<List<Either<SymbolInformation,DocumentSymbol>>> documentSymbolFor = getDocumentSymbolFor(camelLanguageServer);
	List<Either<SymbolInformation, DocumentSymbol>> symbolsInformation = documentSymbolFor.get();
	assertThat(symbolsInformation).hasSize(expectedSize);
	return symbolsInformation;
}
 
Example #25
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void createSymbol(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess,
		Procedure1<? super SymbolInformation> acceptor) {
	String name = getSymbolName(description);
	if (name == null) {
		return;
	}
	SymbolKind kind = getSymbolKind(description);
	if (kind == null) {
		return;
	}
	getSymbolLocation(description, resourceAccess, (Location location) -> {
		SymbolInformation symbol = new SymbolInformation(name, kind, location);
		acceptor.apply(symbol);
	});
}
 
Example #26
Source File: WorkspaceSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSearchSourceOnly() {
	String query = "B*";
	List<SymbolInformation> results = handler.search(query, "hello", true, monitor);
	assertNotNull(results);
	assertEquals("Found " + results.size() + "result", 6, results.size());
	String className = "BaseTest";
	boolean foundClass = results.stream().filter(s -> className.equals(s.getName())).findFirst().isPresent();
	assertTrue("Did not find " + className, foundClass);
}
 
Example #27
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public List<Either<SymbolInformation, DocumentSymbol>> documentSymbol(DocumentSymbolParams params, IProgressMonitor monitor) {

		ITypeRoot unit = JDTUtils.resolveTypeRoot(params.getTextDocument().getUri());
		if (unit == null) {
			return Collections.emptyList();
		}

		if (hierarchicalDocumentSymbolSupported) {
			List<DocumentSymbol> symbols = this.getHierarchicalOutline(unit, monitor);
			return symbols.stream().map(Either::<SymbolInformation, DocumentSymbol>forRight).collect(toList());
		} else {
			SymbolInformation[] elements = this.getOutline(unit, monitor);
			return Arrays.asList(elements).stream().map(Either::<SymbolInformation, DocumentSymbol>forLeft).collect(toList());
		}
	}
 
Example #28
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private void collectChildren(ITypeRoot unit, IJavaElement[] elements, ArrayList<SymbolInformation> symbols,
		IProgressMonitor monitor)
		throws JavaModelException {
	for (IJavaElement element : elements) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		if (element instanceof IParent) {
			collectChildren(unit, filter(((IParent) element).getChildren()), symbols, monitor);
		}
		int type = element.getElementType();
		if (type != IJavaElement.TYPE && type != IJavaElement.FIELD && type != IJavaElement.METHOD) {
			continue;
		}

		Location location = JDTUtils.toLocation(element);
		if (location != null) {
			SymbolInformation si = new SymbolInformation();
			String name = JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
			si.setName(name == null ? element.getElementName() : name);
			si.setKind(mapKind(element));
			if (element.getParent() != null) {
				si.setContainerName(element.getParent().getElementName());
			}
			location.setUri(ResourceUtils.toClientUri(location.getUri()));
			si.setLocation(location);
			if (!symbols.contains(si)) {
				symbols.add(si);
			}
		}
	}
}
 
Example #29
Source File: JDTLanguageServer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
	logInfo(">> workspace/symbol");
	return computeAsync((monitor) -> {
		return WorkspaceSymbolHandler.search(params.getQuery(), monitor);
	});
}
 
Example #30
Source File: WorkspaceSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testProjectSearch() {
	String query = "IFoo";
	List<SymbolInformation> results = handler.search(query, monitor);
	assertNotNull(results);
	assertEquals("Found " + results.size() + " results", 2, results.size());
	SymbolInformation symbol = results.get(0);
	assertEquals(SymbolKind.Interface, symbol.getKind());
	assertEquals("java", symbol.getContainerName());
	assertEquals(query, symbol.getName());
	Location location = symbol.getLocation();
	assertNotEquals("Range should not equal the default range", JDTUtils.newRange(), location.getRange());
	assertTrue("Unexpected uri "+ location.getUri(), location.getUri().endsWith("Foo.java"));
}