Skip to content

Commit

Permalink
fix windows ut
Browse files Browse the repository at this point in the history
Signed-off-by: he1pa <18012015693@163.com>
  • Loading branch information
He1pa committed Nov 28, 2024
1 parent 3eab378 commit 5a967a2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
13 changes: 7 additions & 6 deletions kclvm/parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,10 @@ pub fn parse_program(
opts: &LoadProgramOptions,
) -> Result<LoadProgramResult> {
let compile_entries = get_compile_entries_from_paths(&paths, &opts)?;
let workdir = compile_entries.get_root_path().to_string();
let workdir = compile_entries
.get_root_path()
.to_string()
.adjust_canonicalization();
let mut pkgs: HashMap<String, Vec<String>> = HashMap::new();
let mut new_files = HashSet::new();
for entry in compile_entries.iter() {
Expand Down Expand Up @@ -1059,15 +1062,14 @@ 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();

// 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());

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 Expand Up @@ -1215,8 +1217,7 @@ pub fn get_files_from_path(
if path_buf.is_dir() {
let all_k_files_under_path = get_kcl_files(path, true)?;
for f in &all_k_files_under_path {
let p = PathBuf::from(f);

let p = PathBuf::from(f.adjust_canonicalization());
let fix_path = p
.parent()
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion kclvm/query/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn get_full_schema_type(
/// use maplit::hashmap;
/// use kclvm_ast::MAIN_PKG;
///
/// let work_dir_parent = Path::new(".").join("src").join("test_data").join("get_schema_ty_under_path");
/// let work_dir_parent = Path::new(env!("CARGO_MANIFEST_DIR")).join("src").join("test_data").join("get_schema_ty_under_path");
///
/// let result = get_full_schema_type_under_path(
/// None,
Expand Down
22 changes: 18 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,8 +1459,21 @@ 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);

// FIXME: It takes longer to parse the k8s package on Windows
#[cfg(target_os = "windows")]
wait_async!(20000);

// Mock open file
server.notification::<lsp_types::notification::DidOpenTextDocument>(
Expand All @@ -1473,6 +1486,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 5a967a2

Please sign in to comment.