Search in sources :

Example 6 with TextDocumentContentChangeEvent

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

the class ServerMainTest method testCodeActionRuleDescription.

@Test
public void testCodeActionRuleDescription() throws Exception {
    String uri = getUri("foo.js");
    VersionedTextDocumentIdentifier docId = new VersionedTextDocumentIdentifier(1);
    docId.setUri(uri);
    lsProxy.getTextDocumentService().didChange(new DidChangeTextDocumentParams(docId, Collections.singletonList(new TextDocumentContentChangeEvent("function foo() {\n  alert('toto');\n}"))));
    List<? extends Command> codeActions = lsProxy.getTextDocumentService().codeAction(new CodeActionParams(new TextDocumentIdentifier(uri), new Range(new Position(1, 4), new Position(1, 4)), new CodeActionContext(waitForDiagnostics(uri)))).get();
    assertThat(codeActions).hasSize(1);
    String ruleKey = (String) codeActions.get(0).getArguments().get(0);
    assertThat(ruleKey).isEqualTo("javascript:S1442");
    lsProxy.getWorkspaceService().executeCommand(new ExecuteCommandParams(codeActions.get(0).getCommand(), codeActions.get(0).getArguments())).get();
    assertThat(client.ruleDescs).hasSize(1);
    assertThat(client.ruleDescs.get(0).getKey()).isEqualTo("javascript:S1442");
    assertThat(client.ruleDescs.get(0).getName()).contains("\"alert(...)\" should not be used");
    assertThat(client.ruleDescs.get(0).getHtmlDescription()).contains("can be useful for debugging during development");
    assertThat(client.ruleDescs.get(0).getType()).isEqualTo("VULNERABILITY");
    assertThat(client.ruleDescs.get(0).getSeverity()).isEqualTo("MINOR");
}
Also used : DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Position(org.eclipse.lsp4j.Position) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) Range(org.eclipse.lsp4j.Range) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) Test(org.junit.Test)

Example 7 with TextDocumentContentChangeEvent

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

the class LanguageServerImpl method didChange.

@Override
public void didChange(final DidChangeTextDocumentParams params) {
    final Function0<BuildManager.Buildable> _function = () -> {
        final Function1<TextDocumentContentChangeEvent, TextEdit> _function_1 = (TextDocumentContentChangeEvent event) -> {
            Range _range = event.getRange();
            String _text = event.getText();
            return new TextEdit(_range, _text);
        };
        return this.workspaceManager.didChange(this._uriExtensions.toUri(params.getTextDocument().getUri()), params.getTextDocument().getVersion(), ListExtensions.<TextDocumentContentChangeEvent, TextEdit>map(params.getContentChanges(), _function_1));
    };
    final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
        return buildable.build(cancelIndicator);
    };
    this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) Range(org.eclipse.lsp4j.Range) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) TextEdit(org.eclipse.lsp4j.TextEdit) BuildManager(org.eclipse.xtext.ide.server.BuildManager) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Example 8 with TextDocumentContentChangeEvent

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

the class DocumentTest method change.

private TextDocumentContentChangeEvent change(Position startPos, Position endPos, String newText) {
    TextDocumentContentChangeEvent textDocumentContentChangeEvent = new TextDocumentContentChangeEvent();
    if (startPos != null) {
        textDocumentContentChangeEvent.setRange(new Range(startPos, endPos));
    }
    textDocumentContentChangeEvent.setText(newText);
    return textDocumentContentChangeEvent;
}
Also used : Range(org.eclipse.lsp4j.Range) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent)

Example 9 with TextDocumentContentChangeEvent

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

the class OpenDocumentTest method testDidChange.

@Test
public void testDidChange() {
    String model = "type Test {\n" + "    NonExisting foo\n" + "}\n";
    String firstFile = writeFile("MyType1.testlang", model);
    initialize();
    assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
    open(firstFile, model);
    assertEquals("Couldn't resolve reference to TypeDeclaration 'NonExisting'.", Iterables.getFirst(getDiagnostics().get(firstFile), null).getMessage());
    DidChangeTextDocumentParams didChangeTextDocumentParams = new DidChangeTextDocumentParams();
    didChangeTextDocumentParams.setTextDocument(new VersionedTextDocumentIdentifier(firstFile, 2));
    TextDocumentContentChangeEvent textDocumentContentChangeEvent = new TextDocumentContentChangeEvent("Test");
    textDocumentContentChangeEvent.setRange(new Range(new Position(1, 4), new Position(1, 15)));
    didChangeTextDocumentParams.setContentChanges(Lists.newArrayList(textDocumentContentChangeEvent));
    languageServer.didChange(didChangeTextDocumentParams);
    Assert.assertNull(Iterables.getFirst(getDiagnostics().get(firstFile), null));
}
Also used : DidChangeTextDocumentParams(org.eclipse.lsp4j.DidChangeTextDocumentParams) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) Range(org.eclipse.lsp4j.Range) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent) Test(org.junit.Test)

Example 10 with TextDocumentContentChangeEvent

use of org.eclipse.lsp4j.TextDocumentContentChangeEvent in project sts4 by spring-projects.

the class SimpleTextDocumentService method didOpen.

@Override
public void didOpen(DidOpenTextDocumentParams params) {
    async.execute(() -> {
        TextDocumentItem docId = params.getTextDocument();
        String url = docId.getUri();
        // Log.info("didOpen: "+params.getTextDocument().getUri());
        LanguageId languageId = LanguageId.of(docId.getLanguageId());
        int version = docId.getVersion();
        if (url != null) {
            String text = params.getTextDocument().getText();
            TrackedDocument td = createDocument(url, languageId, version, text).open();
            // Log.info("Opened "+td.getOpenCount()+" times: "+url);
            TextDocument doc = td.getDocument();
            TextDocumentContentChangeEvent change = new TextDocumentContentChangeEvent() {

                @Override
                public Range getRange() {
                    return null;
                }

                @Override
                public Integer getRangeLength() {
                    return null;
                }

                @Override
                public String getText() {
                    return text;
                }
            };
            TextDocumentContentChange evt = new TextDocumentContentChange(doc, ImmutableList.of(change));
            documentChangeListeners.fire(evt);
        }
    });
}
Also used : TextDocumentItem(org.eclipse.lsp4j.TextDocumentItem) TextDocument(org.springframework.ide.vscode.commons.util.text.TextDocument) LanguageId(org.springframework.ide.vscode.commons.util.text.LanguageId) TextDocumentContentChangeEvent(org.eclipse.lsp4j.TextDocumentContentChangeEvent)

Aggregations

TextDocumentContentChangeEvent (org.eclipse.lsp4j.TextDocumentContentChangeEvent)16 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)9 DidChangeTextDocumentParams (org.eclipse.lsp4j.DidChangeTextDocumentParams)7 Range (org.eclipse.lsp4j.Range)7 TextDocumentItem (org.eclipse.lsp4j.TextDocumentItem)4 ArrayList (java.util.ArrayList)3 Position (org.eclipse.lsp4j.Position)3 Test (org.junit.Test)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)2 DeleteEdit (org.eclipse.text.edits.DeleteEdit)2 InsertEdit (org.eclipse.text.edits.InsertEdit)2 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)2 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)2 TextEdit (org.eclipse.text.edits.TextEdit)2 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)2 Path (java.nio.file.Path)1 List (java.util.List)1