Skip to content

Commit

Permalink
fix: fix internal pkg completion (#1453)
Browse files Browse the repository at this point in the history
* fix: remove file extension in completion. do not complete folders that do not contain kcl files

Signed-off-by: he1pa <[email protected]>

* add gitkeep for ut

Signed-off-by: he1pa <[email protected]>

---------

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Jun 28, 2024
1 parent 84b40c7 commit 11dffcb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use indexmap::IndexSet;
use kclvm_ast::ast::{self, ImportStmt, Program, Stmt};
use kclvm_ast::MAIN_PKG;
use kclvm_config::modfile::KCL_FILE_EXTENSION;
use kclvm_driver::get_kcl_files;
use kclvm_driver::toolchain::{get_real_path_from_external, Metadata, Toolchain};
use kclvm_sema::core::global_state::GlobalState;

Expand Down Expand Up @@ -490,6 +491,14 @@ fn completion_import_internal_pkg(
if let Ok(file_type) = entry.file_type() {
// internal pkgs
if file_type.is_dir() {
if let Ok(files) = get_kcl_files(entry.path(), true) {
// skip folder if without kcl file
if files.is_empty() {
continue;
}
} else {
continue;
}
if let Some(name) = entry.file_name().to_str() {
completions.insert(KCLCompletionItem {
label: name.to_string(),
Expand All @@ -507,14 +516,16 @@ fn completion_import_internal_pkg(
}
if let Some(extension) = path.extension() {
if extension == KCL_FILE_EXTENSION {
if let Some(name) = entry.file_name().to_str() {
completions.insert(KCLCompletionItem {
label: name.to_string(),
detail: None,
documentation: None,
kind: Some(KCLCompletionItemKind::Module),
insert_text: None,
});
if let Some(name) = path.file_stem() {
if let Some(name) = name.to_str() {
completions.insert(KCLCompletionItem {
label: name.to_string(),
detail: None,
documentation: None,
kind: Some(KCLCompletionItemKind::Module),
insert_text: None,
});
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: tools/src/LSP/src/completion.rs
expression: "format!(\"{:?}\", got_labels)"
---
["tt"]
["foo", "tt"]
Empty file.
Empty file.

0 comments on commit 11dffcb

Please sign in to comment.