Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new LSP extension for workspace symbol lookup #7698

Merged
merged 1 commit into from
May 18, 2021

Conversation

alcroito
Copy link
Contributor

As well as all symbol types (functions, modules).

Remove outdated documentation regarding symbol lookup filtering.

Closes #4881

@alcroito
Copy link
Contributor Author

The current PR makes the UX of using RA with VSCode a bit nicer (IMHO), but I realize it removes the filtering functionality from other editors.

If that's unacceptable, perhaps we could expose these filtering knobs as settings to be controlled in VSCode? Or detect VSCode as the LSP client and set them accordingly?

@matklad
Copy link
Member

matklad commented Feb 17, 2021

Yeah, it's sad that this got broken in vs code. That being said, I think searching in the current workspace by default works better, and I definitely think that we should keep the heuristic of "search for types by default, if there are no results, search for all symbols instead".

Let's make this user configurable. In config.rs, I think we should add:

search.dependencies: bool = false,
search.allSymbols: bool = false,

@petr-tik
Copy link
Contributor

Let's make this user configurable. In config.rs, I think we should add:

search.dependencies: bool = false,
search.allSymbols: bool = false,

Would it be possible to override these settings on per-request basis? i.e. starting ra with default to not search dependencies, but changing it for 1 request, when you might want to see them.

I think this is the perfect usecase for an elisp function that takes an optional prefix argument similar to this function in lsp-clangd. That way, we can call M-x lsp-find-workspace-symbol or C-u M-x lsp-find-workspace-symbol to include dependencies in the results.

@matklad
Copy link
Member

matklad commented Feb 19, 2021

@petr-tik emacs can directly add * and # to the query string, this PR is specifically for VS Code.

That being said, given that #* workaround is broken in vscode, it make sense to design a proper LSP extension here. See the how-to for how this should be done: https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/dev#how-to-

basically, we need to add two fields to lsp request params: search_scope and search_kinds

@alcroito alcroito changed the title Workspace symbol lookup includes symbols from dependencies by default Add a new LSP extension for Workspace symbol lookup Feb 23, 2021
@alcroito alcroito changed the title Add a new LSP extension for Workspace symbol lookup WIP: Add a new LSP extension for Workspace symbol lookup Feb 23, 2021
@alcroito
Copy link
Contributor Author

alcroito commented Feb 23, 2021

Pushed code to implement a new LSP extension extending the usual workspace symbol lookup request.

Aside from bikeshedding names (suggestions welcomes), I'd like some feedback for a few open points:

  1. I added the additional search_scope and search_kind params to both the global server config, as well as to the request. Is that desirable?
  2. I assume we want a search_kind enum instead of an OR'ed flag-like search_kinds to keep it simple?
  3. Currently the logic still checks for the * and # markers because there might be existing LSP clients using that. Do we want it? Current precedence logic is markers (most important) -> request params -> global config
  4. config.rs currently transforms WorskpaceSymbolSearchScopeDef into lsp_ext::WorkspaceSymbolSearchScope. I'm not sure if we want an additional enum / struct indirection in between those.
  5. I haven't actually tested the per-request params case, only the VSCode setting -> rust-analyzer global config path. Is there an easy way to check the per-request case?

Of course let me know if i did something incorrectly.

@flodiebold
Copy link
Member

Since the markers work fine in Emacs, I would vote for keeping them.

@kjeremy
Copy link
Contributor

kjeremy commented Feb 23, 2021

Should we file an issue or proposal on https://github.com/microsoft/language-server-protocol?

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, sorry @alcroito, this fell of my radar. Feel free to tag @matklad if the PR is not reviewed.

The PR looks good to me as is (so, you picked the right answers for your questions!), we'd only want to expand the extension docs to actually specify the accepted format.

Is there an easy way to check the per-request case?

I don't think so, it's probably best to wait until Emacs some editor implements support for this.

docs/dev/lsp-extensions.md Outdated Show resolved Hide resolved
@alcroito alcroito force-pushed the fix_workspace_symbol_lookup branch from 2c35605 to abf4115 Compare May 17, 2021 21:58
@alcroito alcroito changed the title WIP: Add a new LSP extension for Workspace symbol lookup Add new LSP extension for workspace symbol lookup May 17, 2021
@alcroito
Copy link
Contributor Author

alcroito commented May 17, 2021

Updated PR.

Should I add some caveat / note to https://rust-analyzer.github.io/manual.html#workspace-symbol that the # and * markers don't work with VSCode?

@matklad
Copy link
Member

matklad commented May 17, 2021 via email

The new extension allows filtering of workspace symbool lookup
results by search scope or search kind.

Filtering can be configured in 3 different ways:

 - The '#' or '*' markers can be added inline with the symbol lookup
   query.

   The '#' marker means symbols should be looked up in the current
   workspace and any dependencies. If not specified, only current
   workspace is considered.

   The '*' marker means all kinds of symbols should be looked up
   (types, functions, etc). If not specified, only type symbols are
   returned.

 - Each LSP request can take an optional search_scope or search_kind
   argument query parameter.

 - Finally there are 2 global config options that can be set for all
   requests served by the active RA instance.

Add support for setting the global config options to the VSCode
extension.
The extension does not use the per-request way, but it's useful for
other IDEs.

The latest version of VSCode filters out the inline markers, so
currently the only reasonable way to use the new functionality is
via the global config.
@alcroito alcroito force-pushed the fix_workspace_symbol_lookup branch from abf4115 to 1f7d2a6 Compare May 17, 2021 22:42
@alcroito
Copy link
Contributor Author

Updated manual to mention VSCode users shouldn't use the filtering symbols, but should rely on the config settings instead.

@matklad
Copy link
Member

matklad commented May 18, 2021

bors r+

Thanks!

bors bot added a commit that referenced this pull request May 18, 2021
7698: Add new LSP extension for workspace symbol lookup r=matklad a=alcroito

As well as all symbol types (functions, modules).

Remove outdated documentation regarding symbol lookup filtering.

Closes #4881

Co-authored-by: alcroito <placinta@gmail.com>
@bors
Copy link
Contributor

bors bot commented May 18, 2021

Timed out.

@lnicola
Copy link
Member

lnicola commented May 18, 2021

bors retry

bors bot added a commit that referenced this pull request May 18, 2021
7698: Add new LSP extension for workspace symbol lookup r=matklad a=alcroito

As well as all symbol types (functions, modules).

Remove outdated documentation regarding symbol lookup filtering.

Closes #4881

Co-authored-by: alcroito <placinta@gmail.com>
@bors
Copy link
Contributor

bors bot commented May 18, 2021

Timed out.

@lnicola
Copy link
Member

lnicola commented May 18, 2021

bors retry

@bors
Copy link
Contributor

bors bot commented May 18, 2021

@bors bors bot merged commit 49a5d6a into rust-lang:master May 18, 2021
@alcroito alcroito deleted the fix_workspace_symbol_lookup branch May 18, 2021 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workspace symbol search returns no results when query includes dependencies
6 participants