Search in sources :

Example 1 with Range

use of org.eclipse.lsp4j.Range 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 Range

use of org.eclipse.lsp4j.Range 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 Range

use of org.eclipse.lsp4j.Range 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 Range

use of org.eclipse.lsp4j.Range in project sonarlint-core by SonarSource.

the class SonarLintLanguageServer method convert.

static Optional<Diagnostic> convert(Issue issue) {
    if (issue.getStartLine() != null) {
        Range range = position(issue);
        Diagnostic diagnostic = new Diagnostic();
        DiagnosticSeverity severity = severity(issue.getSeverity());
        diagnostic.setSeverity(severity);
        diagnostic.setRange(range);
        diagnostic.setCode(issue.getRuleKey());
        diagnostic.setMessage(issue.getMessage() + " (" + issue.getRuleKey() + ")");
        diagnostic.setSource(SONARLINT_SOURCE);
        return Optional.of(diagnostic);
    }
    return Optional.empty();
}
Also used : DiagnosticSeverity(org.eclipse.lsp4j.DiagnosticSeverity) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range)

Example 5 with Range

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

the class CodeActionService method recordWorkspaceEdit.

private WorkspaceEdit recordWorkspaceEdit(final Document doc, final XtextResource resource, final IChangeSerializer.IModification<Resource> mod) {
    try {
        final XtextResourceSet rs = new XtextResourceSet();
        final Resource copy = rs.createResource(resource.getURI());
        String _text = resource.getParseResult().getRootNode().getText();
        StringInputStream _stringInputStream = new StringInputStream(_text);
        copy.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
        this.serializer.<Resource>addModification(copy, mod);
        final ArrayList<IEmfResourceChange> documentchanges = CollectionLiterals.<IEmfResourceChange>newArrayList();
        this.serializer.applyModifications(CollectionBasedAcceptor.<IEmfResourceChange>of(documentchanges));
        WorkspaceEdit _workspaceEdit = new WorkspaceEdit();
        final Procedure1<WorkspaceEdit> _function = (WorkspaceEdit it) -> {
            Iterable<ITextDocumentChange> _filter = Iterables.<ITextDocumentChange>filter(documentchanges, ITextDocumentChange.class);
            for (final ITextDocumentChange documentchange : _filter) {
                {
                    final Function1<ITextReplacement, TextEdit> _function_1 = (ITextReplacement replacement) -> {
                        TextEdit _textEdit = new TextEdit();
                        final Procedure1<TextEdit> _function_2 = (TextEdit it_1) -> {
                            it_1.setNewText(replacement.getReplacementText());
                            Position _position = doc.getPosition(replacement.getOffset());
                            Position _position_1 = doc.getPosition(replacement.getEndOffset());
                            Range _range = new Range(_position, _position_1);
                            it_1.setRange(_range);
                        };
                        return ObjectExtensions.<TextEdit>operator_doubleArrow(_textEdit, _function_2);
                    };
                    final List<TextEdit> edits = ListExtensions.<ITextReplacement, TextEdit>map(documentchange.getReplacements(), _function_1);
                    it.getChanges().put(documentchange.getNewURI().toString(), edits);
                }
            }
        };
        return ObjectExtensions.<WorkspaceEdit>operator_doubleArrow(_workspaceEdit, _function);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : Position(org.eclipse.lsp4j.Position) ITextReplacement(org.eclipse.xtext.formatting2.regionaccess.ITextReplacement) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) ITextDocumentChange(org.eclipse.xtext.ide.serializer.ITextDocumentChange) Range(org.eclipse.lsp4j.Range) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) TextEdit(org.eclipse.lsp4j.TextEdit) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) IEmfResourceChange(org.eclipse.xtext.ide.serializer.IEmfResourceChange)

Aggregations

Range (org.eclipse.lsp4j.Range)126 Position (org.eclipse.lsp4j.Position)59 Test (org.junit.Test)38 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)23 TextEdit (org.eclipse.lsp4j.TextEdit)23 ArrayList (java.util.ArrayList)22 List (java.util.List)17 Location (org.eclipse.lsp4j.Location)16 Document (org.eclipse.xtext.ide.server.Document)16 Diagnostic (org.eclipse.lsp4j.Diagnostic)15 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)13 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)13 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)12 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)12 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)9 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)9 Command (org.eclipse.lsp4j.Command)9 CompletionList (org.eclipse.lsp4j.CompletionList)9 RenameParams (org.eclipse.lsp4j.RenameParams)9 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)8