on master help sign in
feat: add a config option to exclude declaration from LSP references (#6886)
2836ea2Vitalii Solodilov
book/src/configuration.md+1
@@ -128,6 +128,7 @@ The following statusline elements can be configured:
128| `display-inlay-hints` | Display inlay hints[^2] | `false` |
128| `display-inlay-hints` | Display inlay hints[^2] | `false` |
129| `display-signature-help-docs` | Display docs under signature help popup | `true` |
129| `display-signature-help-docs` | Display docs under signature help popup | `true` |
130| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
130| `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` |
131
132
132[^1]: By default, a progress spinner is shown in the statusline beside the file path.
133[^1]: By default, a progress spinner is shown in the statusline beside the file path.
133[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix.
134[^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 {
1167 &self,
1167 &self,
1168 text_document: lsp::TextDocumentIdentifier,
1168 text_document: lsp::TextDocumentIdentifier,
1169 position: lsp::Position,
1169 position: lsp::Position,
1170+ include_declaration: bool,
1170 work_done_token: Option<lsp::ProgressToken>,
1171 work_done_token: Option<lsp::ProgressToken>,
1171 ) -> Option<impl Future<Output = Result<Value>>> {
1172 ) -> Option<impl Future<Output = Result<Value>>> {
1172 let capabilities = self.capabilities.get().unwrap();
1173 let capabilities = self.capabilities.get().unwrap();
@@ -1183,7 +1184,7 @@ impl Client {
1183 position,
1184 position,
1184 },
1185 },
1185 context: lsp::ReferenceContext {
1186 context: lsp::ReferenceContext {
1186− include_declaration: true,
1187+ include_declaration,
1187 },
1188 },
1188 work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
1189 work_done_progress_params: lsp::WorkDoneProgressParams { work_done_token },
1189 partial_result_params: lsp::PartialResultParams {
1190 partial_result_params: lsp::PartialResultParams {
helix-term/src/commands/lsp.rs+7−1
@@ -1078,13 +1078,19 @@ pub fn goto_implementation(cx: &mut Context) {
1078}
1078}
1079
1079
1080pub fn goto_reference(cx: &mut Context) {
1080pub fn goto_reference(cx: &mut Context) {
1081+ let config = cx.editor.config();
1081 let (view, doc) = current!(cx.editor);
1082 let (view, doc) = current!(cx.editor);
1082 let language_server = language_server!(cx.editor, doc);
1083 let language_server = language_server!(cx.editor, doc);
1083 let offset_encoding = language_server.offset_encoding();
1084 let offset_encoding = language_server.offset_encoding();
1084
1085
1085 let pos = doc.position(view.id, offset_encoding);
1086 let pos = doc.position(view.id, offset_encoding);
1086
1087
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+ ) {
1088 Some(future) => future,
1094 Some(future) => future,
1089 None => {
1095 None => {
1090 cx.editor
1096 cx.editor
helix-view/src/editor.rs+3
@@ -354,6 +354,8 @@ pub struct LspConfig {
354 pub display_inlay_hints: bool,
354 pub display_inlay_hints: bool,
355 /// Whether to enable snippet support
355 /// Whether to enable snippet support
356 pub snippets: bool,
356 pub snippets: bool,
357+ /// Whether to include declaration in the goto reference query
358+ pub goto_reference_include_declaration: bool,
357}
359}
358
360
359impl Default for LspConfig {
361impl Default for LspConfig {
@@ -365,6 +367,7 @@ impl Default for LspConfig {
365 display_signature_help_docs: true,
367 display_signature_help_docs: true,
366 display_inlay_hints: false,
368 display_inlay_hints: false,
367 snippets: true,
369 snippets: true,
370+ goto_reference_include_declaration: true,
368 }
371 }
369 }
372 }
370}
373}