org.eclipse.lsp4j.DocumentSymbolParams Java Examples

The following examples show how to use org.eclipse.lsp4j.DocumentSymbolParams. 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: 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 #2
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 #3
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 #4
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Compute the symbol information. Executed in a read request.
 * @since 2.20
 */
protected List<Either<SymbolInformation, DocumentSymbol>> documentSymbol(DocumentSymbolParams params,
		CancelIndicator cancelIndicator) {
	URI uri = getURI(params.getTextDocument());
	IDocumentSymbolService documentSymbolService = getIDocumentSymbolService(getResourceServiceProvider(uri));
	if (documentSymbolService == null) {
		return Collections.emptyList();
	}
	return workspaceManager.doRead(uri,
			(document, resource) -> documentSymbolService.getSymbols(document, resource, params, cancelIndicator));
}
 
Example #5
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
  try {
    @Extension
    final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final String fileUri = this.initializeContext(configuration).getUri();
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
    DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
    final CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
    final List<Either<SymbolInformation, DocumentSymbol>> symbols = symbolsFuture.get();
    Procedure1<? super List<Either<SymbolInformation, DocumentSymbol>>> _assertSymbols = configuration.getAssertSymbols();
    boolean _tripleNotEquals = (_assertSymbols != null);
    if (_tripleNotEquals) {
      configuration.getAssertSymbols().apply(symbols);
    } else {
      final Function1<Either<SymbolInformation, DocumentSymbol>, Object> _function = (Either<SymbolInformation, DocumentSymbol> it) -> {
        Object _xifexpression = null;
        if (this.hierarchicalDocumentSymbolSupport) {
          _xifexpression = it.getRight();
        } else {
          _xifexpression = it.getLeft();
        }
        return _xifexpression;
      };
      final List<Object> unwrappedSymbols = ListExtensions.<Either<SymbolInformation, DocumentSymbol>, Object>map(symbols, _function);
      final String actualSymbols = this.toExpectation(unwrappedSymbols);
      this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #6
Source File: ActionScriptServices.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
/**
 * Searches by name for a symbol in a specific document (not the whole
 * workspace)
 */
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params)
{
    return CompletableFutures.computeAsync(compilerWorkspace.getExecutorService(), cancelToken ->
    {
        cancelToken.checkCanceled();

        //make sure that the latest changes have been passed to
        //workspace.fileChanged() before proceeding
        if(realTimeProblemsChecker != null)
        {
            realTimeProblemsChecker.updateNow();
        }
        
        compilerWorkspace.startBuilding();
        try
        {
            boolean hierarchicalDocumentSymbolSupport = false;
            try
            {
                hierarchicalDocumentSymbolSupport = clientCapabilities.getTextDocument().getDocumentSymbol().getHierarchicalDocumentSymbolSupport();
            }
            catch(NullPointerException e)
            {
                //ignore
            }
            DocumentSymbolProvider provider = new DocumentSymbolProvider(workspaceFolderManager, hierarchicalDocumentSymbolSupport);
            return provider.documentSymbol(params, cancelToken);
        }
        finally
        {
            compilerWorkspace.doneBuilding();
        }
    });
}
 
Example #7
Source File: DocumentSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private List<? extends SymbolInformation> getSymbols(String className)
		throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
	String uri = ClassFileUtil.getURI(project, className);
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
	DocumentSymbolParams params = new DocumentSymbolParams();
	params.setTextDocument(identifier);
	//@formatter:off
	List<SymbolInformation> symbols = new DocumentSymbolHandler(false)
			.documentSymbol(params, monitor).stream()
			.map(Either::getLeft).collect(toList());
	//@formatter:on
	assertFalse("No symbols found for " + className, symbols.isEmpty());
	return symbols;
}
 
Example #8
Source File: DocumentSymbolHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static List<? extends DocumentSymbol> internalGetHierarchicalSymbols(IProject project, IProgressMonitor monitor, String className)
		throws JavaModelException, UnsupportedEncodingException, InterruptedException, ExecutionException {
	String uri = ClassFileUtil.getURI(project, className);
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(uri);
	DocumentSymbolParams params = new DocumentSymbolParams();
	params.setTextDocument(identifier);
	//@formatter:off
	List<DocumentSymbol> symbols = new DocumentSymbolHandler(true)
			.documentSymbol(params, monitor).stream()
			.map(Either::getRight).collect(toList());
	//@formatter:on
	assertTrue(symbols.size() > 0);
	return symbols;
}
 
Example #9
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 #10
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 #11
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compute the symbol information. Executed in a read request.
 */
