folke / trouble.nvim

🚦 A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing.
Apache License 2.0
5.12k stars 172 forks source link

feature: Merge results from different LSP sources sharing the same `uri` and `range` #423

Closed pidgeon777 closed 1 month ago

pidgeon777 commented 2 months ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

When multiple LSP servers are attached to a buffer, they could provide multiple, identical results when querying for the same information (definitions, references...).

For example, let's consider the Trouble lsp results provided by 3 different LSP servers attached to a buffer:

  Definitions  3 
   └╴󰍛  Work\Design\src\TOP.vhd  3 
     ├╴OB  : out   std_ulogic; (lsp_server_1) [426, 8]
     ├╴OB  : out   std_ulogic; (lsp_server_2) [426, 8]
     └╴OB  : out   std_ulogic; (lsp_server_3) [426, 8]
  Implementations  2 
   └╴󰍛  Work\Design\src\TOP.vhd  2 
     ├╴OB  : out   std_ulogic; (lsp_server_2) [426, 8]
     └╴OB  : out   std_ulogic; (lsp_server_1) [426, 8]
  Declarations  1 
   └╴󰍛  Work\Design\src\TOP.vhd  1 
     └╴OB  : out   std_ulogic; (lsp_server_2) [426, 8]

As you can see, the same result is repeated multiple times, with the only difference being the LSP server that provided it.

This redundancy makes the provided results not immediate to read and understand.

Describe the solution you'd like

It would be great to merge the results whose uri and range are the same, for example, this way:

  Definitions  3 
   └╴󰍛  Work\Design\src\TOP.vhd  3 
     ├╴OB  : out   std_ulogic; (lsp_server_1, lsp_server_2, lsp_server_3) [426, 8]
   Implementations  2
    └╴󰍛  Work\Design\src\TOP.vhd  2 
      ├╴OB  : out   std_ulogic; (lsp_server_1, lsp_server_2) [426, 8]
   Declarations  1
    └╴󰍛  Work\Design\src\TOP.vhd  1 
      └╴OB  : out   std_ulogic; (lsp_server_2) [426, 8]

By doing this, the provided information would be far more readable and understandable.

If range is not the same for locations with the same uri, the corresponding results should obviously not be merged.

Describe alternatives you've considered

N/A

Additional context

This merge feature could be added as an option in the settings, named for example merge_results (true/false).

This feature could globally affect all of the result kinds / panels provided by Trouble.

folke commented 1 month ago

You could already implement this, by adding a top level filter that removes any dups.

But this is something you'll have to figure out yourself, using the src code and the example below:

https://github.com/folke/trouble.nvim/blob/dev/docs/examples.md#diagnostics-cascade