Search in sources :

Example 11 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project freemarker-languageserver by angelozerr.

the class FreemarkerTextDocumentService method triggerValidation.

private void triggerValidation(TextDocumentItem document) {
    String uri = document.getUri();
    List<Diagnostic> diagnostics = validateFMDocument(uri, document.getText());
    fmLanguageServer.getLanguageClient().publishDiagnostics(new PublishDiagnosticsParams(uri, diagnostics));
}
Also used : PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) Diagnostic(org.eclipse.lsp4j.Diagnostic)

Example 12 with PublishDiagnosticsParams

use of org.eclipse.lsp4j.PublishDiagnosticsParams in project freemarker-languageserver by angelozerr.

the class FreemarkerTextDocumentService method didClose.

@Override
public void didClose(DidCloseTextDocumentParams params) {
    documents.onDidCloseTextDocument(params);
    fmDocuments.onDocumentRemoved(params.getTextDocument().getUri());
    TextDocumentIdentifier document = params.getTextDocument();
    String uri = document.getUri();
    fmLanguageServer.getLanguageClient().publishDiagnostics(new PublishDiagnosticsParams(uri, new ArrayList<Diagnostic>()));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ArrayList(java.util.ArrayList)

Example 13 with PublishDiagnosticsParams

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

the class LanguageServerHarness method intialize.

public InitializeResult intialize(File workspaceRoot) throws Exception {
    server = factory.call();
    int parentPid = random.nextInt(40000) + 1000;
    InitializeParams initParams = new InitializeParams();
    if (workspaceRoot != null) {
        initParams.setRootPath(workspaceRoot.toString());
        initParams.setRootUri(UriUtil.toUri(workspaceRoot).toString());
    }
    initParams.setProcessId(parentPid);
    ClientCapabilities clientCap = new ClientCapabilities();
    TextDocumentClientCapabilities textCap = new TextDocumentClientCapabilities();
    CompletionCapabilities completionCap = new CompletionCapabilities(new CompletionItemCapabilities(true));
    textCap.setCompletion(completionCap);
    clientCap.setTextDocument(textCap);
    WorkspaceClientCapabilities workspaceCap = new WorkspaceClientCapabilities();
    workspaceCap.setApplyEdit(true);
    ExecuteCommandCapabilities exeCap = new ExecuteCommandCapabilities();
    exeCap.setDynamicRegistration(true);
    workspaceCap.setExecuteCommand(exeCap);
    clientCap.setWorkspace(workspaceCap);
    initParams.setCapabilities(clientCap);
    initResult = getServer().initialize(initParams).get();
    if (getServer() instanceof LanguageClientAware) {
        ((LanguageClientAware) getServer()).connect(new STS4LanguageClient() {

            @Override
            public void telemetryEvent(Object object) {
            // TODO Auto-generated method stub
            }

            @Override
            public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) {
                // TODO Auto-generated method stub
                return CompletableFuture.completedFuture(new MessageActionItem("Some Message Request Answer"));
            }

            @Override
            public void showMessage(MessageParams messageParams) {
            // TODO Auto-generated method stub
            }

            @Override
            public void publishDiagnostics(PublishDiagnosticsParams diagnostics) {
                receiveDiagnostics(diagnostics);
            }

            @Override
            public void highlight(HighlightParams highlights) {
                receiveHighlights(highlights);
            }

            @Override
            public void logMessage(MessageParams message) {
            // TODO Auto-generated method stub
            }

            @Override
            public CompletableFuture<ApplyWorkspaceEditResponse> applyEdit(ApplyWorkspaceEditParams params) {
                return Mono.fromCallable(() -> {
                    perform(params.getEdit());
                    return new ApplyWorkspaceEditResponse(true);
                }).toFuture();
            }

            @Override
            public CompletableFuture<Void> registerCapability(RegistrationParams params) {
                return CompletableFuture.completedFuture(null);
            }

            @Override
            public void progress(ProgressParams progressEvent) {
            // TODO Auto-generated method stub
            }

            @Override
            public CompletableFuture<Object> moveCursor(CursorMovement cursorMovement) {
                for (Editor editor : activeEditors) {
                    if (editor.getUri().equals(cursorMovement.getUri())) {
                        editor.setCursor(cursorMovement.getPosition());
                        return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(true));
                    }
                }
                return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
            }

            @Override
            public CompletableFuture<ProjectResponse> project(String uri) {
                return CompletableFuture.completedFuture(null);
            }

            @Override
            public CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params) {
                return CompletableFuture.completedFuture("ok");
            }

            @Override
            public CompletableFuture<Object> removeClasspathListener(ClasspathListenerParams classpathListenerParams) {
                return CompletableFuture.completedFuture("ok");
            }
        });
    }
    getServer().initialized();
    return initResult;
}
Also used : CursorMovement(org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixEdit.CursorMovement) ShowMessageRequestParams(org.eclipse.lsp4j.ShowMessageRequestParams) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) CompletionItemCapabilities(org.eclipse.lsp4j.CompletionItemCapabilities) CompletableFuture(java.util.concurrent.CompletableFuture) RegistrationParams(org.eclipse.lsp4j.RegistrationParams) CompletionCapabilities(org.eclipse.lsp4j.CompletionCapabilities) ExecuteCommandCapabilities(org.eclipse.lsp4j.ExecuteCommandCapabilities) ApplyWorkspaceEditParams(org.eclipse.lsp4j.ApplyWorkspaceEditParams) ClasspathListenerParams(org.springframework.ide.vscode.commons.languageserver.jdt.ls.ClasspathListenerParams) STS4LanguageClient(org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient) MessageParams(org.eclipse.lsp4j.MessageParams) LanguageClientAware(org.eclipse.lsp4j.services.LanguageClientAware) HighlightParams(org.springframework.ide.vscode.commons.languageserver.HighlightParams) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) MessageActionItem(org.eclipse.lsp4j.MessageActionItem) WorkspaceClientCapabilities(org.eclipse.lsp4j.WorkspaceClientCapabilities) ApplyWorkspaceEditResponse(org.eclipse.lsp4j.ApplyWorkspaceEditResponse) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) ProgressParams(org.springframework.ide.vscode.commons.languageserver.ProgressParams)

