Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <18012015693@163.com>
  • Loading branch information
He1pa committed Nov 22, 2024
1 parent 3eab378 commit a08a20b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/windows_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ jobs:
working-directory: .

# Rust unit test
- run: cargo test --workspace -r -- --nocapture
# - run: cargo test --workspace -r -- --nocapture
- run: cargo test --package kcl-language-server --lib -- tests::complete_import_external_file_e2e_test --exact --show-output
working-directory: ./kclvm

- name: Read VERSION file
Expand Down
9 changes: 6 additions & 3 deletions kclvm/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,15 +1059,18 @@ pub fn load_all_files_under_paths(
}
}

let module_cache = module_cache.unwrap_or_default();
let module_cache = loader.module_cache.clone();
let pkgs_not_imported = &mut res.program.pkgs_not_imported;

let mut new_files = HashSet::new();

let mut count = 0;
// Bfs unparsed and import files
loader.parsed_file.extend(unparsed_file.clone());
while let Some(file) = unparsed_file.pop_front() {
new_files.insert(file.clone());

eprintln!("path {:?}", file.get_path());
count += 1;
eprintln!("count {:?}", count);
let module_cache_read = module_cache.read();
match &module_cache_read {
Ok(m_cache) => match m_cache.ast_cache.get(file.get_path()) {
Expand Down
2 changes: 2 additions & 0 deletions kclvm/tools/src/LSP/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ pub fn compile(
}
}

eprintln!("{:?}", "parser");
let mut program =
match load_all_files_under_paths(sess.clone(), &files, Some(opts), params.module_cache) {
Ok(r) => r.program,
Err(e) => return (diags, Err(anyhow::anyhow!("Parse failed: {:?}", e))),
};
diags.extend(sess.1.read().diagnostics.clone());

eprintln!("{:?}", "resolver");
// Resolver
if let Some(cached_scope) = params.scope_cache.as_ref() {
if let Some(file) = &params.file {
Expand Down
1 change: 1 addition & 0 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn completion(
// Complete builtin pkgs if in import stmt
completions.extend(completion_import_stmt(program, pos, metadata));
if !completions.is_empty() {
eprintln!("{:?}", "completion_import_stmt");
return Some(into_completion_items(&completions).into());
}

Expand Down
3 changes: 2 additions & 1 deletion kclvm/tools/src/LSP/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub(crate) fn handle_completion(
params: lsp_types::CompletionParams,
sender: Sender<Task>,
) -> anyhow::Result<Option<lsp_types::CompletionResponse>> {
eprintln!("{:?}", "handle_completion");
let file = file_path_from_url(&params.text_document_position.text_document.uri)?;
let path: VfsPath =
from_lsp::abs_path(&params.text_document_position.text_document.uri)?.into();
Expand Down Expand Up @@ -349,7 +350,7 @@ pub(crate) fn handle_completion(
.read()
.get(&workspace)
.and_then(|opt| opt.2.clone());

eprintln!("{:?}", "completion");
let res = completion(
completion_trigger_character,
&db.prog,
Expand Down
17 changes: 17 additions & 0 deletions kclvm/tools/src/LSP/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,16 @@ impl LanguageServerState {
opts.1.clone(),
);

eprintln!("{:?}", format!(
"Compile workspace: {:?}, main_pkg files: {:?}, changed file: {:?}, options: {:?}, metadate: {:?}, use {:?} micros",
workspace,
files,
filename,
opts.1,
opts.2,
start.elapsed().as_micros()
));

log_message(
format!(
"Compile workspace: {:?}, main_pkg files: {:?}, changed file: {:?}, options: {:?}, metadate: {:?}, use {:?} micros",
Expand Down Expand Up @@ -716,6 +726,9 @@ impl LanguageServerState {
match compile_res {
Ok((prog, schema_map, gs)) => {
let mut workspaces = snapshot.workspaces.write();
eprintln!("{:?}", format!(
"Workspace {:?} compile success",workspace
));
log_message(
format!(
"Workspace {:?} compile success",workspace
Expand All @@ -742,6 +755,10 @@ impl LanguageServerState {
}
}
Err(e) => {

eprintln!("{:?}", format!(
"Workspace {:?} compile failed: {:?}",workspace, e
));
let mut workspaces = snapshot.workspaces.write();
log_message(
format!(
Expand Down
18 changes: 14 additions & 4 deletions kclvm/tools/src/LSP/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,19 +1427,19 @@ fn formatting_unsaved_test() {

#[test]
fn complete_import_external_file_e2e_test() {
let path = PathBuf::from(".")
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("src")
.join("test_data")
.join("completion_test")
.join("import")
.join("external")
.join("external_1")
.join("external_1");
let path = root
.join("main.k")
.canonicalize()
.unwrap()
.display()
.to_string();

let _ = Command::new("kcl")
.arg("mod")
.arg("metadata")
Expand All @@ -1459,9 +1459,18 @@ fn complete_import_external_file_e2e_test() {
)
.output()
.unwrap();

let src = std::fs::read_to_string(path.clone()).unwrap();
let server = Project {}.server(InitializeParams::default());

let initialize_params = InitializeParams {
workspace_folders: Some(vec![WorkspaceFolder {
uri: Url::from_file_path(root.clone()).unwrap(),
name: "test".to_string(),
}]),
..Default::default()
};
let server = Project {}.server(initialize_params);
wait_async!(2000);
// Mock open file
server.notification::<lsp_types::notification::DidOpenTextDocument>(
lsp_types::DidOpenTextDocumentParams {
Expand All @@ -1473,6 +1482,7 @@ fn complete_import_external_file_e2e_test() {
},
},
);
wait_async!(2000);

let id = server.next_request_id.get();
server.next_request_id.set(id.wrapping_add(1));
Expand Down

0 comments on commit a08a20b

Please sign in to comment.