mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Use ty's completions in playground (#18425)
This commit is contained in:
parent
d1cb8e2142
commit
67d94d9ec8
3 changed files with 82 additions and 7 deletions
|
@ -293,6 +293,27 @@ impl Workspace {
|
|||
}))
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn completions(
|
||||
&self,
|
||||
file_id: &FileHandle,
|
||||
position: Position,
|
||||
) -> Result<Vec<Completion>, Error> {
|
||||
let source = source_text(&self.db, file_id.file);
|
||||
let index = line_index(&self.db, file_id.file);
|
||||
|
||||
let offset = position.to_text_size(&source, &index, self.position_encoding)?;
|
||||
|
||||
let completions = ty_ide::completion(&self.db, file_id.file, offset);
|
||||
|
||||
Ok(completions
|
||||
.into_iter()
|
||||
.map(|completion| Completion {
|
||||
label: completion.label,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_name = "inlayHints")]
|
||||
pub fn inlay_hints(&self, file_id: &FileHandle, range: Range) -> Result<Vec<InlayHint>, Error> {
|
||||
let index = line_index(&self.db, file_id.file);
|
||||
|
@ -586,6 +607,7 @@ pub struct LocationLink {
|
|||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Hover {
|
||||
#[wasm_bindgen(getter_with_clone)]
|
||||
pub markdown: String,
|
||||
|
@ -594,6 +616,14 @@ pub struct Hover {
|
|||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Completion {
|
||||
#[wasm_bindgen(getter_with_clone)]
|
||||
pub label: String,
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct InlayHint {
|
||||
#[wasm_bindgen(getter_with_clone)]
|
||||
pub markdown: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue