mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Add new completion data to wasm bridge
This commit is contained in:
parent
5816985ecd
commit
64a4e2889e
1 changed files with 40 additions and 7 deletions
|
@ -423,13 +423,32 @@ impl Workspace {
|
||||||
|
|
||||||
Ok(completions
|
Ok(completions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|completion| Completion {
|
.map(|comp| {
|
||||||
kind: completion.kind(&self.db).map(CompletionKind::from),
|
let kind = comp.kind(&self.db).map(CompletionKind::from);
|
||||||
name: completion.name.into(),
|
let type_display = comp.ty.map(|ty| ty.display(&self.db).to_string());
|
||||||
documentation: completion
|
let import_edit = comp.import.as_ref().map(|edit| {
|
||||||
|
let range = Range::from_text_range(
|
||||||
|
edit.range(),
|
||||||
|
&index,
|
||||||
|
&source,
|
||||||
|
self.position_encoding,
|
||||||
|
);
|
||||||
|
TextEdit {
|
||||||
|
range,
|
||||||
|
new_text: edit.content().map(ToString::to_string).unwrap_or_default(),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Completion {
|
||||||
|
name: comp.name.into(),
|
||||||
|
kind,
|
||||||
|
detail: type_display,
|
||||||
|
description: comp.module_name.map(ToString::to_string),
|
||||||
|
insert_text: comp.insert.map(String::from),
|
||||||
|
additional_text_edits: import_edit.map(|edit| vec![edit]),
|
||||||
|
documentation: comp
|
||||||
.documentation
|
.documentation
|
||||||
.map(|documentation| documentation.render_plaintext()),
|
.map(|docstring| docstring.render_plaintext()),
|
||||||
detail: completion.ty.map(|ty| ty.display(&self.db).to_string()),
|
}
|
||||||
})
|
})
|
||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
@ -918,9 +937,15 @@ pub struct Completion {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub kind: Option<CompletionKind>,
|
pub kind: Option<CompletionKind>,
|
||||||
#[wasm_bindgen(getter_with_clone)]
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
|
pub insert_text: Option<String>,
|
||||||
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
|
pub additional_text_edits: Option<Vec<TextEdit>>,
|
||||||
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
pub documentation: Option<String>,
|
pub documentation: Option<String>,
|
||||||
#[wasm_bindgen(getter_with_clone)]
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
pub detail: Option<String>,
|
pub detail: Option<String>,
|
||||||
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
|
pub description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
@ -985,6 +1010,14 @@ impl From<ty_ide::CompletionKind> for CompletionKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct TextEdit {
|
||||||
|
range: Range,
|
||||||
|
#[wasm_bindgen(getter_with_clone)]
|
||||||
|
new_text: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
||||||
pub enum InlayHintKind {
|
pub enum InlayHintKind {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue