on master help sign in
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

commit2836ea2ac40bd54ec1b00ffcd5927cdb4b7724d3 authorVitalii Solodilov <Mcdkr@yandex.ru> dateThu 27 Apr 2023, 17:30 (4 years ago) parent222be0f
4 files changed+13−2
book/src/configuration.md+1 helix-lsp/src/client.rs+2−1 helix-term/src/commands/lsp.rs+7−1 helix-view/src/editor.rs+3
book/src/configuration.md+1
@@ -128,6 +128,7 @@ The following statusline elements can be configured:
128128| `display-inlay-hints` | Display inlay hints[^2] | `false` |
129129| `display-signature-help-docs` | Display docs under signature help popup | `true` |
130130| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
131+| `goto-reference-include-declaration` | Include declaration in the goto references popup. | `true` |
131132
132133[^1]: By default, a progress spinner is shown in the statusline beside the file path.
133134[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix.
helix-lsp/src/client.rs+2−1
@@ -1167,6 +1167,7 @@ impl Client {
11671167 &self,
11681168 text_document: lsp::TextDocumentIdentifier,
11691169 position: lsp::Position,
1170+ include_declaration: bool,
11701171 work_done_token: Option<lsp::ProgressToken>,
11711172 ) -> Option<impl Future<Output = Result<Value>>> {
11721173 let capabilities = self.capabilities.get().unwrap();
@@ -1183,7 +1184,7 @@ impl Client {
11831184 position,
11841185 },
11851186 context: lsp::ReferenceContext {
1186− include_declaration: true,
1187+ include_declaration,
11871188 },
11881189 work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
11891190 partial_result_params: lsp::PartialResultParams {
helix-term/src/commands/lsp.rs+7−1
@@ -1078,13 +1078,19 @@ pub fn goto_implementation(cx: &mut Context) {
10781078}
10791079
10801080pub fn goto_reference(cx: &mut Context) {
1081+ let config = cx.editor.config();
10811082 let (view, doc) = current!(cx.editor);
10821083 let language_server = language_server!(cx.editor, doc);
10831084 let offset_encoding = language_server.offset_encoding();
10841085
10851086 let pos = doc.position(view.id, offset_encoding);
10861087
1087− let future = match language_server.goto_reference(doc.identifier(), pos, None) {
1088+ let future = match language_server.goto_reference(
1089+ doc.identifier(),
1090+ pos,
1091+ config.lsp.goto_reference_include_declaration,
1092+ None,
1093+ ) {
10881094 Some(future) => future,
10891095 None => {
10901096 cx.editor
helix-view/src/editor.rs+3
@@ -354,6 +354,8 @@ pub struct LspConfig {
354354 pub display_inlay_hints: bool,
355355 /// Whether to enable snippet support
356356 pub snippets: bool,
357+ /// Whether to include declaration in the goto reference query
358+ pub goto_reference_include_declaration: bool,
357359}
358360
359361impl Default for LspConfig {
@@ -365,6 +367,7 @@ impl Default for LspConfig {
365367 display_signature_help_docs: true,
366368 display_inlay_hints: false,
367369 snippets: true,
370+ goto_reference_include_declaration: true,
368371 }
369372 }
370373}