Skip to content

Commit

Permalink
update semantic tokens with function type
Browse files Browse the repository at this point in the history
Signed-off-by: shruti2522 <[email protected]>
  • Loading branch information
shruti2522 committed Jun 3, 2024
1 parent 91408f2 commit 6c978a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
30 changes: 7 additions & 23 deletions kclvm/sema/src/namer/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::core::package::ImportInfo;
use crate::core::symbol::{
AttributeSymbol, FunctionSymbol, RuleSymbol, SchemaSymbol, SymbolKind, SymbolRef,
TypeAliasSymbol, ValueSymbol,
AttributeSymbol, RuleSymbol, SchemaSymbol, SymbolKind, SymbolRef, TypeAliasSymbol, ValueSymbol,
};

use super::Namer;
Expand Down Expand Up @@ -115,18 +114,10 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Namer<'ctx> {
.value_fully_qualified_name_set
.contains(&value_fully_qualified_name)
{
let value_ref = if let ast::Expr::Lambda(_lambda_expr) = &assign_stmt.value.node
{
self.gs.get_symbols_mut().alloc_function_symbol(
FunctionSymbol::new(value_name, start_pos, end_pos, Some(owner), true),
self.ctx.get_node_key(&target.id),
)
} else {
self.gs.get_symbols_mut().alloc_value_symbol(
ValueSymbol::new(value_name, start_pos, end_pos, Some(owner), true),
self.ctx.get_node_key(&target.id),
)
};
let value_ref = self.gs.get_symbols_mut().alloc_value_symbol(
ValueSymbol::new(value_name, start_pos, end_pos, Some(owner), true),
self.ctx.get_node_key(&target.id),
);
self.ctx
.value_fully_qualified_name_set
.insert(value_fully_qualified_name);
Expand Down Expand Up @@ -264,15 +255,8 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Namer<'ctx> {
None
}

fn walk_call_expr(&mut self, call_expr: &'ctx ast::CallExpr) -> Self::Result {
let (start_pos, end_pos): Range = call_expr.func.get_span_pos();
let owner = self.ctx.owner_symbols.last().unwrap().clone();
let func_name = call_expr.func.node.get_expr_name();
let func_ref = self.gs.get_symbols_mut().alloc_function_symbol(
FunctionSymbol::new(func_name, start_pos, end_pos, Some(owner), true),
self.ctx.get_node_key(&call_expr.func.id),
);
Some(vec![func_ref])
fn walk_call_expr(&mut self, _call_expr: &'ctx ast::CallExpr) -> Self::Result {
None
}

fn walk_subscript(&mut self, _subscript: &'ctx ast::Subscript) -> Self::Result {
Expand Down
13 changes: 12 additions & 1 deletion kclvm/tools/src/LSP/src/semantic_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use kclvm_sema::core::{
global_state::GlobalState,
symbol::{KCLSymbol, SymbolKind},
};
use kclvm_sema::ty::TypeKind;
use lsp_types::{SemanticToken, SemanticTokenType, SemanticTokens, SemanticTokensResult};

pub const LEGEND_TYPE: &[SemanticTokenType] = &[
Expand Down Expand Up @@ -63,7 +64,17 @@ pub(crate) fn get_kind(ty: SymbolKind, symbol: &KCLSymbol, gs: &GlobalState) ->
SymbolKind::Attribute => Some(type_index(SemanticTokenType::PROPERTY)),
SymbolKind::Package => Some(type_index(SemanticTokenType::NAMESPACE)),
SymbolKind::TypeAlias => Some(type_index(SemanticTokenType::TYPE)),
SymbolKind::Value => Some(type_index(SemanticTokenType::VARIABLE)),
SymbolKind::Value => {
// Check if the value is a lambda or a function type
if let Some(ty) = &symbol.get_sema_info().ty {
match ty.kind {
TypeKind::Function(_) => Some(type_index(SemanticTokenType::FUNCTION)),
_ => Some(type_index(SemanticTokenType::VARIABLE)),
}
} else {
Some(type_index(SemanticTokenType::VARIABLE))
}
}
SymbolKind::Function => Some(type_index(SemanticTokenType::FUNCTION)),
SymbolKind::Rule => Some(type_index(SemanticTokenType::MACRO)),
SymbolKind::Unresolved => match &symbol.get_definition() {
Expand Down

0 comments on commit 6c978a3

Please sign in to comment.