feat: add a config option to exclude declaration from LSP references (#6886)

* feat: added the config option to exclude declaration from reference query

Fixes: #5344

* fix: review

* fix: review
This commit is contained in:
Vitalii Solodilov 2023-04-27 17:30:15 +03:00 committed by GitHub
parent 222be0f1e7
commit 2836ea2ac4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 2 deletions

View File

@ -128,6 +128,7 @@ ### `[editor.lsp]` Section
| `display-inlay-hints` | Display inlay hints[^2] | `false` |
| `display-signature-help-docs` | Display docs under signature help popup | `true` |
| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` |
[^1]: By default, a progress spinner is shown in the statusline beside the file path.
[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix.

View File

@ -1167,6 +1167,7 @@ pub fn goto_reference(
&self,
text_document: lsp::TextDocumentIdentifier,
position: lsp::Position,
include_declaration: bool,
work_done_token: Option<lsp::ProgressToken>,
) -> Option<impl Future<Output = Result<Value>>> {
let capabilities = self.capabilities.get().unwrap();
@ -1183,7 +1184,7 @@ pub fn goto_reference(
position,
},
context: lsp::ReferenceContext {
include_declaration: true,
include_declaration,
},
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
partial_result_params: lsp::PartialResultParams {

View File

@ -1078,13 +1078,19 @@ pub fn goto_implementation(cx: &mut Context) {
}
pub fn goto_reference(cx: &mut Context) {
let config = cx.editor.config();
let (view, doc) = current!(cx.editor);
let language_server = language_server!(cx.editor, doc);
let offset_encoding = language_server.offset_encoding();
let pos = doc.position(view.id, offset_encoding);
let future = match language_server.goto_reference(doc.identifier(), pos, None) {
let future = match language_server.goto_reference(
doc.identifier(),
pos,
config.lsp.goto_reference_include_declaration,
None,
) {
Some(future) => future,
None => {
cx.editor

View File

@ -354,6 +354,8 @@ pub struct LspConfig {
pub display_inlay_hints: bool,
/// Whether to enable snippet support
pub snippets: bool,
/// Whether to include declaration in the goto reference query
pub goto_reference_include_declaration: bool,
}
impl Default for LspConfig {
@ -365,6 +367,7 @@ fn default() -> Self {
display_signature_help_docs: true,
display_inlay_hints: false,
snippets: true,
goto_reference_include_declaration: true,
}
}
}