Use ty's completions in playground (#18425)

This commit is contained in:
Micha Reiser 2025-06-03 10:11:39 +02:00 committed by GitHub
parent d1cb8e2142
commit 67d94d9ec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 82 additions and 7 deletions

View file

@ -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,