protected List<Either<SymbolInformation, DocumentSymbol>> documentSymbol(OpenFileContext ofc,
		DocumentSymbolParams params, CancelIndicator cancelIndicator) {
	URI uri = ofc.getURI();
	IDocumentSymbolService documentSymbolService = getIDocumentSymbolService(getResourceServiceProvider(uri));
	if ((documentSymbolService == null)) {
		return Collections.emptyList();
	}
	XtextResource res = ofc.getResource();
	XDocument doc = ofc.getDocument();
	return documentSymbolService.getSymbols(doc, res, params, cancelIndicator);
}
 
Example #12
Source File: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
		DocumentSymbolParams params) {
	URI uri = getURI(params.getTextDocument());
	return openFilesManager.runInOpenFileContext(uri, "documentSymbol", (ofc, ci) -> {
		return documentSymbol(ofc, params, ci);
	});
}
 
Example #13
Source File: GroovyServices.java    From groovy-language-server with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
		DocumentSymbolParams params) {
	URI uri = URI.create(params.getTextDocument().getUri());
	recompileIfContextChanged(uri);

	DocumentSymbolProvider provider = new DocumentSymbolProvider(astVisitor);
	return provider.provideDocumentSymbols(params.getTextDocument());
}
 
Example #14
Source File: CamelTextDocumentService.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
	LOGGER.info("documentSymbol: {}", params.getTextDocument());
	return new DocumentSymbolProcessor(openedDocuments.get(params.getTextDocument().getUri())).getDocumentSymbols();
}
 
Example #15
Source File: IDocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
List<Either<SymbolInformation, DocumentSymbol>> getSymbols(Document document, XtextResource resource,
DocumentSymbolParams params, CancelIndicator cancelIndicator);
 
Example #16
Source File: IDocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(Document document, XtextResource resource,
		DocumentSymbolParams params, CancelIndicator cancelIndicator) {

	return emptyList();
}
 
Example #17
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(Document document, XtextResource resource,
		DocumentSymbolParams params, CancelIndicator cancelIndicator) {
	return getSymbols(resource, cancelIndicator);
}
 
Example #18
Source File: HierarchicalDocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(Document document, XtextResource resource,
		DocumentSymbolParams params, CancelIndicator cancelIndicator) {
	return getSymbols(resource, cancelIndicator);
}
 
Example #19
Source File: LanguageServerImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
		DocumentSymbolParams params) {
	return requestManager.runRead((cancelIndicator) -> documentSymbol(params, cancelIndicator));
}
 
Example #20
Source File: TeiidDdlTextDocumentService.java    From syndesis with Apache License 2.0 4 votes vote down vote up
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
        DocumentSymbolParams params) {
    LOGGER.debug("documentSymbol: {}", params.getTextDocument());
    return CompletableFuture.completedFuture(Collections.emptyList());
}
 
Example #21
Source File: AbstractCamelLanguageServerTest.java    From camel-language-server with Apache License 2.0 4 votes vote down vote up
protected CompletableFuture<List<Either<SymbolInformation,DocumentSymbol>>> getDocumentSymbolFor(CamelLanguageServer camelLanguageServer) {
	TextDocumentService textDocumentService = camelLanguageServer.getTextDocumentService();
	DocumentSymbolParams params = new DocumentSymbolParams(new TextDocumentIdentifier(DUMMY_URI+extensionUsed));
	return textDocumentService.documentSymbol(params);
}
 
Example #22
Source File: TextDocumentService.java    From lsp4j with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * The document symbol request is sent from the client to the server to list all
 * symbols found in a given text document.
 * 
 * Registration Options: {@link TextDocumentRegistrationOptions}
 * 
 * <p>
 * <b>Caveat</b>: although the return type allows mixing the
 * {@link DocumentSymbol} and {@link SymbolInformation} instances into a list do
 * not do it because the clients cannot accept a heterogeneous list. A list of
 * {@code DocumentSymbol} instances is only a valid return value if the
 * {@link DocumentSymbolCapabilities#getHierarchicalDocumentSymbolSupport()
 * textDocument.documentSymbol.hierarchicalDocumentSymbolSupport} is
 * {@code true}. More details on this difference between the LSP and the LSP4J
 * can be found <a href="https://github.com/eclipse/lsp4j/issues/252">here</a>.
 * </p>
 */
@JsonRequest
@ResponseJsonAdapter(DocumentSymbolResponseAdapter.class)
default CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
	throw new UnsupportedOperationException();
}