Skip to content

Commit

Permalink
Feat: lsp support find refs (#721)
Browse files Browse the repository at this point in the history
* feat: lsp find references

Signed-off-by: xiarui.xr <[email protected]>

* find refs: add unit test; fix kcl_pos bug

Signed-off-by: xiarui.xr <[email protected]>

* find references: add more tests

Signed-off-by: xiarui.xr <[email protected]>

* remove unused comment

Signed-off-by: xiarui.xr <[email protected]>

* chore: cargo fmt

Signed-off-by: xiarui.xr <[email protected]>

* find refs: revert bench test temporarily

Signed-off-by: xiarui.xr <[email protected]>

* minor fix

Signed-off-by: xiarui.xr <[email protected]>

* minor fix: use if-else instead of match statement

Signed-off-by: xiarui.xr <[email protected]>

* lsp: cache word index in lsp state

Signed-off-by: xiarui.xr <[email protected]>

* chore: format code

Signed-off-by: xiarui.xr <[email protected]>

* find refs: incrementally update word_index after file changes

Signed-off-by: xiarui.xr <[email protected]>

---------

Signed-off-by: xiarui.xr <[email protected]>
  • Loading branch information
amyXia1994 authored Oct 12, 2023
1 parent e13ef0e commit 93eb9d7
Show file tree
Hide file tree
Showing 27 changed files with 1,106 additions and 650 deletions.
1 change: 1 addition & 0 deletions kclvm/tools/src/LSP/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn server_capabilities(client_caps: &ClientCapabilities) -> ServerCapabiliti
),
document_formatting_provider: Some(OneOf::Left(true)),
document_range_formatting_provider: Some(OneOf::Left(true)),
references_provider: Some(OneOf::Left(true)),
..Default::default()
}
}
10 changes: 5 additions & 5 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn completion_attr(
if let Some((node, schema_expr)) = is_in_schema(program, pos) {
let schema_def = find_def(node, &schema_expr.name.get_end_pos(), prog_scope);
if let Some(schema) = schema_def {
if let Definition::Object(obj) = schema {
if let Definition::Object(obj, _) = schema {
let schema_type = obj.ty.into_schema_type();
completions.extend(schema_type.attrs.keys().map(|attr| KCLCompletionItem {
label: attr.clone(),
Expand Down Expand Up @@ -178,7 +178,7 @@ pub(crate) fn get_completion(
let def = find_def(stmt, pos, prog_scope);
if let Some(def) = def {
match def {
crate::goto_def::Definition::Object(obj) => {
crate::goto_def::Definition::Object(obj, _) => {
match &obj.ty.kind {
// builtin (str) functions
kclvm_sema::ty::TypeKind::Str => {
Expand Down Expand Up @@ -226,7 +226,7 @@ pub(crate) fn get_completion(
_ => {}
}
}
crate::goto_def::Definition::Scope(s) => {
crate::goto_def::Definition::Scope(s, _) => {
for (name, obj) in &s.elems {
if let ScopeObjectKind::Module(_) = obj.borrow().kind {
continue;
Expand Down Expand Up @@ -259,7 +259,7 @@ pub(crate) fn get_completion(
find_def(stmt, &schema_expr.name.get_end_pos(), prog_scope);
if let Some(schema) = schema_def {
match schema {
Definition::Object(obj) => {
Definition::Object(obj, _) => {
let schema_type = obj.ty.into_schema_type();
items.extend(
schema_type
Expand All @@ -271,7 +271,7 @@ pub(crate) fn get_completion(
.collect::<IndexSet<KCLCompletionItem>>(),
);
}
Definition::Scope(_) => {}
Definition::Scope(_, _) => {}
}
}
}
Expand Down
28 changes: 0 additions & 28 deletions kclvm/tools/src/LSP/src/find_ref/find_refs.rs

This file was deleted.

6 changes: 0 additions & 6 deletions kclvm/tools/src/LSP/src/find_ref/go_to_def.rs

This file was deleted.

134 changes: 0 additions & 134 deletions kclvm/tools/src/LSP/src/find_ref/mod.rs

This file was deleted.

10 changes: 0 additions & 10 deletions kclvm/tools/src/LSP/src/find_ref/test_data/inherit.k

This file was deleted.

4 changes: 0 additions & 4 deletions kclvm/tools/src/LSP/src/find_ref/test_data/inherit_pkg.k

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 93eb9d7

Please sign in to comment.