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 windows ci #1685

Merged
merged 4 commits into from
Oct 12, 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
2 changes: 1 addition & 1 deletion .github/workflows/windows_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
working-directory: .

# Rust unit test
- run: cargo test -r -p kclvm-*
- run: cargo test --workspace -r -- --nocapture
working-directory: ./kclvm

- uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions kclvm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions kclvm/ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,32 @@ pub struct Pos(String, u64, u64, u64, u64);

impl From<PosTuple> for Pos {
fn from(value: PosTuple) -> Self {
Self(value.0, value.1, value.2, value.3, value.4)
Self(
value.0.adjust_canonicalization(),
value.1,
value.2,
value.3,
value.4,
)
}
}

impl From<Pos> for PosTuple {
fn from(val: Pos) -> Self {
(val.0, val.1, val.2, val.3, val.4)
(val.0.adjust_canonicalization(), val.1, val.2, val.3, val.4)
}
}

impl From<Pos> for Range {
fn from(val: Pos) -> Self {
(
Position {
filename: val.0.clone(),
filename: val.0.clone().adjust_canonicalization(),
line: val.1,
column: Some(val.2),
},
Position {
filename: val.0,
filename: val.0.adjust_canonicalization(),
line: val.3,
column: Some(val.4),
},
Expand Down Expand Up @@ -220,7 +226,7 @@ impl<T> Node<T> {
Self {
id,
node,
filename: pos.0.clone(),
filename: pos.0.clone().adjust_canonicalization(),
line: pos.1,
column: pos.2,
end_line: pos.3,
Expand All @@ -232,7 +238,7 @@ impl<T> Node<T> {
Self {
id: AstIndex::default(),
node,
filename: pos.0.clone(),
filename: pos.0.clone().adjust_canonicalization(),
line: pos.1,
column: pos.2,
end_line: pos.3,
Expand All @@ -242,7 +248,7 @@ impl<T> Node<T> {

pub fn pos(&self) -> PosTuple {
(
self.filename.clone(),
self.filename.clone().adjust_canonicalization(),
self.line,
self.column,
self.end_line,
Expand All @@ -251,7 +257,7 @@ impl<T> Node<T> {
}

pub fn set_pos(&mut self, pos: PosTuple) {
self.filename = pos.0.clone();
self.filename = pos.0.clone().adjust_canonicalization();
self.line = pos.1;
self.column = pos.2;
self.end_line = pos.3;
Expand Down
9 changes: 8 additions & 1 deletion kclvm/parser/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use kclvm_utils::path::{is_absolute, is_dir, path_exist};
use std::collections::VecDeque;
use std::fs;
use std::path::Path;
use std::path::PathBuf;

use crate::LoadProgramOptions;

Expand Down Expand Up @@ -424,7 +425,13 @@ fn get_main_files_from_pkg_path(
}
}

path_list.push(s);
match PathBuf::from(s.clone()).canonicalize() {
Ok(path) => {
path_list.push(path.to_str().unwrap().to_string());
}
// path from virtual file system
Err(_) => path_list.push(s),
}

// get k files
let mut k_files: Vec<String> = Vec::new();
Expand Down
7 changes: 5 additions & 2 deletions kclvm/parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use kclvm_ast::token::{CommentKind, Token, TokenKind};
use kclvm_ast::token_stream::{Cursor, TokenStream};
use kclvm_error::ParseErrorMessage;
use kclvm_span::symbol::Symbol;
use kclvm_utils::path::PathPrefix;

/// The parser is built on top of the [`kclvm_parser::lexer`], and ordering KCL tokens
/// [`kclvm_ast::token`] to KCL ast nodes [`kclvm_ast::ast`].
Expand Down Expand Up @@ -86,7 +87,8 @@ impl<'a> Parser<'a> {
let filename = kclvm_utils::path::convert_windows_drive_letter(&format!(
"{}",
lo.file.name.prefer_remapped()
));
))
.adjust_canonicalization();

(
filename,
Expand Down Expand Up @@ -197,7 +199,8 @@ impl<'a> Parser<'a> {
let hi = sess.lookup_char_pos(tok.span.hi());
let filename = kclvm_utils::path::convert_windows_drive_letter(
&format!("{}", lo.file.name.prefer_remapped()),
);
)
.adjust_canonicalization();

let node = kclvm_ast::ast::Node {
id: kclvm_ast::ast::AstIndex::default(),
Expand Down
1 change: 1 addition & 0 deletions kclvm/query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ kclvm-ast-pretty = {path = "../ast_pretty"}
kclvm-parser = {path = "../parser"}
kclvm-sema = {path = "../sema"}
kclvm-error = {path = "../error"}
kclvm-utils ={ path = "../utils"}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
fancy-regex = "0.7.1"
Expand Down
9 changes: 7 additions & 2 deletions kclvm/query/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
};
use kclvm_error::{DiagnosticId, ErrorKind, Level};
use kclvm_parser::parse_file_force_errors;
use kclvm_utils::path::PathPrefix;
use pretty_assertions::assert_eq;
use selector::ListOptions;

Expand Down Expand Up @@ -887,8 +888,12 @@ fn test_overridefile_with_invalid_kcl() {
"expected one of [\"=\"] got eof"
);
assert_eq!(
result.parse_errors[0].messages[0].range.0.filename,
simple_path.display().to_string()
result.parse_errors[0].messages[0]
.range
.0
.filename
.adjust_canonicalization(),
simple_path.display().to_string().adjust_canonicalization()
);
assert_eq!(result.parse_errors[0].messages[0].range.0.line, 1);
assert_eq!(result.parse_errors[0].messages[0].range.0.column, Some(8));
Expand Down
4 changes: 2 additions & 2 deletions kclvm/tools/benches/proc_macro_crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub fn bench_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
let end_time = std::time::Instant::now();
let time = (end_time - start_time).as_micros();
println!("{} took {} μs", stringify!(#fn_name), (end_time - start_time).as_micros());
// 200 ms
assert!(time < 200000, "Bench mark test failed");
// 400 ms
assert!(time < 400000, "Bench mark test failed");
result
}
};
Expand Down
11 changes: 8 additions & 3 deletions kclvm/tools/src/LSP/src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashSet;

use indexmap::IndexSet;
use kclvm_ast::ast::Program;
use kclvm_driver::{lookup_compile_workspace, toolchain};
Expand All @@ -14,6 +12,8 @@ use kclvm_sema::{
namer::Namer,
resolver::{resolve_program_with_opts, scope::KCLScopeCache},
};
use std::collections::HashSet;
use std::path::PathBuf;

use crate::{
state::{KCLGlobalStateCache, KCLVfs},
Expand Down Expand Up @@ -149,7 +149,12 @@ pub fn compile_with_params(
IndexSet<kclvm_error::Diagnostic>,
anyhow::Result<(Program, GlobalState)>,
) {
let file = params.file.clone().unwrap();
let file = PathBuf::from(params.file.clone().unwrap())
.canonicalize()
.unwrap()
.to_str()
.unwrap()
.to_string();
// Lookup compile workspace from the cursor file.
let (mut files, opts, _) = lookup_compile_workspace(&toolchain::default(), &file, true);
if !files.contains(&file) {
Expand Down
12 changes: 6 additions & 6 deletions kclvm/tools/src/LSP/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
//! + new line
//! + schema init

use std::io;
use std::{fs, path::Path};

use crate::goto_def::{find_def, find_symbol};
use indexmap::IndexSet;
use kclvm_ast::ast::{self, ImportStmt, Program, Stmt};
Expand All @@ -26,6 +23,8 @@ 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;
use std::io;
use std::{fs, path::Path};

use kclvm_error::Position as KCLPos;
use kclvm_sema::builtin::{BUILTIN_FUNCTIONS, STANDARD_SYSTEM_MODULES};
Expand All @@ -34,6 +33,7 @@ use kclvm_sema::core::scope::{LocalSymbolScopeKind, ScopeKind};
use kclvm_sema::core::symbol::SymbolKind;
use kclvm_sema::resolver::doc::{parse_schema_doc_string, SchemaDoc};
use kclvm_sema::ty::{FunctionType, SchemaType, Type, TypeKind};
use kclvm_utils::path::PathPrefix;
use lsp_types::{CompletionItem, CompletionItemKind, InsertTextFormat};

use crate::util::{inner_most_expr_in_stmt, is_in_docstring};
Expand Down Expand Up @@ -252,7 +252,6 @@ fn completion_dot(
if symbol.is_none() {
symbol = find_symbol(pos, gs, false);
}

let def = match symbol {
Some(symbol_ref) => {
if let SymbolKind::Unresolved = symbol_ref.get_kind() {
Expand Down Expand Up @@ -472,7 +471,6 @@ fn completion_import_stmt(
line: pos.line,
column: Some(0),
};

if let Some(node) = program.pos_to_stmt(line_start_pos) {
if let Stmt::Import(_) = node.node {
completions.extend(completion_import_builtin_pkg());
Expand Down Expand Up @@ -527,7 +525,9 @@ fn completion_import_internal_pkg(
} else {
// internal module
let path = entry.path();
if path.to_str().unwrap_or("") == line_start_pos.filename {
if path.to_str().unwrap_or("").adjust_canonicalization()
== line_start_pos.filename.adjust_canonicalization()
{
continue;
}
if let Some(extension) = path.extension() {
Expand Down
81 changes: 35 additions & 46 deletions kclvm/tools/src/LSP/src/document_symbol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::path::Path;

use kclvm_ast::MAIN_PKG;
use kclvm_error::Position;
use kclvm_sema::core::global_state::GlobalState;
Expand Down Expand Up @@ -28,57 +26,48 @@ pub fn document_symbol(file: &str, gs: &GlobalState) -> Option<lsp_types::Docume
Some(def) => {
let symbol_range = symbol.get_range();
// filter current file symbols
if let Ok(canonicalized_path) =
Path::new(&symbol_range.0.filename).canonicalize()
{
if canonicalized_path.eq(Path::new(file)) {
match def.get_kind() {
KCLSymbolKind::Schema => {
match &mut symbol_to_document_symbol(symbol) {
Some(schema_symbol) => {
let module_info = gs
.get_packages()
.get_module_info(&dummy_pos.filename);
let attrs = symbol.get_all_attributes(
gs.get_symbols(),
module_info,
);
let mut children = vec![];

for attr in attrs {
match gs.get_symbols().get_symbol(attr)
{
Some(attr_symbol) => {
match symbol_to_document_symbol(
attr_symbol,
) {
Some(symbol) => {
children.push(symbol)
}
None => {}
if symbol_range.0.filename == file {
match def.get_kind() {
KCLSymbolKind::Schema => {
match &mut symbol_to_document_symbol(symbol) {
Some(schema_symbol) => {
let module_info = gs
.get_packages()
.get_module_info(&dummy_pos.filename);
let attrs = symbol.get_all_attributes(
gs.get_symbols(),
module_info,
);
let mut children = vec![];

for attr in attrs {
match gs.get_symbols().get_symbol(attr) {
Some(attr_symbol) => {
match symbol_to_document_symbol(
attr_symbol,
) {
Some(symbol) => {
children.push(symbol)
}
None => {}
}
None => {}
}
None => {}
}

schema_symbol.children = Some(children);
schema_symbol.name = format!(
"schema {}",
schema_symbol.name
);
document_symbols
.push(schema_symbol.clone());
}
None => {}

schema_symbol.children = Some(children);
schema_symbol.name =
format!("schema {}", schema_symbol.name);
document_symbols.push(schema_symbol.clone());
}
None => {}
}
_ => {
if let Some(symbol) =
symbol_to_document_symbol(symbol)
{
document_symbols.push(symbol)
}
}
_ => {
if let Some(symbol) = symbol_to_document_symbol(symbol)
{
document_symbols.push(symbol)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion kclvm/tools/src/LSP/src/find_refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ mod tests {
for loc in resp {
let url = file_path_from_url(&loc.uri).unwrap();
let got_path = Path::new(&url);
let relative_path = got_path.strip_prefix(root_path.clone()).unwrap();
let relative_path = got_path
.strip_prefix(root_path.clone())
.unwrap()
.display()
.to_string()
.replace("\\", "/");
res.push_str(&format!(
"path: {:?}, range: {:?}\n",
relative_path, loc.range
Expand Down
Loading
Loading