Skip to content

Commit

Permalink
feat: enhance lsp completion detail (kcl-lang#805)
Browse files Browse the repository at this point in the history
* feat: enhance lsp completion detail. Add completion kind(icon in vscode), detail and doc in completion item. Enhance completion label for function

Signed-off-by: He1pa <[email protected]>

* doc: fix doc typo

Signed-off-by: He1pa <[email protected]>

---------

Signed-off-by: He1pa <[email protected]>
  • Loading branch information
He1pa authored Oct 26, 2023
1 parent 4eac50d commit 1d9eccb
Show file tree
Hide file tree
Showing 3 changed files with 356 additions and 215 deletions.
28 changes: 28 additions & 0 deletions kclvm/sema/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ impl Type {
TypeKind::Named(name) => name.to_string(),
}
}

pub fn ty_doc(&self) -> Option<String> {
match &self.kind {
TypeKind::Schema(schema) => Some(schema.doc.clone()),
TypeKind::Function(func) => Some(func.doc.clone()),
_ => None,
}
}

pub fn into_function_ty(&self) -> FunctionType {
match &self.kind {
TypeKind::Function(func) => func.clone(),
_ => panic!("Not a function type"),
}
}
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -399,6 +414,19 @@ impl FunctionType {
self.return_ty.ty_str()
)
}

pub fn func_signature_str(&self, name: &String) -> String {
format!(
"function {}({}) -> {}",
name,
self.params
.iter()
.map(|param| format!("{}: {}", param.name, param.ty.ty_str()))
.collect::<Vec<String>>()
.join(", "),
self.return_ty.ty_str()
)
}
}

impl FunctionType {
Expand Down
Loading

0 comments on commit 1d9eccb

Please sign in to comment.