Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix internal pkg completion #1453

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Peefy marked this conversation as resolved.
Show resolved Hide resolved
// 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.
Loading