GithubHelp home page GithubHelp logo

Comments (8)

fannheyward avatar fannheyward commented on June 15, 2024 2

diagnostic.separateRelatedInformationAsDiagnostics has added into coc.nvim.

from coc-rust-analyzer.

fannheyward avatar fannheyward commented on June 15, 2024 1

Agreed, showing related informations will do grep help for user. We should not be limited to how VSCode does.

from coc-rust-analyzer.

fannheyward avatar fannheyward commented on June 15, 2024

coc.nvim + coc-rust-analyzer already support relatedInformation diagnostic, but not displayed in floating window. Put your cursor on line 6 x, current diagnostic position, run :CocCommand workspace.diagnosticRelated, you will get related informations in coc lists.

I'll try to improve this.

from coc-rust-analyzer.

fannheyward avatar fannheyward commented on June 15, 2024

Try :CocUpdate. I've displayed relatedInformation messages with diagnostic message. You still need :CocCommand workspace.diagnosticRelated to do jumping.

from coc-rust-analyzer.

Ferdi265 avatar Ferdi265 commented on June 15, 2024

Thank for the quick answer/fix! Much more usable now :)

However, I usually use the virtual text feature much more than the floating messages, so seeing them there would be the absolute best, but I think I'll try experimenting with the plugin code myself and report my findings when I did :)

from coc-rust-analyzer.

Ferdi265 avatar Ferdi265 commented on June 15, 2024

With a bit of experimentation I managed to create separate diagnostics from the related information.

virtual text related information

IMO this should probably be solved directly in neoclide/coc.nvim though, since many language servers publish related information, which might be useful to see in-editor.

diff --git a/src/client.ts b/src/client.ts
index 4f749af..fdc6862 100644
--- a/src/client.ts
+++ b/src/client.ts
@@ -40,18 +40,26 @@ export function createClient(config: Config, bin: string): LanguageClient {
         return help;
       },
       handleDiagnostics: async (uri, diagnostics, next) => {
+        const mkInfoDiag = (related, diag) => {
+          return {
+            "code": diag.code,
+            "source": diag.source,
+            "message": related.message,
+            "range": related.location.range,
+            "uri": related.location.uri,
+            "severity": 4
+          };
+        };
+        const infos = [];
+
         diagnostics.map((diagnostic) => {
           if (diagnostic.relatedInformation) {
-            let message = `${diagnostic.message}\n\nRelated diagnostics: (Run \`:CocCommand workspace.diagnosticRelated\` to jump)\n`;
             for (const info of diagnostic.relatedInformation) {
-              const basename = path.basename(Uri.parse(info.location.uri).fsPath);
-              const ln = info.location.range.start.line;
-              message = `${message}\n${basename}(line ${ln + 1}): ${info.message}`;
+              infos.push(mkInfoDiag(info, diagnostic));
             }
-            diagnostic.message = message;
           }
         });
-        next(uri, diagnostics);
+        next(uri, diagnostics.concat(infos));
       },
     },
     outputChannel,

from coc-rust-analyzer.

fannheyward avatar fannheyward commented on June 15, 2024

I was going to concat related information as diagnostics to all diagnostics list, same as what your patch does, but this is how VSCode + rust-analyzer does:

Screen Shot 2020-03-26 at 20 54 30

I don't know whether it's correct to separate the related informations to diagnostics list.

from coc-rust-analyzer.

Ferdi265 avatar Ferdi265 commented on June 15, 2024

At least for me, fixing bugs in a larger function is much easier when the related diagnostics are also shown directly in the editor.

It would be cool to have it as an option, so users can choose whether or not they should be shown as separate diagnostics.

Also, integrating the related information into the popup should IMO also be solved in coc.nvim, since it might be useful to have the message structured (this would allow switching between both styles for any language via a config option).

TL;DR:

  • yes, if your whole goal is to just replicate the VS-code plugin, then your patch is better than mine
  • fixing this for all of CoC would make this much more configurable and more flexible, on top of giving the user more choice in how to view his errors / warnings

I'm going to try to look at the CoC codebase, and see if I can integrate something like what you did, and as a configurable option my proposal.

from coc-rust-analyzer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.