diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index e0b07e5db..703725a0d 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -11,8 +11,8 @@ use crate::{ core::{ scope::{ConfigScopeContext, LocalSymbolScopeKind}, symbol::{ - CommentOrDocSymbol, DecoratorSymbol, ExpressionSymbol, Symbol, SymbolHint, - SymbolHintKind, SymbolRef, SymbolSemanticInfo, UnresolvedSymbol, ValueSymbol, + CommentOrDocSymbol, DecoratorSymbol, ExpressionSymbol, SymbolHint, SymbolHintKind, + SymbolRef, SymbolSemanticInfo, UnresolvedSymbol, ValueSymbol, }, }, ty::{Parameter, Type, TypeKind, ANY_TYPE_STR, SCHEMA_MEMBER_FUNCTIONS}, @@ -499,25 +499,38 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for AdvancedResolver<'ctx> { &target.node.names.last().unwrap().id }; let value = self.gs.get_symbols_mut().alloc_value_symbol( - ValueSymbol::new(name.clone(), start_pos, end_pos, None, false), + ValueSymbol::new(name.clone(), start_pos, end_pos.clone(), None, false), self.ctx.get_node_key(&ast_id), self.ctx.current_pkgpath.clone().unwrap(), ); self.gs .get_scopes_mut() .add_def_to_scope(cur_scope, name, value); - if let Some(symbol) = self.gs.get_symbols_mut().values.get_mut(value.get_id()) { - let ty = self - .ctx - .node_ty_map - .borrow() - .get(&self.ctx.get_node_key(ast_id)) - .map(|ty| ty.clone()); - symbol.hint = ty.as_ref().map(|ty| SymbolHint { - kind: SymbolHintKind::TypeHint(ty.ty_hint()), - pos: symbol.get_range().1, - }); - symbol.sema_info = SymbolSemanticInfo { ty, doc: None }; + let symbols = self.gs.get_symbols_mut(); + let ty = match symbols.values.get_mut(value.get_id()) { + Some(symbol) => { + let ty = self + .ctx + .node_ty_map + .borrow() + .get(&self.ctx.get_node_key(ast_id)) + .map(|ty| ty.clone()); + symbol.sema_info = SymbolSemanticInfo { + ty: ty.clone(), + doc: None, + }; + ty + } + None => None, + }; + if let Some(ty) = ty { + symbols.alloc_hint( + SymbolHint { + kind: SymbolHintKind::TypeHint(ty.ty_hint()), + pos: end_pos, + }, + self.ctx.current_pkgpath.clone().unwrap(), + ); } } @@ -1595,12 +1608,9 @@ impl<'ctx> AdvancedResolver<'ctx> { .get(&self.ctx.get_node_key(&&target.id)) .map(|symbol_ref| *symbol_ref) { - if let Some(symbol) = self - .gs - .get_symbols_mut() - .values - .get_mut(identifier_symbol.get_id()) - { + let symbols = self.gs.get_symbols_mut(); + + if let Some(symbol) = symbols.values.get_mut(identifier_symbol.get_id()) { let id = if let Some(last) = target.node.paths.last() { last.id() } else { @@ -1612,13 +1622,20 @@ impl<'ctx> AdvancedResolver<'ctx> { .borrow() .get(&self.ctx.get_node_key(&id)) .map(|ty| ty.clone()); - if with_hint { - symbol.hint = ty.as_ref().map(|ty| SymbolHint { - kind: SymbolHintKind::TypeHint(ty.ty_hint()), - pos: symbol.get_range().1, - }); + + symbol.sema_info = SymbolSemanticInfo { + ty: ty.clone(), + doc: None, + }; + if with_hint & ty.is_some() { + symbols.alloc_hint( + SymbolHint { + kind: SymbolHintKind::TypeHint(ty.unwrap().ty_hint()), + pos: target.get_end_pos(), + }, + self.ctx.current_pkgpath.clone().unwrap(), + ); } - symbol.sema_info = SymbolSemanticInfo { ty, doc: None }; } let cur_scope = *self.ctx.scopes.last().unwrap(); @@ -1664,12 +1681,9 @@ impl<'ctx> AdvancedResolver<'ctx> { .get(&self.ctx.get_node_key(&&identifier.id)) .map(|symbol_ref| *symbol_ref) { - if let Some(symbol) = self - .gs - .get_symbols_mut() - .values - .get_mut(identifier_symbol.get_id()) - { + let symbols = self.gs.get_symbols_mut(); + + if let Some(symbol) = symbols.values.get_mut(identifier_symbol.get_id()) { let id = if identifier.node.names.is_empty() { &identifier.id } else { @@ -1679,15 +1693,22 @@ impl<'ctx> AdvancedResolver<'ctx> { .ctx .node_ty_map .borrow() - .get(&self.ctx.get_node_key(id)) + .get(&self.ctx.get_node_key(&id)) .map(|ty| ty.clone()); - if with_hint { - symbol.hint = ty.as_ref().map(|ty| SymbolHint { - kind: SymbolHintKind::TypeHint(ty.ty_hint()), - pos: symbol.get_range().1, - }); + + symbol.sema_info = SymbolSemanticInfo { + ty: ty.clone(), + doc: None, + }; + if with_hint & ty.is_some() { + symbols.alloc_hint( + SymbolHint { + kind: SymbolHintKind::TypeHint(ty.unwrap().ty_hint()), + pos: identifier.get_end_pos(), + }, + self.ctx.current_pkgpath.clone().unwrap(), + ); } - symbol.sema_info = SymbolSemanticInfo { ty, doc: None }; } if self.ctx.maybe_def && identifier.node.names.len() > 0 { @@ -1842,20 +1863,12 @@ impl<'ctx> AdvancedResolver<'ctx> { ast::Expr::Identifier(id) => id.names.last().unwrap().id.clone(), _ => arg.id.clone(), }; - if let Some(arg_ref) = symbol_data + match symbol_data .symbols_info .node_symbol_map .get(&self.ctx.get_node_key(&id)) { - match arg_ref.get_kind() { - crate::core::symbol::SymbolKind::Expression => { - if let Some(expr) = symbol_data.exprs.get_mut(arg_ref.get_id()) { - expr.hint = Some(SymbolHint { - pos: arg.get_pos(), - kind: SymbolHintKind::VarHint(param.name.clone()), - }); - } - } + Some(arg_ref) => match arg_ref.get_kind() { crate::core::symbol::SymbolKind::Unresolved => { let mut has_hint = false; if let Some(unresolved) = @@ -1870,17 +1883,33 @@ impl<'ctx> AdvancedResolver<'ctx> { } } if has_hint { - if let Some(unresolved) = - symbol_data.unresolved.get_mut(arg_ref.get_id()) - { - unresolved.hint = Some(SymbolHint { + symbol_data.alloc_hint( + SymbolHint { kind: SymbolHintKind::VarHint(param.name.clone()), pos: arg.get_pos(), - }); - } + }, + self.ctx.current_pkgpath.clone().unwrap(), + ); } } - _ => {} + _ => { + symbol_data.alloc_hint( + SymbolHint { + kind: SymbolHintKind::VarHint(param.name.clone()), + pos: arg.get_pos(), + }, + self.ctx.current_pkgpath.clone().unwrap(), + ); + } + }, + None => { + symbol_data.alloc_hint( + SymbolHint { + kind: SymbolHintKind::VarHint(param.name.clone()), + pos: arg.get_pos(), + }, + self.ctx.current_pkgpath.clone().unwrap(), + ); } } } diff --git a/kclvm/sema/src/core/global_state.rs b/kclvm/sema/src/core/global_state.rs index c0bf0a208..66f6b4736 100644 --- a/kclvm/sema/src/core/global_state.rs +++ b/kclvm/sema/src/core/global_state.rs @@ -620,6 +620,20 @@ impl GlobalState { ); } + for (_, hints) in &self.symbols.hints { + for hint in hints { + if file_sema_map_cache.contains_key(&hint.pos.filename) { + continue; + } + let filename = &hint.pos.filename; + if !file_sema_map.contains_key(filename) { + file_sema_map.insert(filename.clone(), FileSemanticInfo::new(filename.clone())); + } + let file_sema_info = file_sema_map.get_mut(filename).unwrap(); + file_sema_info.hints.push(hint.clone()); + } + } + // remove dummy file file_sema_map.remove(""); diff --git a/kclvm/sema/src/core/semantic_information.rs b/kclvm/sema/src/core/semantic_information.rs index 1dc3b03e7..a1720f2da 100644 --- a/kclvm/sema/src/core/semantic_information.rs +++ b/kclvm/sema/src/core/semantic_information.rs @@ -2,7 +2,10 @@ use indexmap::IndexMap; use kclvm_ast::ast::AstIndex; use std::sync::Arc; -use super::{scope::ScopeRef, symbol::SymbolRef}; +use super::{ + scope::ScopeRef, + symbol::{SymbolHint, SymbolRef}, +}; use crate::ty::Type; #[allow(unused)] #[derive(Debug, Default, Clone)] @@ -25,6 +28,7 @@ pub struct FileSemanticInfo { pub(crate) scopes: Vec, pub(crate) symbol_locs: IndexMap, pub(crate) local_scope_locs: IndexMap, + pub(crate) hints: Vec, } impl FileSemanticInfo { @@ -35,6 +39,7 @@ impl FileSemanticInfo { scopes: vec![], symbol_locs: IndexMap::default(), local_scope_locs: IndexMap::default(), + hints: vec![], } } @@ -57,6 +62,10 @@ impl FileSemanticInfo { pub fn get_symbols(&self) -> &Vec { &self.symbols } + + pub fn get_hints(&self) -> &Vec { + &self.hints + } } #[derive(Debug, Eq, PartialEq, Clone)] diff --git a/kclvm/sema/src/core/symbol.rs b/kclvm/sema/src/core/symbol.rs index fe056aa56..efad6eacd 100644 --- a/kclvm/sema/src/core/symbol.rs +++ b/kclvm/sema/src/core/symbol.rs @@ -1,4 +1,7 @@ -use std::{collections::HashSet, sync::Arc}; +use std::{ + collections::{HashMap, HashSet}, + sync::Arc, +}; use generational_arena::Arena; use indexmap::{IndexMap, IndexSet}; @@ -44,8 +47,6 @@ pub trait Symbol { module_info: Option<&ModuleInfo>, ) -> Vec; - fn get_hint(&self) -> Option<&Self::SymbolHint>; - fn simple_dump(&self) -> String; fn full_dump(&self, data: &Self::SymbolData) -> Option; @@ -75,6 +76,7 @@ pub struct SymbolData { pub(crate) comments: Arena, pub(crate) decorators: Arena, pub(crate) functions: Arena, + pub(crate) hints: HashMap>, pub(crate) symbols_info: SymbolDB, } @@ -866,6 +868,15 @@ impl SymbolData { symbol_ref } + pub fn alloc_hint(&mut self, hint: SymbolHint, pkg_name: String) { + match self.hints.get_mut(&pkg_name) { + Some(hints) => hints.push(hint), + None => { + self.hints.insert(pkg_name, vec![hint]); + } + } + } + #[inline] pub fn get_node_symbol_map(&self) -> &IndexMap { &self.symbols_info.node_symbol_map @@ -893,6 +904,7 @@ impl SymbolData { if let Some(symbols) = self.symbols_info.pkg_symbol_map.get(invalidate_pkg) { to_remove.extend(symbols.iter().cloned()); } + self.hints.remove(invalidate_pkg); } for symbol in to_remove { self.remove_symbol(&symbol); @@ -1150,10 +1162,6 @@ impl Symbol for SchemaSymbol { self.get_attribute(name, data, module_info).is_some() } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"SchemaSymbol\",\n"); @@ -1297,7 +1305,6 @@ pub struct ValueSymbol { pub(crate) owner: Option, pub(crate) sema_info: SymbolSemanticInfo, pub(crate) r#ref: HashSet, - pub(crate) hint: Option, pub(crate) is_global: bool, } @@ -1365,10 +1372,6 @@ impl Symbol for ValueSymbol { self.get_attribute(name, data, module_info).is_some() } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - self.hint.as_ref() - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"ValueSymbol\",\n"); @@ -1425,7 +1428,6 @@ impl ValueSymbol { owner, sema_info: SymbolSemanticInfo::default(), is_global, - hint: None, r#ref: HashSet::default(), } } @@ -1512,10 +1514,6 @@ impl Symbol for AttributeSymbol { self.get_attribute(name, data, module_info).is_some() } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"AttributeSymbol\",\n"); @@ -1654,10 +1652,6 @@ impl Symbol for PackageSymbol { self.members.contains_key(name) } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"PackageSymbol\",\n"); @@ -1790,10 +1784,6 @@ impl Symbol for TypeAliasSymbol { self.get_attribute(name, data, module_info).is_some() } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"TypeAliasSymbol\",\n"); @@ -1916,10 +1906,6 @@ impl Symbol for RuleSymbol { false } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"RuleSymbol\",\n"); @@ -1997,7 +1983,6 @@ pub struct UnresolvedSymbol { pub(crate) end: Position, pub(crate) owner: Option, pub(crate) sema_info: SymbolSemanticInfo, - pub(crate) hint: Option, pub(crate) is_type: bool, pub(crate) r#ref: HashSet, } @@ -2073,10 +2058,6 @@ impl Symbol for UnresolvedSymbol { &self.sema_info } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - self.hint.as_ref() - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"UnresolvedSymbol\",\n"); @@ -2129,7 +2110,6 @@ impl UnresolvedSymbol { end, sema_info: SymbolSemanticInfo::default(), owner, - hint: None, is_type, r#ref: HashSet::default(), } @@ -2165,7 +2145,6 @@ pub struct ExpressionSymbol { pub(crate) name: String, pub(crate) sema_info: SymbolSemanticInfo, - pub(crate) hint: Option, pub(crate) r#ref: HashSet, } @@ -2236,10 +2215,6 @@ impl Symbol for ExpressionSymbol { &self.sema_info } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - self.hint.as_ref() - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"ExpressionSymbol\",\n"); @@ -2284,7 +2259,6 @@ impl ExpressionSymbol { end, sema_info: SymbolSemanticInfo::default(), owner, - hint: None, r#ref: HashSet::default(), } } @@ -2359,10 +2333,6 @@ impl Symbol for CommentOrDocSymbol { vec![] } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"CommentSymbol\",\n"); @@ -2478,10 +2448,6 @@ impl Symbol for DecoratorSymbol { vec![] } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"CommentSymbol\",\n"); @@ -2608,10 +2574,6 @@ impl Symbol for FunctionSymbol { &self.sema_info } - fn get_hint(&self) -> Option<&Self::SymbolHint> { - None - } - fn simple_dump(&self) -> String { let mut output = "{\n".to_string(); output.push_str("\"kind\": \"FunctionSymbol\",\n"); diff --git a/kclvm/tools/src/LSP/src/inlay_hints.rs b/kclvm/tools/src/LSP/src/inlay_hints.rs index 9dce2a445..f3b8fe7ac 100644 --- a/kclvm/tools/src/LSP/src/inlay_hints.rs +++ b/kclvm/tools/src/LSP/src/inlay_hints.rs @@ -1,7 +1,9 @@ use indexmap::IndexSet; use kclvm_sema::core::global_state::GlobalState; use kclvm_sema::core::symbol::{SymbolHint, SymbolHintKind}; -use lsp_types::{InlayHint, InlayHintLabelPart, Position as LspPosition}; +use lsp_types::{ + InlayHint, InlayHintKind, InlayHintLabelPart, Position as LspPosition, Range, TextEdit, +}; use std::hash::Hash; use crate::to_lsp::lsp_pos; @@ -14,6 +16,11 @@ struct KCLInlayHint { /// An inlay hint label part allows for interactive and composite labels /// of inlay hints. pub part: InlayHintLabelPart, + + pub kind: InlayHintKind, + + /// Optional text edits that are performed when accepting(e.g. double-click in VSCode) this inlay hint. + pub text_edits: Option>, } impl Hash for KCLInlayHint { @@ -36,13 +43,8 @@ pub fn inlay_hints(file: &str, gs: &GlobalState) -> Option> { let mut inlay_hints: IndexSet = Default::default(); let sema_db = gs.get_sema_db(); if let Some(file_sema) = sema_db.get_file_sema(file) { - let symbols = file_sema.get_symbols(); - for symbol_ref in symbols { - if let Some(symbol) = gs.get_symbols().get_symbol(*symbol_ref) { - if let Some(hint) = symbol.get_hint() { - inlay_hints.insert(generate_inlay_hint(hint)); - } - } + for hint in file_sema.get_hints() { + inlay_hints.insert(generate_inlay_hint(hint)); } } Some( @@ -55,17 +57,32 @@ pub fn inlay_hints(file: &str, gs: &GlobalState) -> Option> { #[inline] fn generate_inlay_hint(hint: &SymbolHint) -> KCLInlayHint { - let (part, position) = get_hint_label(hint); - KCLInlayHint { position, part } + let (part, position, kind) = get_hint_label(hint); + let text_edits = match hint.kind { + SymbolHintKind::TypeHint(_) => Some(vec![TextEdit { + range: Range { + start: position.clone(), + end: position.clone(), + }, + new_text: part.value.clone(), + }]), + SymbolHintKind::VarHint(_) => None, + }; + KCLInlayHint { + position, + part, + kind, + text_edits, + } } #[inline] fn into_lsp_inlay_hint(hint: &KCLInlayHint) -> InlayHint { InlayHint { - position: hint.position, + position: hint.position.clone(), label: lsp_types::InlayHintLabel::LabelParts(vec![hint.part.clone()]), - kind: None, - text_edits: None, + kind: Some(hint.kind), + text_edits: hint.text_edits.clone(), tooltip: None, padding_left: None, padding_right: None, @@ -73,7 +90,7 @@ fn into_lsp_inlay_hint(hint: &KCLInlayHint) -> InlayHint { } } -fn get_hint_label(hint: &SymbolHint) -> (InlayHintLabelPart, LspPosition) { +fn get_hint_label(hint: &SymbolHint) -> (InlayHintLabelPart, LspPosition, InlayHintKind) { match &hint.kind { SymbolHintKind::TypeHint(ty) => ( InlayHintLabelPart { @@ -81,6 +98,7 @@ fn get_hint_label(hint: &SymbolHint) -> (InlayHintLabelPart, LspPosition) { ..Default::default() }, lsp_pos(&hint.pos), + InlayHintKind::TYPE, ), SymbolHintKind::VarHint(var) => ( InlayHintLabelPart { @@ -88,6 +106,7 @@ fn get_hint_label(hint: &SymbolHint) -> (InlayHintLabelPart, LspPosition) { ..Default::default() }, lsp_pos(&hint.pos), + InlayHintKind::PARAMETER, ), } } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap index 7ae4829d5..2d8d04cdb 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__assign_stmt_type_hint.snap @@ -19,8 +19,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 0, + character: 1, + }, + end: Position { + line: 0, + character: 1, + }, + }, + new_text: ": int", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -41,8 +59,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 1, + character: 1, + }, + end: Position { + line: 1, + character: 1, + }, + }, + new_text: ": str", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -63,8 +99,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 2, + character: 1, + }, + end: Position { + line: 2, + character: 1, + }, + }, + new_text: ": str", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -85,8 +139,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 3, + character: 1, + }, + end: Position { + line: 3, + character: 1, + }, + }, + new_text: ": (int) -> int", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -107,8 +179,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 10, + character: 1, + }, + end: Position { + line: 10, + character: 1, + }, + }, + new_text: ": Name", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -129,8 +219,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 13, + character: 2, + }, + end: Position { + line: 13, + character: 2, + }, + }, + new_text: ": Name", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -151,8 +259,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 14, + character: 4, + }, + end: Position { + line: 14, + character: 4, + }, + }, + new_text: ": any", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -173,8 +299,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 16, + character: 1, + }, + end: Position { + line: 16, + character: 1, + }, + }, + new_text: ": str", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -195,8 +339,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 17, + character: 2, + }, + end: Position { + line: 17, + character: 2, + }, + }, + new_text: ": [int | str]", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -217,8 +379,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 18, + character: 2, + }, + end: Position { + line: 18, + character: 2, + }, + }, + new_text: ": {str:str}", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -239,8 +419,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 21, + character: 3, + }, + end: Position { + line: 21, + character: 3, + }, + }, + new_text: ": number_multiplier(1Ki)", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -261,8 +459,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 23, + character: 4, + }, + end: Position { + line: 23, + character: 4, + }, + }, + new_text: ": (any, any, any) -> any", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__function_call_arg_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__function_call_arg_hint.snap index 770ab5697..43be80669 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__function_call_arg_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__function_call_arg_hint.snap @@ -19,8 +19,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 0, + character: 1, + }, + end: Position { + line: 0, + character: 1, + }, + }, + new_text: ": int", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -41,8 +59,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 2, + character: 4, + }, + end: Position { + line: 2, + character: 4, + }, + }, + new_text: ": (any, any, any) -> any", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -63,8 +99,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 6, + character: 1, + }, + end: Position { + line: 6, + character: 1, + }, + }, + new_text: ": any", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -85,7 +139,9 @@ Some( }, ], ), - kind: None, + kind: Some( + Parameter, + ), text_edits: None, tooltip: None, padding_left: None, @@ -107,7 +163,9 @@ Some( }, ], ), - kind: None, + kind: Some( + Parameter, + ), text_edits: None, tooltip: None, padding_left: None, @@ -129,8 +187,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 8, + character: 1, + }, + end: Position { + line: 8, + character: 1, + }, + }, + new_text: ": int", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -151,8 +227,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 9, + character: 2, + }, + end: Position { + line: 9, + character: 2, + }, + }, + new_text: ": any", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -173,7 +267,345 @@ Some( }, ], ), - kind: None, + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 11, + character: 1, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: ": int", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 11, + character: 1, + }, + end: Position { + line: 11, + character: 1, + }, + }, + new_text: ": int", + }, + ], + ), + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 11, + character: 12, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "sub: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 11, + character: 19, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "start: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 11, + character: 22, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "end: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 12, + character: 1, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: ": int", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 12, + character: 1, + }, + end: Position { + line: 12, + character: 1, + }, + }, + new_text: ": int", + }, + ], + ), + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 12, + character: 12, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "sub: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 12, + character: 19, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "start: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 12, + character: 22, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "end: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 13, + character: 1, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: ": int", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 13, + character: 1, + }, + end: Position { + line: 13, + character: 1, + }, + }, + new_text: ": int", + }, + ], + ), + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 13, + character: 12, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "sub: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 13, + character: 19, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "start: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), + text_edits: None, + tooltip: None, + padding_left: None, + padding_right: None, + data: None, + }, + InlayHint { + position: Position { + line: 13, + character: 22, + }, + label: LabelParts( + [ + InlayHintLabelPart { + value: "end: ", + tooltip: None, + location: None, + command: None, + }, + ], + ), + kind: Some( + Parameter, + ), text_edits: None, tooltip: None, padding_left: None, diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__schema_arg_hint.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__schema_arg_hint.snap index 496236911..1a655ca67 100644 --- a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__schema_arg_hint.snap +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__inlay_hints__tests__schema_arg_hint.snap @@ -1,6 +1,5 @@ --- source: tools/src/LSP/src/inlay_hints.rs -assertion_line: 122 expression: "format!(\"{:#?}\", res)" --- Some( @@ -20,8 +19,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 1, + character: 5, + }, + end: Position { + line: 1, + character: 5, + }, + }, + new_text: ": int", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -42,8 +59,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 2, + character: 5, + }, + end: Position { + line: 2, + character: 5, + }, + }, + new_text: ": str", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -64,8 +99,26 @@ Some( }, ], ), - kind: None, - text_edits: None, + kind: Some( + Type, + ), + text_edits: Some( + [ + TextEdit { + range: Range { + start: Position { + line: 4, + character: 1, + }, + end: Position { + line: 4, + character: 1, + }, + }, + new_text: ": Person", + }, + ], + ), tooltip: None, padding_left: None, padding_right: None, @@ -86,7 +139,9 @@ Some( }, ], ), - kind: None, + kind: Some( + Parameter, + ), text_edits: None, tooltip: None, padding_left: None, @@ -108,7 +163,9 @@ Some( }, ], ), - kind: None, + kind: Some( + Parameter, + ), text_edits: None, tooltip: None, padding_left: None, diff --git a/kclvm/tools/src/LSP/src/test_data/inlay_hints/function_call/function_call.k b/kclvm/tools/src/LSP/src/test_data/inlay_hints/function_call/function_call.k index d950b77f1..d64294ac8 100644 --- a/kclvm/tools/src/LSP/src/test_data/inlay_hints/function_call/function_call.k +++ b/kclvm/tools/src/LSP/src/test_data/inlay_hints/function_call/function_call.k @@ -7,4 +7,8 @@ func = lambda x, y, z{ k = func(a, 1, z = 2) x = 1 -k1 = func(x, 1, z = 2) \ No newline at end of file +k1 = func(x, 1, z = 2) + +b = "".find("abc", 0, -1) +c = "".find("abc", 0, 1) +d = "".find("abc", 0, 1 + 1) \ No newline at end of file