Example 14 with PublishDiagnosticsParams

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

the class SimpleTextDocumentService method publishDiagnostics.

public void publishDiagnostics(TextDocumentIdentifier docId, Collection<Diagnostic> diagnostics) {
    LanguageClient client = server.getClient();
    if (client != null && diagnostics != null) {
        PublishDiagnosticsParams params = new PublishDiagnosticsParams();
        params.setUri(docId.getUri());
        params.setDiagnostics(ImmutableList.copyOf(diagnostics));
        client.publishDiagnostics(params);
    }
}
Also used : LanguageClient(org.eclipse.lsp4j.services.LanguageClient) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams)

Example 15 with PublishDiagnosticsParams

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

the class ActionScriptTextDocumentService method checkFilePathForSyntaxProblems.

private void checkFilePathForSyntaxProblems(Path path) {
    URI uri = path.toUri();
    PublishDiagnosticsParams publish = new PublishDiagnosticsParams();
    ArrayList<Diagnostic> diagnostics = new ArrayList<>();
    publish.setDiagnostics(diagnostics);
    publish.setUri(uri.toString());
    codeProblemTracker.trackFileWithProblems(uri);
    ASParser parser = null;
    Reader reader = getReaderForPath(path);
    if (reader != null) {
        StreamingASTokenizer tokenizer = StreamingASTokenizer.createForRepairingASTokenizer(reader, uri.toString(), null);
        ASToken[] tokens = tokenizer.getTokens(reader);
        if (tokenizer.hasTokenizationProblems()) {
            for (ICompilerProblem problem : tokenizer.getTokenizationProblems()) {
                addCompilerProblem(problem, publish);
            }
        }
        RepairingTokenBuffer buffer = new RepairingTokenBuffer(tokens);
        Workspace workspace = new Workspace();
        workspace.endRequest();
        parser = new ASParser(workspace, buffer);
        FileNode node = new FileNode(workspace);
        try {
            parser.file(node);
        } catch (Exception e) {
            parser = null;
            System.err.println("Failed to parse file (" + path.toString() + "): " + e);
            e.printStackTrace();
        }
        //if an error occurred above, parser will be null
        if (parser != null) {
            for (ICompilerProblem problem : parser.getSyntaxProblems()) {
                addCompilerProblem(problem, publish);
            }
        }
    }
    Diagnostic diagnostic = createDiagnosticWithoutRange();
    diagnostic.setSeverity(DiagnosticSeverity.Information);
    if (reader == null) {
        //the file does not exist
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("File not found: " + path.toAbsolutePath().toString() + ". Error checking disabled.");
    } else if (parser == null) {
        //something terrible happened, and this is the best we can do
        diagnostic.setSeverity(DiagnosticSeverity.Error);
        diagnostic.setMessage("A fatal error occurred while checking for simple syntax problems.");
    } else if (currentProjectOptions == null) {
        //something went wrong while attempting to load and parse the
        //project configuration.
        diagnostic.setMessage("Failed to load project configuration options. Error checking disabled, except for simple syntax problems.");
    } else {
        //we loaded and parsed the project configuration, so something went
        //wrong while checking for errors.
        diagnostic.setMessage("A fatal error occurred while checking for errors. Error checking disabled, except for simple syntax problems.");
    }
    diagnostics.add(diagnostic);
    codeProblemTracker.cleanUpStaleProblems();
    if (languageClient != null) {
        languageClient.publishDiagnostics(publish);
    }
}
Also used : StreamingASTokenizer(org.apache.flex.compiler.internal.parsing.as.StreamingASTokenizer) ArrayList(java.util.ArrayList) Diagnostic(org.eclipse.lsp4j.Diagnostic) Reader(java.io.Reader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ASToken(org.apache.flex.compiler.internal.parsing.as.ASToken) RepairingTokenBuffer(org.apache.flex.compiler.internal.parsing.as.RepairingTokenBuffer) URI(java.net.URI) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ASParser(org.apache.flex.compiler.internal.parsing.as.ASParser) ICompilerProblem(org.apache.flex.compiler.problems.ICompilerProblem) PublishDiagnosticsParams(org.eclipse.lsp4j.PublishDiagnosticsParams) FileNode(org.apache.flex.compiler.internal.tree.as.FileNode) IFileNode(org.apache.flex.compiler.tree.as.IFileNode) Workspace(org.apache.flex.compiler.internal.workspaces.Workspace) IWorkspace(org.apache.flex.compiler.workspaces.IWorkspace)

Aggregations

PublishDiagnosticsParams (org.eclipse.lsp4j.PublishDiagnosticsParams)22 Diagnostic (org.eclipse.lsp4j.Diagnostic)8 URI (java.net.URI)7 ArrayList (java.util.ArrayList)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)6 HashMap (java.util.HashMap)4 ICompilerProblem (org.apache.flex.compiler.problems.ICompilerProblem)4 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 ConcurrentModificationException (java.util.ConcurrentModificationException)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)3 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)3 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2 Workspace (org.apache.flex.compiler.internal.workspaces.Workspace)2 IWorkspace (org.apache.flex.compiler.workspaces.IWorkspace)2