Skip to content

Commit

Permalink
feat: add a config option to exclude declaration from LSP references (h…
Browse files Browse the repository at this point in the history
…elix-editor#6886)

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

Fixes: helix-editor#5344

* fix: review

* fix: review
  • Loading branch information
mcdoker18 authored and Triton171 committed Jun 18, 2023
1 parent a237ee0 commit 90c056b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ The following statusline elements can be configured:
| `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.
Expand Down
3 changes: 2 additions & 1 deletion helix-lsp/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ impl Client {
&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();
Expand All @@ -1183,7 +1184,7 @@ impl Client {
position,
},
context: lsp::ReferenceContext {
include_declaration: true,
include_declaration,
},
work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
partial_result_params: lsp::PartialResultParams {
Expand Down
8 changes: 7 additions & 1 deletion helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -365,6 +367,7 @@ impl Default for LspConfig {
display_signature_help_docs: true,
display_inlay_hints: false,
snippets: true,
goto_reference_include_declaration: true,
}
}
}
Expand Down

0 comments on commit 90c056b

Please sign in to comment.