[ty] Add completion kind to playground (#19251)

This commit is contained in:
Micha Reiser 2025-07-10 09:41:59 +02:00 committed by GitHub
parent 801f69a7b4
commit 5fb2fb916b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 124 additions and 1 deletions

View file

@ -309,6 +309,7 @@ impl Workspace {
Ok(completions
.into_iter()
.map(|completion| Completion {
kind: completion.kind(&self.db).map(CompletionKind::from),
name: completion.name.into(),
})
.collect())
@ -666,6 +667,69 @@ pub struct Hover {
pub struct Completion {
#[wasm_bindgen(getter_with_clone)]
pub name: String,
pub kind: Option<CompletionKind>,
}
#[wasm_bindgen]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CompletionKind {
Text,
Method,
Function,
Constructor,
Field,
Variable,
Class,
Interface,
Module,
Property,
Unit,
Value,
Enum,
Keyword,
Snippet,
Color,
File,
Reference,
Folder,
EnumMember,
Constant,
Struct,
Event,
Operator,
TypeParameter,
}
impl From<ty_python_semantic::CompletionKind> for CompletionKind {
fn from(value: ty_python_semantic::CompletionKind) -> Self {
match value {
ty_python_semantic::CompletionKind::Text => Self::Text,
ty_python_semantic::CompletionKind::Method => Self::Method,
ty_python_semantic::CompletionKind::Function => Self::Function,
ty_python_semantic::CompletionKind::Constructor => Self::Constructor,
ty_python_semantic::CompletionKind::Field => Self::Field,
ty_python_semantic::CompletionKind::Variable => Self::Variable,
ty_python_semantic::CompletionKind::Class => Self::Class,
ty_python_semantic::CompletionKind::Interface => Self::Interface,
ty_python_semantic::CompletionKind::Module => Self::Module,
ty_python_semantic::CompletionKind::Property => Self::Property,
ty_python_semantic::CompletionKind::Unit => Self::Unit,
ty_python_semantic::CompletionKind::Value => Self::Value,
ty_python_semantic::CompletionKind::Enum => Self::Enum,
ty_python_semantic::CompletionKind::Keyword => Self::Keyword,
ty_python_semantic::CompletionKind::Snippet => Self::Snippet,
ty_python_semantic::CompletionKind::Color => Self::Color,
ty_python_semantic::CompletionKind::File => Self::File,
ty_python_semantic::CompletionKind::Reference => Self::Reference,
ty_python_semantic::CompletionKind::Folder => Self::Folder,
ty_python_semantic::CompletionKind::EnumMember => Self::EnumMember,
ty_python_semantic::CompletionKind::Constant => Self::Constant,
ty_python_semantic::CompletionKind::Struct => Self::Struct,
ty_python_semantic::CompletionKind::Event => Self::Event,
ty_python_semantic::CompletionKind::Operator => Self::Operator,
ty_python_semantic::CompletionKind::TypeParameter => Self::TypeParameter,
}
}
}
#[wasm_bindgen]