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

The following examples show how to use org.eclipse.lsp4j.Location#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: PsiUtilsImpl.java    From intellij-quarkus with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Location toLocation(PsiMember psiMember) {
    PsiElement sourceElement = psiMember.getNavigationElement();
    if (sourceElement != null) {
        PsiFile file = sourceElement.getContainingFile();
        Location location = new Location();
        location.setUri(VfsUtilCore.convertToURL(file.getVirtualFile().getUrl()).toExternalForm());
        Document document = PsiDocumentManager.getInstance(psiMember.getProject()).getDocument(file);
        TextRange range = sourceElement.getTextRange();
        int startLine = document.getLineNumber(range.getStartOffset());
        int startLineOffset = document.getLineStartOffset(startLine);
        int endLine = document.getLineNumber(range.getEndOffset());
        int endLineOffset = document.getLineStartOffset(endLine);
        location.setRange(new Range(LSPIJUtils.toPosition(range.getStartOffset(), document), LSPIJUtils.toPosition(range.getEndOffset(), document)));
        return location;
    }
    return null;
}
 
Example 2
Source File: LanguageServerCompilerUtils.java    From vscode-as3mxml with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a compiler source location to a language server location. May
 * return null if the line or column of the source location is -1.
 */
public static Location getLocationFromSourceLocation(ISourceLocation sourceLocation)
{
    Path sourceLocationPath = Paths.get(sourceLocation.getSourcePath());
    Location location = new Location();
    location.setUri(sourceLocationPath.toUri().toString());

    Range range = getRangeFromSourceLocation(sourceLocation);
    if (range == null)
    {
        //this is probably generated by the compiler somehow
        return null;
    }
    location.setRange(range);

    return location;
}
 
Example 3
Source File: DefinitionTextUtils.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
public Location toLocation()
{
    Location location = new Location();
    String escapedText = UrlEscapers.urlFragmentEscaper().escape(text);
    URI uri = URI.create("swc://" + path + "?" + escapedText);
    location.setUri(uri.toString());
    location.setRange(toRange());
    return location;
}
 
Example 4
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;
}