emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.78k stars 884 forks source link

Sort xref results #2099

Closed muirdm closed 4 years ago

muirdm commented 4 years ago

Currently gopls returns find-references, find-implementations, go-to-definition, etc. results in a random/useless order. I opened https://github.com/golang/go/issues/40904 to discuss, but previously they have not been receptive to ordering on the server.

It would be useful if lsp-mode would sort the results for me. I propose we sort by file name and then by position within file. For file name, I propose we prefer the origin file, then we prefer files within the same directory (sorted lexicographically), then we just sort remaining files lexicographically.

yyoncho commented 4 years ago

Make sense. As a side note, you may wanna try M-x lsp-treemacs-references and related.

muirdm commented 4 years ago

lsp-treemacs-references

Interesting. Does it support (next-error) functionality to cycle through results? How does it order results?

Also, I got an error trying lsp-treemacs-references on a larger project (it worked on a small project):

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  directory-file-name(nil)
  (file-name-nondirectory (directory-file-name path))
  f-filename(nil)
...
yyoncho commented 4 years ago

Interesting. Does it support (next-error) functionality to cycle through results?

Do you mean next reference? I think that treemacs might have next-node or something.

How does it order results?

ATM it is grouping the results, sorting them is a single liner.

Also, I got an error trying lsp-treemacs-references on a larger project (it worked on a small project):

Is this the full callstack? Can you provide recipe to reproduce that? Most likely filename is missing for some of the results.

muirdm commented 4 years ago

@leungbk sorry, I was playing around with this today and didn't assign myself. I didn't do any heuristics beyond basic file/line/column sorting. It was a learning experience for me so no hard feelings if you do/did something better 😅

leungbk commented 4 years ago

@leungbk sorry, I was playing around with this today and didn't assign myself. I didn't do any heuristics beyond basic file/line/column sorting. It was a learning experience for me so no hard feelings if you do/did something better sweat_smile

It's fine, go ahead and PR when you're ready.

muirdm commented 4 years ago

Should we add any additional sorting heuristics like preferring the current file/folder or just leave it like this for now?

yyoncho commented 4 years ago

Should we add any additional sorting heuristics like preferring the current file/folder or just leave it like this for now?

Leaving up to you to decide. I guess it should be configurable because looks like something that some might want to turn off.

muirdm commented 4 years ago

OK. I've lost steam on this so let's just let the simple sorting percolate and see if people complain or request smarter sorting.