Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lsp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 6 additions & 0 deletions lsp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions pyrefly/lib/lsp/non_wasm/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2409,11 +2409,15 @@ impl Server {

fn hover(&self, transaction: &Transaction<'_>, params: HoverParams) -> Option<Hover> {
let uri = &params.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(
Expand Down
2 changes: 2 additions & 0 deletions pyrefly/lib/lsp/non_wasm/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ pub struct LspAnalysisConfig {
pub diagnostic_mode: Option<DiagnosticMode>,
pub import_format: Option<ImportFormat>,
pub inlay_hints: Option<InlayHintConfig>,
#[serde(default)]
pub show_hover_go_to_links: Option<bool>,
}

fn deserialize_analysis<'de, D>(deserializer: D) -> Result<Option<LspAnalysisConfig>, D::Error>
Expand Down
10 changes: 8 additions & 2 deletions pyrefly/lib/lsp/wasm/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub struct HoverValue {
pub type_: Type,
pub docstring: Option<Docstring>,
pub display: Option<String>,
pub show_go_to_links: bool,
}

impl HoverValue {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -236,6 +240,7 @@ pub fn get_hover(
transaction: &Transaction<'_>,
handle: &Handle,
position: TextSize,
show_go_to_links: bool,
) -> Option<Hover> {
// Handle hovering over an ignore comment
if let Some(module) = transaction.get_module_info(handle) {
Expand Down Expand Up @@ -323,6 +328,7 @@ pub fn get_hover(
type_,
docstring,
display: type_display,
show_go_to_links,
}
.format(),
)
Expand Down
2 changes: 1 addition & 1 deletion pyrefly/lib/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
Expand Down
2 changes: 1 addition & 1 deletion pyrefly/lib/test/lsp/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
..
Expand Down
2 changes: 2 additions & 0 deletions website/docs/IDE.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down