Search in sources :

Example 1 with TextDocumentIdentifier

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

the class ActionScriptTextDocumentService method isInXMLComment.

private boolean isInXMLComment(TextDocumentPositionParams params) {
    TextDocumentIdentifier textDocument = params.getTextDocument();
    Path path = LanguageServerUtils.getPathFromLanguageServerURI(textDocument.getUri());
    if (path == null || !sourceByPath.containsKey(path)) {
        return false;
    }
    String code = sourceByPath.get(path);
    int startComment = code.lastIndexOf("<!--", currentOffset - 1);
    if (startComment == -1) {
        return false;
    }
    int endComment = code.indexOf("-->", startComment);
    return endComment > currentOffset;
}
Also used : Path(java.nio.file.Path) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier)

Example 2 with TextDocumentIdentifier

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

the class ServerMainTest method cleanDiagnosticsOnClose.

@Test
public void cleanDiagnosticsOnClose() throws Exception {
    String uri = getUri("foo.js");
    lsProxy.getTextDocumentService().didClose(new DidCloseTextDocumentParams(new TextDocumentIdentifier(uri)));
    assertThat(waitForDiagnostics(uri)).isEmpty();
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) DidCloseTextDocumentParams(org.eclipse.lsp4j.DidCloseTextDocumentParams) Test(org.junit.Test)

Example 3 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project erlide_eclipse by erlang.

the class LanguageServerEclipseUtils method toTextDocumentPosistionParams.

public static TextDocumentPositionParams toTextDocumentPosistionParams(final URI fileUri, final int offset, final IDocument document) throws BadLocationException {
    final Position start = LanguageServerEclipseUtils.toPosition(offset, document);
    final TextDocumentPositionParams param = new TextDocumentPositionParams();
    param.setPosition(start);
    final TextDocumentIdentifier id = new TextDocumentIdentifier(fileUri.toString());
    param.setTextDocument(id);
    return param;
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) TextDocumentPositionParams(org.eclipse.lsp4j.TextDocumentPositionParams)

Example 4 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class AbstractQuickFixTest method evaluateCodeActions.

protected List<Command> evaluateCodeActions(ICompilationUnit cu) throws JavaModelException {
    CompilationUnit astRoot = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
    IProblem[] problems = astRoot.getProblems();
    Range range = getRange(cu, problems);
    CodeActionParams parms = new CodeActionParams();
    TextDocumentIdentifier textDocument = new TextDocumentIdentifier();
    textDocument.setUri(JDTUtils.toURI(cu));
    parms.setTextDocument(textDocument);
    parms.setRange(range);
    CodeActionContext context = new CodeActionContext();
    context.setDiagnostics(DiagnosticsHandler.toDiagnosticsArray(cu, Arrays.asList(problems)));
    parms.setContext(context);
    List<Command> commands = new CodeActionHandler().getCodeActionCommands(parms, new NullProgressMonitor());
    if (this.ignoredCommands != null) {
        List<Command> filteredList = new ArrayList<>();
        for (Command command : commands) {
            for (String str : this.ignoredCommands) {
                if (command.getTitle().matches(str)) {
                    filteredList.add(command);
                    break;
                }
            }
        }
        commands.removeAll(filteredList);
    }
    return commands;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CodeActionParams(org.eclipse.lsp4j.CodeActionParams) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) IProblem(org.eclipse.jdt.core.compiler.IProblem) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) CodeActionHandler(org.eclipse.jdt.ls.core.internal.handlers.CodeActionHandler) Command(org.eclipse.lsp4j.Command)

Example 5 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class CodeActionHandlerTest method testCodeAction_removeUnterminatedString.

@Test
public void testCodeAction_removeUnterminatedString() throws Exception {
    ICompilationUnit unit = getWorkingCopy("src/java/Foo.java", "public class Foo {\n" + "	void foo() {\n" + "String s = \"some str\n" + "	}\n" + "}\n");
    CodeActionParams params = new CodeActionParams();
    params.setTextDocument(new TextDocumentIdentifier(JDTUtils.toURI(unit)));
    final Range range = getRange(unit, "some str");
    params.setRange(range);
    params.setContext(new CodeActionContext(Arrays.asList(getDiagnostic(Integer.toString(IProblem.UnterminatedString), range))));
    List<? extends Command> commands = server.codeAction(params).join();
    Assert.assertNotNull(commands);
    Assert.assertEquals(1, commands.size());
    Command c = commands.get(0);
    Assert.assertEquals(CodeActionHandler.COMMAND_ID_APPLY_EDIT, c.getCommand());
}
Also used : CodeActionParams(org.eclipse.lsp4j.CodeActionParams) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Command(org.eclipse.lsp4j.Command) Range(org.eclipse.lsp4j.Range) Test(org.junit.Test)

Aggregations

TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)83 Position (org.eclipse.lsp4j.Position)37 Test (org.junit.Test)37 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)25 Range (org.eclipse.lsp4j.Range)23 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)20 List (java.util.List)14 RenameParams (org.eclipse.lsp4j.RenameParams)14 Document (org.eclipse.xtext.ide.server.Document)14 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)13 Extension (org.eclipse.xtext.xbase.lib.Extension)12 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)11 CompletionList (org.eclipse.lsp4j.CompletionList)10 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)9 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)9 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)8 Path (java.nio.file.Path)7 Command (org.eclipse.lsp4j.Command)7 Location (org.eclipse.lsp4j.Location)7 URI (java.net.URI)6