From 0f3ee00cc61940d78139c5c686b721bb0aaec500 Mon Sep 17 00:00:00 2001 From: he1pa <18012015693@163.com> Date: Tue, 13 Aug 2024 14:27:43 +0800 Subject: [PATCH] fix: fix config entry key def Signed-off-by: he1pa <18012015693@163.com> --- kclvm/sema/src/advanced_resolver/node.rs | 12 ++++---- kclvm/tools/src/LSP/src/goto_def.rs | 28 +++++++++++++++++++ ...def__tests__goto_attr_in_schema_def_5.snap | 5 ++++ ...def__tests__goto_attr_in_schema_def_6.snap | 5 ++++ ...def__tests__goto_attr_in_schema_def_7.snap | 5 ++++ ...def__tests__goto_attr_in_schema_def_8.snap | 5 ++++ .../goto_attr_in_schema_def.k | 15 ++++++++++ 7 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_5.snap create mode 100644 kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_6.snap create mode 100644 kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_7.snap create mode 100644 kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_8.snap diff --git a/kclvm/sema/src/advanced_resolver/node.rs b/kclvm/sema/src/advanced_resolver/node.rs index 919c1943b..984564b02 100644 --- a/kclvm/sema/src/advanced_resolver/node.rs +++ b/kclvm/sema/src/advanced_resolver/node.rs @@ -1127,11 +1127,13 @@ impl<'ctx> AdvancedResolver<'ctx> { if let crate::core::symbol::SymbolKind::Attribute = symbol_ref.get_kind() { - self.gs.get_scopes_mut().add_def_to_scope( - cur_scope, - name, - first_unresolved_ref, - ); + if maybe_def { + self.gs.get_scopes_mut().add_def_to_scope( + cur_scope, + name, + first_unresolved_ref, + ); + } } } _ => {} diff --git a/kclvm/tools/src/LSP/src/goto_def.rs b/kclvm/tools/src/LSP/src/goto_def.rs index 1a22e44b8..fcdc24920 100644 --- a/kclvm/tools/src/LSP/src/goto_def.rs +++ b/kclvm/tools/src/LSP/src/goto_def.rs @@ -497,4 +497,32 @@ mod tests { 17, 12 ); + + goto_def_test_snapshot!( + goto_attr_in_schema_def_5, + "src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k", + 32, + 15 + ); + + goto_def_test_snapshot!( + goto_attr_in_schema_def_6, + "src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k", + 33, + 15 + ); + + goto_def_test_snapshot!( + goto_attr_in_schema_def_7, + "src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k", + 32, + 10 + ); + + goto_def_test_snapshot!( + goto_attr_in_schema_def_8, + "src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k", + 33, + 10 + ); } diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_5.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_5.snap new file mode 100644 index 000000000..39d8a63b3 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_5.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/LSP/src/goto_def.rs +expression: "format!(\"{:?}\", { fmt_resp(& res) })" +--- +"path: \"src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k\", range: Range { start: Position { line: 26, character: 4 }, end: Position { line: 26, character: 7 } }" diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_6.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_6.snap new file mode 100644 index 000000000..de9991b65 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_6.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/LSP/src/goto_def.rs +expression: "format!(\"{:?}\", { fmt_resp(& res) })" +--- +"path: \"src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k\", range: Range { start: Position { line: 28, character: 4 }, end: Position { line: 28, character: 7 } }" diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_7.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_7.snap new file mode 100644 index 000000000..d21ffc774 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_7.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/LSP/src/goto_def.rs +expression: "format!(\"{:?}\", { fmt_resp(& res) })" +--- +"path: \"src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k\", range: Range { start: Position { line: 21, character: 4 }, end: Position { line: 21, character: 7 } }" diff --git a/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_8.snap b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_8.snap new file mode 100644 index 000000000..1fb53c9fb --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_8.snap @@ -0,0 +1,5 @@ +--- +source: tools/src/LSP/src/goto_def.rs +expression: "format!(\"{:?}\", { fmt_resp(& res) })" +--- +"path: \"src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k\", range: Range { start: Position { line: 22, character: 4 }, end: Position { line: 22, character: 7 } }" diff --git a/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k b/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k index f2d8dafac..7604626e6 100644 --- a/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k +++ b/kclvm/tools/src/LSP/src/test_data/goto_def_test/goto_attr_in_schema_def/goto_attr_in_schema_def.k @@ -17,3 +17,18 @@ schema Nested: if a: aa: "aa" } + +schema Baz: + foo: [str] + bar: Name + +schema RoleBinding: + + foo?: [str] + + bar: Name + + baz: Baz = Baz { + foo: foo + bar: bar + }