Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: lsp hover keyword highlight #1331

Merged
merged 11 commits into from
May 22, 2024
15 changes: 4 additions & 11 deletions kclvm/sema/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl SchemaType {
}
}

pub fn schema_ty_signature_str(&self) -> String {
pub fn schema_ty_signature_str(&self) -> (String, String) {
let base: String = if let Some(base) = &self.base {
format!("({})", base.name)
} else {
Expand All @@ -312,17 +312,10 @@ impl SchemaType {
.join(", ")
)
};
let params_str = if !params.is_empty() && !base.is_empty() {
format!("\\{}{}", params, base)
} else if !params.is_empty() {
format!("{}", params)
} else if !base.is_empty() {
format!("{}", base)
} else {
"".to_string()
};

format!("{}\n\nschema {}{}", self.pkgpath, self.name, params_str)
let rest_sign = format!("schema {}{}{}:", self.name, params, base);

(self.pkgpath.clone(), rest_sign)
}

pub fn schema_ty_signature_no_pkg(&self) -> String {
Expand Down
8 changes: 5 additions & 3 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ fn schema_ty_to_value_complete_item(schema_ty: &SchemaType) -> KCLCompletionItem
);
let detail = {
let mut details = vec![];
details.push(schema_ty.schema_ty_signature_str());
let (pkgpath, rest_sign) = schema_ty.schema_ty_signature_str();
Peefy marked this conversation as resolved.
Show resolved Hide resolved
details.push(format!("{}\n\n{}", pkgpath, rest_sign));
details.push("Attributes:".to_string());
for (name, attr) in &schema_ty.attrs {
details.push(format!(
Expand Down Expand Up @@ -543,7 +544,8 @@ fn schema_ty_to_value_complete_item(schema_ty: &SchemaType) -> KCLCompletionItem
fn schema_ty_to_type_complete_item(schema_ty: &SchemaType) -> KCLCompletionItem {
let detail = {
let mut details = vec![];
details.push(schema_ty.schema_ty_signature_str());
let (pkgpath, rest_sign) = schema_ty.schema_ty_signature_str();
details.push(format!("{}\n\n{}", pkgpath, rest_sign));
details.push("Attributes:".to_string());
for (name, attr) in &schema_ty.attrs {
details.push(format!(
Expand Down Expand Up @@ -1259,7 +1261,7 @@ mod tests {
label: "Person(b){}".to_string(),
kind: Some(CompletionItemKind::CLASS),
detail: Some(
"__main__\n\nschema Person\\[b: int](Base)\nAttributes:\nc: int"
"__main__\n\nschema Person[b: int](Base):\nAttributes:\nc: int"
.to_string()
),
documentation: Some(lsp_types::Documentation::String("".to_string())),
Expand Down
Loading
Loading