Search in sources :

Example 1 with Position

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

the class ActionScriptTextDocumentService method patch.

private String patch(String sourceText, TextDocumentContentChangeEvent change) {
    Range range = change.getRange();
    Position start = range.getStart();
    StringReader reader = new StringReader(sourceText);
    int offset = lineAndCharacterToOffset(reader, start.getLine(), start.getCharacter());
    return sourceText.substring(0, offset) + change.getText() + sourceText.substring(offset + change.getRangeLength());
}
Also used : Position(org.eclipse.lsp4j.Position) StringReader(java.io.StringReader) Range(org.eclipse.lsp4j.Range)

Example 2 with Position

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

the class ActionScriptTextDocumentService method addCompilerProblem.

private void addCompilerProblem(ICompilerProblem problem, PublishDiagnosticsParams publish) {
    if (!flexLibSDKContainsFalconCompiler) {
        if (problem.getClass().equals(FontEmbeddingNotSupported.class)) {
            //ignore this error because the framework SDK can embed fonts
            return;
        }
    }
    Diagnostic diagnostic = new Diagnostic();
    DiagnosticSeverity severity = LanguageServerUtils.getDiagnosticSeverityFromCompilerProblem(problem);
    diagnostic.setSeverity(severity);
    Range range = LanguageServerUtils.getRangeFromSourceLocation(problem);
    if (range == null) {
        //fall back to an empty range
        range = new Range(new Position(), new Position());
    }
    diagnostic.setRange(range);
    diagnostic.setMessage(problem.toString());
    try {
        Field field = problem.getClass().getDeclaredField("errorCode");
        int errorCode = (int) field.get(problem);
        diagnostic.setCode(Integer.toString(errorCode));
    } catch (Exception e) {
    //skip it
    }
    List<Diagnostic> diagnostics = publish.getDiagnostics();
    diagnostics.add(diagnostic);
}
Also used : Field(java.lang.reflect.Field) DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Position(org.eclipse.lsp4j.Position) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with Position

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

the class LanguageServerUtils method getRangeFromSourceLocation.

/**
     * Converts a compiler source location to a language server range. May
     * return null if the line or column of the source location is -1.
     */
public static Range getRangeFromSourceLocation(ISourceLocation sourceLocation) {
    int line = sourceLocation.getLine();
    int column = sourceLocation.getColumn();
    if (line == -1 || column == -1) {
        //this is probably generated by the compiler somehow
        return null;
    }
    Position start = new Position();
    start.setLine(line);
    start.setCharacter(column);
    int endLine = sourceLocation.getEndLine();
    int endColumn = sourceLocation.getEndColumn();
    if (endLine == -1 || endColumn == -1) {
        endLine = line;
        endColumn = column;
    }
    Position end = new Position();
    end.setLine(endLine);
    end.setCharacter(endColumn);
    Range range = new Range();
    range.setStart(start);
    range.setEnd(end);
    return range;
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Example 4 with Position

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

the class Document method getPosition.

public Position getPosition(final int offset) {
    final int l = this.contents.length();
    if (((offset < 0) || (offset > l))) {
        String _plus = (Integer.valueOf(offset) + " text was : ");
        String _plus_1 = (_plus + this.contents);
        throw new IndexOutOfBoundsException(_plus_1);
    }
    final char NL = '\n';
    int line = 0;
    int column = 0;
    for (int i = 0; (i < l); i++) {
        {
            final char ch = this.contents.charAt(i);
            if ((i == offset)) {
                return new Position(line, column);
            }
            if ((ch == NL)) {
                line++;
                column = 0;
            } else {
                column++;
            }
        }
    }
    return new Position(line, column);
}
Also used : Position(org.eclipse.lsp4j.Position)

Example 5 with Position

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

the class ContentAssistService method createCompletionList.

public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
    try {
        final CompletionList result = new CompletionList();
        result.setIsIncomplete(true);
        final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
        final int caretOffset = document.getOffSet(params.getPosition());
        final Position caretPosition = params.getPosition();
        final TextRegion position = new TextRegion(caretOffset, 0);
        try {
            this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
        } catch (final Throwable _t) {
            if (_t instanceof Throwable) {
                final Throwable t = (Throwable) _t;
                boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
                boolean _not = (!_isOperationCanceledException);
                if (_not) {
                    throw t;
                }
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
        final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
            final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
            item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
            List<CompletionItem> _items = result.getItems();
            _items.add(item);
        };
        IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) ContentAssistEntry(org.eclipse.xtext.ide.editor.contentassist.ContentAssistEntry) TextRegion(org.eclipse.xtext.util.TextRegion) Position(org.eclipse.lsp4j.Position) CompletionItem(org.eclipse.lsp4j.CompletionItem) CompletionList(org.eclipse.lsp4j.CompletionList) List(java.util.List) IdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalAcceptor) IIdeContentProposalAcceptor(org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor)

Aggregations

Position (org.eclipse.lsp4j.Position)133 Test (org.junit.Test)61 Range (org.eclipse.lsp4j.Range)59 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)38 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)25 List (java.util.List)24 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)22 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)18 ArrayList (java.util.ArrayList)17 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)17 Location (org.eclipse.lsp4j.Location)16 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)15 Document (org.eclipse.xtext.ide.server.Document)14 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)12 RenameParams (org.eclipse.lsp4j.RenameParams)11 AbstractLanguageServerTest (org.eclipse.xtext.testing.AbstractLanguageServerTest)11 TextEdit (org.eclipse.lsp4j.TextEdit)10 Arrays (java.util.Arrays)9 Token (org.antlr.v4.runtime.Token)9 TokenStream (org.antlr.v4.runtime.TokenStream)9