Skip to content

Commit

Permalink
fix find refs from schema attr def
Browse files Browse the repository at this point in the history
Signed-off-by: xiarui.xr <[email protected]>
  • Loading branch information
amyXia1994 committed Oct 13, 2023
1 parent 63f937c commit 4b8502b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
14 changes: 7 additions & 7 deletions kclvm/tools/src/LSP/src/find_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ mod tests {
},
};
let expect = vec![
// Location {
// uri: url.clone(),
// range: Range {
// start: Position::new(5, 4),
// end: Position::new(5, 8),
// },
// },
Location {
uri: url.clone(),
range: Range {
start: Position::new(5, 4),
end: Position::new(5, 8),
},
},
Location {
uri: url.clone(),
range: Range {
Expand Down
12 changes: 4 additions & 8 deletions kclvm/tools/src/LSP/src/goto_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(crate) fn find_def(
),
);
let id = pre_process_identifier(id_node, kcl_pos);
match parent {
match parent {
Some(schema_expr) => {
if let Expr::Schema(schema_expr) = schema_expr.node {
let schema_def =
Expand All @@ -171,7 +171,7 @@ pub(crate) fn find_def(
}
None => {
if let Some(inner_most_scope) = prog_scope.inner_most_scope(kcl_pos) {
return resolve_var(
return resolve_var(
&id.names,
&inner_most_scope,
&prog_scope.scope_map,
Expand Down Expand Up @@ -220,7 +220,7 @@ pub(crate) fn find_def(
},
_ => {}
}
}
}
None
}

Expand Down Expand Up @@ -1018,10 +1018,6 @@ mod tests {
compare_goto_res(res, (&file, 43, 4, 43, 9));
}

// this test case if to ensure the go-to-def result of schema attribute def
// schema Person {
// target: str
// }
#[test]
#[bench_test]
fn schema_attribute_def_goto_def() {
Expand All @@ -1037,6 +1033,6 @@ mod tests {
};

let res = goto_definition(&program, &pos, &prog_scope);
compare_goto_res(res, (&file, 19, 4, 19, 8));
compare_goto_res(res, (&file, 18, 4, 18, 8));
}
}
18 changes: 18 additions & 0 deletions kclvm/tools/src/LSP/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,24 @@ pub(crate) fn inner_most_expr_in_stmt(
(None, schema_def)
}
Stmt::SchemaAttr(schema_attr_expr) => {
walk_if_contains!(
Node::node_with_pos(
Expr::Identifier(Identifier {
names: vec![*schema_attr_expr.name.clone()],
pkgpath: "".to_string(),
ctx: kclvm_ast::ast::ExprContext::Load,
}),
(
schema_attr_expr.name.filename.clone(),
schema_attr_expr.name.line,
schema_attr_expr.name.column,
schema_attr_expr.name.end_line,
schema_attr_expr.name.end_column,
),
),
pos,
schema_def
);
if schema_attr_expr.ty.contains_pos(pos) {
return (
build_identifier_from_ty_string(&schema_attr_expr.ty, pos),
Expand Down

0 comments on commit 4b8502b

Please sign in to comment.