gagbo/consult-lsp

Is there a way to filter the results?

furkanusta opened this issue · 4 comments

When I run consult-lsp-symbols I see system methods/class due to the way C++ include's works (I suppose). I'd like to filter those by checking if source files belong to the project. I've checked annotate functions but I do not think they provide the functionality.

I am not sure how much of the work is being done by LSP server, emacs-lsp, consult and this package. Feel free to close this, if it cannot be done at this level easily.

gagbo commented

For all LSP commands, you can use the "narrow" keys from consult to reduce the set of results to certain types. If you want to see all the categories, use C-h v consult-lsp-symbols-narrow.

lsp-symbols in particular, has a specific pattern on top of that (because like consult-grep, it sends user input to an external process - the LSP server - to get the results). So you can also split your query with the async-separator (# by default if I remember correctly) and everything after the # will just be used to filter the current candidates you have in your minibuffer (so you can use it to type some filepath and filter everything by the path). Everything that is before the # will be sent to refine the query to the LSP server.

I've added a screenshot to better explain my use case
Screenshot_20220603_224917

Here I am using narrowing to only show classes but this also includes classes defined in the system libraries /usr/include/qt5... and I'd like to filter those out.

If I use a secondary filter #K#usr I can show only the system libraries but I need an inverse of this functionality. (Since the files already in the project do not have a full path but a relative one I cannot use this approach to show them only).

gagbo commented

You should be able to use #K#!usr can't you ? The part that goes after the second # is going to be used by your own filtering mechanisms. I use orderless and I set it up so that ! as a prefix acts as a negation of the pattern, so I can ignore these things using !usr for example

Oh, I had orderless in my setup but I never tweaked it and this worked like a charm. Thanks.