Search in sources :

Example 21 with Position

use of org.eclipse.lsp4j.Position in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method createDiagnosticWithoutRange.

private Diagnostic createDiagnosticWithoutRange() {
    Diagnostic diagnostic = new Diagnostic();
    Range range = new Range();
    range.setStart(new Position());
    range.setEnd(new Position());
    diagnostic.setRange(range);
    return diagnostic;
}
Also used : Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range)

Example 22 with Position

use of org.eclipse.lsp4j.Position in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method resolveDefinition.

private void resolveDefinition(IDefinition definition, List<Location> result) {
    String definitionPath = definition.getSourcePath();
    if (definitionPath == null) {
        //if the definition is in an MXML file, getSourcePath() may return
        //null, but getContainingFilePath() will return something
        definitionPath = definition.getContainingFilePath();
        if (definitionPath == null) {
            //if everything is null, there's nothing to do
            return;
        }
        //however, getContainingFilePath() also works for SWCs
        if (!definitionPath.endsWith(AS_EXTENSION) && !definitionPath.endsWith(MXML_EXTENSION) && (definitionPath.contains(SDK_LIBRARY_PATH_SIGNATURE_UNIX) || definitionPath.contains(SDK_LIBRARY_PATH_SIGNATURE_WINDOWS))) {
            //if it's a framework SWC, we're going to attempt to resolve
            //the source file 
            ICompilationUnit unit = currentProject.getScope().getCompilationUnitForDefinition(definition);
            try {
                byte[] abcBytes = unit.getABCBytesRequest().get().getABCBytes();
                ABCParser parser = new ABCParser(abcBytes);
                PoolingABCVisitor visitor = new PoolingABCVisitor();
                parser.parseABC(visitor);
                Pool<String> pooledStrings = visitor.getStringPool();
                for (String pooledString : pooledStrings.getValues()) {
                    if (pooledString.contains(SDK_SOURCE_PATH_SIGNATURE_UNIX) || pooledString.contains(SDK_SOURCE_PATH_SIGNATURE_WINDOWS)) {
                        //just go with the first one that we find
                        definitionPath = transformDebugFilePath(pooledString);
                        break;
                    }
                }
            } catch (InterruptedException e) {
            //safe to ignore
            }
        }
        if (!definitionPath.endsWith(AS_EXTENSION) && !definitionPath.endsWith(MXML_EXTENSION)) {
            //if it's in a SWC or something, we don't know how to resolve
            return;
        }
    }
    Path resolvedPath = Paths.get(definitionPath);
    Location location = new Location();
    location.setUri(resolvedPath.toUri().toString());
    int nameLine = definition.getNameLine();
    int nameColumn = definition.getNameColumn();
    if (nameLine == -1 || nameColumn == -1) {
        //getNameLine() and getNameColumn() will both return -1 for a
        //variable definition created by an MXML tag with an id.
        //so we need to figure them out from the offset instead.
        int nameOffset = definition.getNameStart();
        if (nameOffset == -1) {
            //we can't find the name, so give up
            return;
        }
        Reader reader = getReaderForPath(resolvedPath);
        if (reader == null) {
            //we can't get the code at all
            return;
        }
        Position position = new Position();
        offsetToLineAndCharacter(reader, nameOffset, position);
        nameLine = position.getLine();
        nameColumn = position.getCharacter();
    }
    if (nameLine == -1 || nameColumn == -1) {
        //we can't find the name, so give up
        return;
    }
    Position start = new Position();
    start.setLine(nameLine);
    start.setCharacter(nameColumn);
    Position end = new Position();
    end.setLine(nameLine);
    end.setCharacter(nameColumn + definition.getNameEnd() - definition.getNameStart());
    Range range = new Range();
    range.setStart(start);
    range.setEnd(end);
    location.setRange(range);
    result.add(location);
}
Also used : Path(java.nio.file.Path) ICompilationUnit(org.apache.flex.compiler.units.ICompilationUnit) Position(org.eclipse.lsp4j.Position) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Range(org.eclipse.lsp4j.Range) PoolingABCVisitor(org.apache.flex.abc.PoolingABCVisitor) ABCParser(org.apache.flex.abc.ABCParser) Location(org.eclipse.lsp4j.Location) ISourceLocation(org.apache.flex.compiler.common.ISourceLocation)

Example 23 with Position

use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.

the class LanguageServerImpl method toDiagnostic.

