diff --git a/lsp/README.md b/lsp/README.md index 489aa901d8..d02a9fb4ef 100644 --- a/lsp/README.md +++ b/lsp/README.md @@ -38,3 +38,6 @@ settings: but not find-references. - `pyrefly.lspPath` [string: '']: if your platform is not supported, you can build pyrefly from source and specify the binary here. +- `python.analysis.showHoverGoToLinks` [boolean: true]: Controls whether hover + tooltips include "Go to definition" and "Go to type definition" navigation + links. Set to `false` for cleaner tooltips with only type information. diff --git a/lsp/package.json b/lsp/package.json index 511b1fb155..e4290d65bd 100644 --- a/lsp/package.json +++ b/lsp/package.json @@ -173,6 +173,12 @@ "default": false } } + }, + "python.analysis.showHoverGoToLinks": { + "type": "boolean", + "default": true, + "description": "Controls whether hover tooltips include 'Go to definition' and 'Go to type definition' navigation links.", + "scope": "resource" } } } diff --git a/pyrefly/lib/lsp/non_wasm/server.rs b/pyrefly/lib/lsp/non_wasm/server.rs index d359346d8b..dbfc157ee0 100644 --- a/pyrefly/lib/lsp/non_wasm/server.rs +++ b/pyrefly/lib/lsp/non_wasm/server.rs @@ -2409,11 +2409,15 @@ impl Server { fn hover(&self, transaction: &Transaction<'_>, params: HoverParams) -> Option { let uri = ¶ms.text_document_position_params.text_document.uri; - let handle = self.make_handle_if_enabled(uri, Some(HoverRequest::METHOD))?; + let (handle, lsp_config) = + self.make_handle_with_lsp_analysis_config_if_enabled(uri, Some(HoverRequest::METHOD))?; let info = transaction.get_module_info(&handle)?; let position = self.from_lsp_position(uri, &info, params.text_document_position_params.position); - get_hover(transaction, &handle, position) + let show_go_to_links = lsp_config + .and_then(|c| c.show_hover_go_to_links) + .unwrap_or(true); + get_hover(transaction, &handle, position, show_go_to_links) } fn inlay_hints( diff --git a/pyrefly/lib/lsp/non_wasm/workspace.rs b/pyrefly/lib/lsp/non_wasm/workspace.rs index fcea1da152..6eecec8bdb 100644 --- a/pyrefly/lib/lsp/non_wasm/workspace.rs +++ b/pyrefly/lib/lsp/non_wasm/workspace.rs @@ -243,6 +243,8 @@ pub struct LspAnalysisConfig { pub diagnostic_mode: Option, pub import_format: Option, pub inlay_hints: Option, + #[serde(default)] + pub show_hover_go_to_links: Option, } fn deserialize_analysis<'de, D>(deserializer: D) -> Result, D::Error> diff --git a/pyrefly/lib/lsp/wasm/hover.rs b/pyrefly/lib/lsp/wasm/hover.rs index b385473142..205a6465d5 100644 --- a/pyrefly/lib/lsp/wasm/hover.rs +++ b/pyrefly/lib/lsp/wasm/hover.rs @@ -104,6 +104,7 @@ pub struct HoverValue { pub type_: Type, pub docstring: Option, pub display: Option, + pub show_go_to_links: bool, } impl HoverValue { @@ -165,8 +166,11 @@ impl HoverValue { .name .as_ref() .map_or("".to_owned(), |s| format!("{s}: ")); - let symbol_def_formatted = - HoverValue::format_symbol_def_locations(&self.type_).unwrap_or("".to_owned()); + let symbol_def_formatted = if self.show_go_to_links { + HoverValue::format_symbol_def_locations(&self.type_).unwrap_or("".to_owned()) + } else { + String::new() + }; let type_display = self .display .clone() @@ -236,6 +240,7 @@ pub fn get_hover( transaction: &Transaction<'_>, handle: &Handle, position: TextSize, + show_go_to_links: bool, ) -> Option { // Handle hovering over an ignore comment if let Some(module) = transaction.get_module_info(handle) { @@ -323,6 +328,7 @@ pub fn get_hover( type_, docstring, display: type_display, + show_go_to_links, } .format(), ) diff --git a/pyrefly/lib/playground.rs b/pyrefly/lib/playground.rs index 1f24e17cfb..5df1020add 100644 --- a/pyrefly/lib/playground.rs +++ b/pyrefly/lib/playground.rs @@ -441,7 +441,7 @@ impl Playground { let handle = self.handles.get(&self.active_filename)?; let transaction = self.state.transaction(); let position = self.to_text_size(&transaction, pos)?; - let hover = get_hover(&transaction, handle, position)?; + let hover = get_hover(&transaction, handle, position, true)?; Some(MonacoHover { contents: vec![hover.contents], }) diff --git a/pyrefly/lib/test/lsp/hover.rs b/pyrefly/lib/test/lsp/hover.rs index 7fdaaa91c8..1306e951d5 100644 --- a/pyrefly/lib/test/lsp/hover.rs +++ b/pyrefly/lib/test/lsp/hover.rs @@ -16,7 +16,7 @@ use crate::state::state::State; use crate::test::util::get_batched_lsp_operations_report; fn get_test_report(state: &State, handle: &Handle, position: TextSize) -> String { - match get_hover(&state.transaction(), handle, position) { + match get_hover(&state.transaction(), handle, position, true) { Some(Hover { contents: HoverContents::Markup(markup), .. diff --git a/website/docs/IDE.mdx b/website/docs/IDE.mdx index ccfc9ba7dd..c308742e48 100644 --- a/website/docs/IDE.mdx +++ b/website/docs/IDE.mdx @@ -37,6 +37,8 @@ The following configuration options are IDE-specific and exposed as VSCode setti - Use a specific interpreter - If the [`Python`](https://marketplace.visualstudio.com/items?itemName=ms-python.python) VSCode extension is installed, [selecting an interpreter](https://code.visualstudio.com/docs/python/environments) will override the interpreter and settings Pyrefly uses to type check your project, even if one is specified in your Pyrefly configuration. - `python.defaultInterpreterPath` will override the default interpreter selected by VSCode for your workspace. +- Control hover tooltip links + - `python.analysis.showHoverGoToLinks` [boolean: true]: Controls whether hover tooltips include "Go to definition" and "Go to type definition" navigation links. Set to `false` for cleaner tooltips with only type information. ## Issues? If you experience issues with the Pyrefly extension, please create an [issue](https://github.com/facebook/pyrefly/issues) on github.