Skip to content

Commit 0dfa27a

Browse files
impl ?
1 parent 165ee55 commit 0dfa27a

File tree

7 files changed

+302
-42
lines changed

7 files changed

+302
-42
lines changed

crates/pyrefly_types/src/display.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
//! Display a type. The complexity comes from if we have two classes with the same name,
99
//! we want to display disambiguating information (e.g. module name or location).
10+
use std::cell::RefCell;
1011
use std::fmt;
1112
use std::fmt::Display;
1213

14+
use dupe::Dupe;
1315
use pyrefly_python::module_name::ModuleName;
1416
use pyrefly_python::qname::QName;
1517
use pyrefly_util::display::Fmt;
@@ -87,6 +89,7 @@ pub struct TypeDisplayContext<'a> {
8789
/// Should we display for IDE Hover? This makes type names more readable but less precise.
8890
hover: bool,
8991
always_display_module_name: bool,
92+
display_modules: RefCell<SmallSet<ModuleName>>,
9093
}
9194

9295
impl<'a> TypeDisplayContext<'a> {
@@ -232,13 +235,26 @@ impl<'a> TypeDisplayContext<'a> {
232235
name: &str,
233236
f: &mut fmt::Formatter<'_>,
234237
) -> fmt::Result {
238+
self.display_modules
239+
.borrow_mut()
240+
.insert(ModuleName::from_str(module));
235241
if self.always_display_module_name {
236242
write!(f, "{module}.{name}")
237243
} else {
238244
write!(f, "{name}")
239245
}
240246
}
241247

248+
pub fn referenced_modules(&self) -> SmallSet<ModuleName> {
249+
let mut modules = self.display_modules.borrow().clone();
250+
for info in self.qnames.values() {
251+
for module in info.info.keys() {
252+
modules.insert(module.dupe());
253+
}
254+
}
255+
modules
256+
}
257+
242258
fn fmt_helper<'b>(
243259
&self,
244260
t: &'b Type,

pyrefly/lib/lsp/non_wasm/server.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ use crate::lsp::non_wasm::module_helpers::module_info_to_uri;
196196
use crate::lsp::non_wasm::queue::HeavyTaskQueue;
197197
use crate::lsp::non_wasm::queue::LspEvent;
198198
use crate::lsp::non_wasm::queue::LspQueue;
199-
use crate::lsp::non_wasm::stdlib::is_python_stdlib_file;
200-
use crate::lsp::non_wasm::stdlib::should_show_stdlib_error;
201199
use crate::lsp::non_wasm::transaction_manager::TransactionManager;
202200
use crate::lsp::non_wasm::will_rename_files::will_rename_files;
203201
use crate::lsp::non_wasm::workspace::LspAnalysisConfig;
@@ -2339,20 +2337,29 @@ impl Server {
23392337
.into_iter()
23402338
.filter_map(|x| {
23412339
// If the url is a notebook cell, filter out inlay hints for other cells
2342-
if info.to_cell_for_lsp(x.0) != maybe_cell_idx {
2340+
if info.to_cell_for_lsp(x.position) != maybe_cell_idx {
23432341
return None;
23442342
}
2345-
let position = info.to_lsp_position(x.0);
2343+
let position = info.to_lsp_position(x.position);
23462344
// The range is half-open, so the end position is exclusive according to the spec.
23472345
if position >= range.start && position < range.end {
2346+
let mut text_edits = Vec::with_capacity(1 + x.import_edits.len());
2347+
text_edits.push(TextEdit {
2348+
range: Range::new(position, position),
2349+
new_text: x.label.clone(),
2350+
});
2351+
for (offset, import_text) in x.import_edits {
2352+
let insert_position = info.to_lsp_position(offset);
2353+
text_edits.push(TextEdit {
2354+
range: Range::new(insert_position, insert_position),
2355+
new_text: import_text,
2356+
});
2357+
}
23482358
Some(InlayHint {
23492359
position,
2350-
label: InlayHintLabel::String(x.1.clone()),
2360+
label: InlayHintLabel::String(x.label),
23512361
kind: None,
2352-
text_edits: Some(vec![TextEdit {
2353-
range: Range::new(position, position),
2354-
new_text: x.1,
2355-
}]),
2362+
text_edits: Some(text_edits),
23562363
tooltip: None,
23572364
padding_left: None,
23582365
padding_right: None,

pyrefly/lib/playground.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,12 @@ impl Playground {
515515
.get_module_info(handle)
516516
.zip(transaction.inlay_hints(handle, Default::default()))
517517
.map(|(info, hints)| {
518-
hints.into_map(|(position, label)| {
519-
let position = Position::from_display_pos(info.display_pos(position));
520-
InlayHint { label, position }
518+
hints.into_map(|hint| {
519+
let position = Position::from_display_pos(info.display_pos(hint.position));
520+
InlayHint {
521+
label: hint.label,
522+
position,
523+
}
521524
})
522525
})
523526
.unwrap_or_default()

0 commit comments

Comments
 (0)