Java Code Examples for org.eclipse.lsp4j.DocumentSymbol#setRange()

The following examples show how to use org.eclipse.lsp4j.DocumentSymbol#setRange() . 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: DocumentSymbolMapper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Converts the {@code EObject} argument into a {@link DocumentSymbol document symbol} without the
 * {@link DocumentSymbol#children children} information filled in.
 */
public DocumentSymbol toDocumentSymbol(EObject object) {
	DocumentSymbol documentSymbol = new DocumentSymbol();
	String objectName = nameProvider.getName(object);
	if (objectName != null) {
		documentSymbol.setName(objectName);
	}
	SymbolKind objectKind = kindProvider.getSymbolKind(object);
	if (objectKind != null) {
		documentSymbol.setKind(objectKind);
	}
	Range objectRange = rangeProvider.getRange(object);
	if (objectRange != null) {
		documentSymbol.setRange(objectRange);
	}
	Range objectSelectionRange = rangeProvider.getSelectionRange(object);
	if (objectSelectionRange != null) {
		documentSymbol.setSelectionRange(objectSelectionRange);
	}
	documentSymbol.setDetail(detailsProvider.getDetails(object));
	documentSymbol.setDeprecated(deprecationInfoProvider.isDeprecated(object));
	documentSymbol.setChildren(new ArrayList<>());
	return documentSymbol;
}
 
Example 2
Source File: DocumentSymbolHandler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private DocumentSymbol toDocumentSymbol(IJavaElement unit, IProgressMonitor monitor) {
	int type = unit.getElementType();
	if (type != TYPE && type != FIELD && type != METHOD && type != PACKAGE_DECLARATION && type != COMPILATION_UNIT) {
		return null;
	}
	if (monitor.isCanceled()) {
		throw new OperationCanceledException("User abort");
	}
	DocumentSymbol symbol = new DocumentSymbol();
	try {
		String name = getName(unit);
		symbol.setName(name);
		symbol.setRange(getRange(unit));
		symbol.setSelectionRange(getSelectionRange(unit));
		symbol.setKind(mapKind(unit));
		symbol.setDeprecated(isDeprecated(unit));
		symbol.setDetail(getDetail(unit, name));
		if (unit instanceof IParent) {
			//@formatter:off
			IJavaElement[] children = filter(((IParent) unit).getChildren());
			symbol.setChildren(Stream.of(children)
					.map(child -> toDocumentSymbol(child, monitor))
					.filter(Objects::nonNull)
					.collect(Collectors.toList()));
			//@formatter:off
		}
	} catch (JavaModelException e) {
		Exceptions.sneakyThrow(e);
	}
	return symbol;
}
 
Example 3
Source File: WorkspaceFolderManager.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
public DocumentSymbol definitionToDocumentSymbol(IDefinition definition, ILspProject project)
{
    String definitionBaseName = definition.getBaseName();
    if (definition instanceof IPackageDefinition)
    {
        definitionBaseName = "package " + definitionBaseName;
    }
    if (definitionBaseName.length() == 0)
    {
        //vscode expects all items to have a name
        return null;
    }

    Range range = definitionToRange(definition, project);
    if (range == null)
    {
        //we can't find where the source code for this symbol is located
        return null;
    }

    DocumentSymbol symbol = new DocumentSymbol();
    symbol.setKind(LanguageServerCompilerUtils.getSymbolKindFromDefinition(definition));
    symbol.setName(definitionBaseName);
    symbol.setRange(range);
    symbol.setSelectionRange(range);

    IDeprecationInfo deprecationInfo = definition.getDeprecationInfo();
    if (deprecationInfo != null)
    {
        symbol.setDeprecated(true);
    }

    return symbol;
}