Search in sources :

Example 36 with Range

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

the class DocumentExtensions method newRange.

public Range newRange(Resource resource, int startOffset, int endOffset) {
    Position startPosition = newPosition(resource, startOffset);
    if (startPosition == null) {
        return null;
    }
    Position endPosition = newPosition(resource, endOffset);
    if (endPosition == null) {
        return null;
    }
    return new Range(startPosition, endPosition);
}
Also used : Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Example 37 with Range

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

the class ContentAssistService method toCompletionItem.

protected CompletionItem toCompletionItem(ContentAssistEntry entry, int caretOffset, Position caretPosition, Document document) {
    CompletionItem completionItem = new CompletionItem();
    String label = entry.getLabel();
    if (label == null) {
        label = entry.getProposal();
    }
    completionItem.setLabel(label);
    completionItem.setDetail(entry.getDescription());
    completionItem.setDocumentation(entry.getDocumentation());
    String prefix = entry.getPrefix();
    if (prefix == null) {
        prefix = "";
    }
    int prefixOffset = caretOffset - prefix.length();
    Position prefixPosition = document.getPosition(prefixOffset);
    completionItem.setTextEdit(Either.forLeft(new TextEdit(new Range(prefixPosition, caretPosition), entry.getProposal())));
    completionItem.setKind(translateKind(entry));
    if (!entry.getTextReplacements().isEmpty()) {
        if (completionItem.getAdditionalTextEdits() == null) {
            completionItem.setAdditionalTextEdits(new ArrayList<>(entry.getTextReplacements().size()));
        }
        entry.getTextReplacements().forEach((ReplaceRegion it) -> completionItem.getAdditionalTextEdits().add(toTextEdit(it, document)));
    }
    if (ContentAssistEntry.KIND_SNIPPET.equals(entry.getKind())) {
        completionItem.setInsertTextFormat(InsertTextFormat.Snippet);
    }
    return completionItem;
}
Also used : CompletionItem(org.eclipse.lsp4j.CompletionItem) Position(org.eclipse.lsp4j.Position) ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) TextEdit(org.eclipse.lsp4j.TextEdit) Range(org.eclipse.lsp4j.Range)

Example 38 with Range

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

the class AbstractLanguageServerTest method testCodeAction.

protected void testCodeAction(final Procedure1<? super AbstractLanguageServerTest.TestCodeActionConfiguration> configurator) {
    try {
        @Extension final AbstractLanguageServerTest.TestCodeActionConfiguration configuration = new AbstractLanguageServerTest.TestCodeActionConfiguration();
        configuration.setFilePath(("MyModel." + this.fileExtension));
        configurator.apply(configuration);
        final String filePath = this.initializeContext(configuration).getUri();
        CodeActionParams _codeActionParams = new CodeActionParams();
        final Procedure1<CodeActionParams> _function = (CodeActionParams it) -> {
            TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(filePath);
            it.setTextDocument(_textDocumentIdentifier);
            Range _range = new Range();
            final Procedure1<Range> _function_1 = (Range it_1) -> {
                int _line = configuration.getLine();
                int _column = configuration.getColumn();
                Position _position = new Position(_line, _column);
                it_1.setStart(_position);
                it_1.setEnd(it_1.getStart());
            };
            Range _doubleArrow = ObjectExtensions.<Range>operator_doubleArrow(_range, _function_1);
            it.setRange(_doubleArrow);
            CodeActionContext _codeActionContext = new CodeActionContext();
            final Procedure1<CodeActionContext> _function_2 = (CodeActionContext it_1) -> {
                it_1.setDiagnostics(this.getDiagnostics().get(filePath));
            };
            CodeActionContext _doubleArrow_1 = ObjectExtensions.<CodeActionContext>operator_doubleArrow(_codeActionContext, _function_2);
            it.setContext(_doubleArrow_1);
        };
        CodeActionParams _doubleArrow = ObjectExtensions.<CodeActionParams>operator_doubleArrow(_codeActionParams, _function);
        final CompletableFuture<List<Either<Command, CodeAction>>> result = this.languageServer.codeAction(_doubleArrow);
        if ((configuration.assertCodeActions != null)) {
            configuration.assertCodeActions.apply(result.get());
        } else {
            this.assertEquals(configuration.expectedCodeActions, this.toExpectation(result.get()));
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) CodeAction(org.eclipse.lsp4j.CodeAction) FoldingRange(org.eclipse.lsp4j.FoldingRange) Range(org.eclipse.lsp4j.Range) Endpoint(org.eclipse.lsp4j.jsonrpc.Endpoint) Extension(org.eclipse.xtext.xbase.lib.Extension) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList)

Example 39 with Range

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

the class AbstractLanguageServerTest method _toExpectation.

protected String _toExpectation(final DocumentHighlight it) {
    String _xblockexpression = null;
    {
        StringConcatenation _builder = new StringConcatenation();
        {
            Range _range = it.getRange();
            boolean _tripleEquals = (_range == null);
            if (_tripleEquals) {
                _builder.append("[NaN, NaN]:[NaN, NaN]");
            } else {
                String _expectation = this.toExpectation(it.getRange());
                _builder.append(_expectation);
            }
        }
        final String rangeString = _builder.toString();
        StringConcatenation _builder_1 = new StringConcatenation();
        {
            DocumentHighlightKind _kind = it.getKind();
            boolean _tripleEquals_1 = (_kind == null);
            if (_tripleEquals_1) {
                _builder_1.append("NaN");
            } else {
                String _expectation_1 = this.toExpectation(it.getKind());
                _builder_1.append(_expectation_1);
            }
        }
        _builder_1.append(" ");
        _builder_1.append(rangeString);
        _xblockexpression = _builder_1.toString();
    }
    return _xblockexpression;
}
Also used : DocumentHighlightKind(org.eclipse.lsp4j.DocumentHighlightKind) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) FoldingRange(org.eclipse.lsp4j.FoldingRange) Range(org.eclipse.lsp4j.Range)

Example 40 with Range

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

the class CodeLensService method computeCodeLenses.

@Override
public List<? extends CodeLens> computeCodeLenses(Document document, XtextResource resource, CodeLensParams params, CancelIndicator indicator) {
    CodeLens codeLens = new CodeLens();
    Command command = new Command();
    command.setCommand("do.this");
    command.setTitle("Do Awesome Stuff");
    command.setArguments(Lists.newArrayList("foo", Integer.valueOf(1), Boolean.valueOf(true)));
    codeLens.setCommand(command);
    codeLens.setData(new Position(1, 2));
    codeLens.setRange(new Range(new Position(1, 1), new Position(1, 2)));
    return Lists.newArrayList(codeLens);
}
Also used : CodeLens(org.eclipse.lsp4j.CodeLens) Command(org.eclipse.lsp4j.Command) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range)

Aggregations

Range (org.eclipse.lsp4j.Range)293 Test (org.junit.Test)178 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)153 Position (org.eclipse.lsp4j.Position)111 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)105 AbstractSelectionTest (org.eclipse.jdt.ls.core.internal.correction.AbstractSelectionTest)54 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)47 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)47 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)41 ArrayList (java.util.ArrayList)39 Command (org.eclipse.lsp4j.Command)34 List (java.util.List)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)31 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)30 Diagnostic (org.eclipse.lsp4j.Diagnostic)29 TextEdit (org.eclipse.lsp4j.TextEdit)29 CodeAction (org.eclipse.lsp4j.CodeAction)28 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)27 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)25 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)21