private Diagnostic toDiagnostic(final Issue issue) {
    Diagnostic _diagnostic = new Diagnostic();
    final Procedure1<Diagnostic> _function = (Diagnostic it) -> {
        it.setCode(issue.getCode());
        DiagnosticSeverity _switchResult = null;
        Severity _severity = issue.getSeverity();
        if (_severity != null) {
            switch(_severity) {
                case ERROR:
                    _switchResult = DiagnosticSeverity.Error;
                    break;
                case WARNING:
                    _switchResult = DiagnosticSeverity.Warning;
                    break;
                case INFO:
                    _switchResult = DiagnosticSeverity.Information;
                    break;
                default:
                    _switchResult = DiagnosticSeverity.Hint;
                    break;
            }
        } else {
            _switchResult = DiagnosticSeverity.Hint;
        }
        it.setSeverity(_switchResult);
        it.setMessage(issue.getMessage());
        Integer _elvis = null;
        Integer _lineNumber = issue.getLineNumber();
        if (_lineNumber != null) {
            _elvis = _lineNumber;
        } else {
            _elvis = Integer.valueOf(1);
        }
        final int lineNumber = ((_elvis).intValue() - 1);
        Integer _elvis_1 = null;
        Integer _column = issue.getColumn();
        if (_column != null) {
            _elvis_1 = _column;
        } else {
            _elvis_1 = Integer.valueOf(1);
        }
        final int column = ((_elvis_1).intValue() - 1);
        Integer _elvis_2 = null;
        Integer _length = issue.getLength();
        if (_length != null) {
            _elvis_2 = _length;
        } else {
            _elvis_2 = Integer.valueOf(0);
        }
        final Integer length = _elvis_2;
        Position _position = new Position(lineNumber, column);
        Position _position_1 = new Position(lineNumber, (column + (length).intValue()));
        Range _range = new Range(_position, _position_1);
        it.setRange(_range);
    };
    return ObjectExtensions.<Diagnostic>operator_doubleArrow(_diagnostic, _function);
}
Also used : DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Severity(org.eclipse.xtext.diagnostics.Severity) Range(org.eclipse.lsp4j.Range)

Example 24 with Position

use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.

the class ChangeConverter method _handleReplacements.

protected void _handleReplacements(final IEmfResourceChange change) {
    try {
        final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        try {
            final URI uri = change.getResource().getURI();
            change.getResource().save(outputStream, null);
            byte[] _byteArray = outputStream.toByteArray();
            String _charset = this.getCharset(change.getResource());
            final String newContent = new String(_byteArray, _charset);
            final Function2<Document, XtextResource, List<TextEdit>> _function = (Document document, XtextResource resource) -> {
                List<TextEdit> _xblockexpression = null;
                {
                    Position _position = document.getPosition(0);
                    Position _position_1 = document.getPosition(document.getContents().length());
                    final Range range = new Range(_position, _position_1);
                    final TextEdit textEdit = new TextEdit(range, newContent);
                    _xblockexpression = this.addTextEdit(uri, textEdit);
                }
                return _xblockexpression;
            };
            this.workspaceManager.<List<TextEdit>>doRead(uri, _function);
        } finally {
            outputStream.close();
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) TextEdit(org.eclipse.lsp4j.TextEdit) XtextResource(org.eclipse.xtext.resource.XtextResource) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.eclipse.xtext.ide.server.Document) Range(org.eclipse.lsp4j.Range) URI(org.eclipse.emf.common.util.URI)

Example 25 with Position

use of org.eclipse.lsp4j.Position in project xtext-core by eclipse.

the class ChangeConverter method _handleReplacements.

protected void _handleReplacements(final ITextDocumentChange change) {
    int _size = change.getReplacements().size();
    boolean _greaterThan = (_size > 0);
    if (_greaterThan) {
        final URI uri = change.getNewURI();
        final Function2<Document, XtextResource, List<TextEdit>> _function = (Document document, XtextResource resource) -> {
            List<TextEdit> _xblockexpression = null;
            {
                final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
                    TextEdit _xblockexpression_1 = null;
                    {
                        final Position start = document.getPosition(replacement.getOffset());
                        int _offset = replacement.getOffset();
                        int _length = replacement.getLength();
                        int _plus = (_offset + _length);
                        final Position end = document.getPosition(_plus);
                        final Range range = new Range(start, end);
                        String _replacementText = replacement.getReplacementText();
                        _xblockexpression_1 = new TextEdit(range, _replacementText);
                    }
                    return _xblockexpression_1;
                };
                final List<TextEdit> textEdits = ListExtensions.<ITextReplacement, TextEdit>map(change.getReplacements(), _function_1);
                _xblockexpression = this.addTextEdit(uri, ((TextEdit[]) Conversions.unwrapArray(textEdits, TextEdit.class)));
            }
            return _xblockexpression;
        };
        this.workspaceManager.<List<TextEdit>>doRead(uri, _function);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) XtextResource(org.eclipse.xtext.resource.XtextResource) Document(org.eclipse.xtext.ide.server.Document) Range(org.eclipse.lsp4j.Range) URI(org.eclipse.emf.common.util.URI) TextEdit(org.eclipse.lsp4j.TextEdit) List(java.util.List)

Aggregations

Position (org.eclipse.lsp4j.Position)37 Range (org.eclipse.lsp4j.Range)18 Test (org.junit.Test)10 List (java.util.List)9 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)9 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)7 CompletionList (org.eclipse.lsp4j.CompletionList)6 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)6 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)6 Extension (org.eclipse.xtext.xbase.lib.Extension)6 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)5 CompletionItem (org.eclipse.lsp4j.CompletionItem)4 Diagnostic (org.eclipse.lsp4j.Diagnostic)4 Location (org.eclipse.lsp4j.Location)4 TextEdit (org.eclipse.lsp4j.TextEdit)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 StringReader (java.io.StringReader)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 Path (java.nio.file.Path)2 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)2