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.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_5.snap.new new file mode 100644 index 000000000..20e73428a --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_5.snap.new @@ -0,0 +1,6 @@ +--- +source: tools/src/LSP/src/goto_def.rs +assertion_line: 501 +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.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_6.snap.new new file mode 100644 index 000000000..1dc322ef0 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_6.snap.new @@ -0,0 +1,6 @@ +--- +source: tools/src/LSP/src/goto_def.rs +assertion_line: 508 +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.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_7.snap.new new file mode 100644 index 000000000..5e4c5ca3b --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_7.snap.new @@ -0,0 +1,6 @@ +--- +source: tools/src/LSP/src/goto_def.rs +assertion_line: 515 +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.new b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_8.snap.new new file mode 100644 index 000000000..37c679977 --- /dev/null +++ b/kclvm/tools/src/LSP/src/snapshots/kcl_language_server__goto_def__tests__goto_attr_in_schema_def_8.snap.new @@ -0,0 +1,6 @@ +--- +source: tools/src/LSP/src/goto_def.rs +assertion_line: 522 +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 + }