Skip to content

Commit 70803b9

Browse files
authored
feat(canon): more typechecker (#92)
* feat(canon): more typechecker * fmt * wip * wip * wip * update oxc
1 parent 4a0e51f commit 70803b9

26 files changed

+637
-583
lines changed

Cargo.lock

Lines changed: 40 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ vize_canon = { path = "crates/vize_canon", version = "0.19.0", default-features
4747
vize_fresco = { path = "crates/vize_fresco", version = "0.19.0", default-features = false }
4848

4949
# OXC dependencies (git for local dev, version for crates.io publish)
50-
oxc_parser = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
51-
oxc_ast = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
52-
oxc_ast_visit = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
53-
oxc_span = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
54-
oxc_allocator = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
55-
oxc_syntax = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
56-
oxc_diagnostics = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
57-
oxc_semantic = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
58-
oxc_transformer = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
59-
oxc_codegen = { version = "0.114.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
50+
oxc_parser = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
51+
oxc_ast = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
52+
oxc_ast_visit = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
53+
oxc_span = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
54+
oxc_allocator = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
55+
oxc_syntax = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
56+
oxc_diagnostics = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
57+
oxc_semantic = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
58+
oxc_transformer = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
59+
oxc_codegen = { version = "0.116.0", git = "https://github.com/oxc-project/oxc", branch = "main" }
6060
# oxc_formatter is not yet on crates.io, so vize_glyph is excluded from crates.io publish
6161
oxc_formatter = { git = "https://github.com/oxc-project/oxc", branch = "main" }
6262

crates/vize/src/commands/check/reporting.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ pub(crate) fn map_diagnostic_position(
6262
(vts_line + 1, vts_character + 1)
6363
}
6464

65+
/// Check if a virtual TS position has a source mapping to user code.
66+
/// Returns false for positions in generated code (compiler macros, type helpers, etc.)
67+
pub(crate) fn has_source_mapping(
68+
virtual_ts: &str,
69+
source_map: &[vize_canon::virtual_ts::VizeMapping],
70+
vts_line: u32,
71+
vts_character: u32,
72+
) -> bool {
73+
let vts_offset = line_col_to_offset(virtual_ts, vts_line, vts_character);
74+
source_map
75+
.iter()
76+
.any(|m| vts_offset >= m.gen_range.start && vts_offset < m.gen_range.end)
77+
}
78+
6579
/// Convert line/column (0-based) to byte offset in content.
6680
fn line_col_to_offset(content: &str, line: u32, col: u32) -> usize {
6781
let mut current_line = 0u32;

crates/vize/src/commands/check/runner.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub(crate) fn run_direct(args: &CheckArgs) {
189189
use vize_carton::Bump;
190190
use vize_croquis::{Analyzer, AnalyzerOptions, ImportStatementInfo, ReExportInfo, TypeExport};
191191

192-
use super::reporting::map_diagnostic_position;
192+
use super::reporting::{has_source_mapping, map_diagnostic_position};
193193

194194
let start = Instant::now();
195195

@@ -599,7 +599,26 @@ pub(crate) fn run_direct(args: &CheckArgs) {
599599
// Module resolution: fundamental limitation of single-file mode.
600600
// tsgo cannot resolve .vue imports, path aliases, or npm packages
601601
// without a full project context. This is NOT a virtual TS bug.
602-
if matches!(code_num, Some(2307) | Some(2666)) {
602+
if matches!(
603+
code_num,
604+
Some(2307)
605+
| Some(2666)
606+
| Some(6133)
607+
| Some(7006)
608+
| Some(7043)
609+
| Some(7044)
610+
) {
611+
continue;
612+
}
613+
614+
// Filter diagnostics in generated code (compiler macros, type helpers).
615+
// Only report errors that map back to user source code.
616+
if !has_source_mapping(
617+
&g.virtual_ts,
618+
&g.source_map,
619+
diag.range.start.line,
620+
diag.range.start.character,
621+
) {
603622
continue;
604623
}
605624

crates/vize_canon/src/lsp_client/mod.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ impl TsgoLspClient {
8383

8484
eprintln!("\x1b[90m[tsgo] Using: {tsgo}\x1b[0m");
8585

86-
// Determine project root (for tsgo binary search)
87-
let _project_root = working_dir
86+
// Determine project root (for node_modules resolution)
87+
let project_root = working_dir
8888
.map(std::path::PathBuf::from)
8989
.or_else(|| std::env::current_dir().ok())
9090
.and_then(|p| p.canonicalize().ok());
@@ -95,6 +95,33 @@ impl TsgoLspClient {
9595
let temp_dir_path = std::env::temp_dir().join(&*cstr!("vize-tsgo-{}", std::process::id()));
9696
std::fs::create_dir_all(&temp_dir_path)
9797
.map_err(|e| cstr!("Failed to create temp directory: {e}"))?;
98+
99+
// Find and symlink node_modules so tsgo can resolve packages (e.g., 'vue').
100+
// Walk up from project root to find node_modules that contains 'vue'.
101+
let node_modules_path = project_root.as_ref().and_then(|root| {
102+
let mut dir = root.as_path();
103+
loop {
104+
let nm = dir.join("node_modules");
105+
if nm.join("vue").is_dir() {
106+
return Some(nm);
107+
}
108+
dir = dir.parent()?;
109+
}
110+
});
111+
if let Some(ref nm_path) = node_modules_path {
112+
let symlink_target = temp_dir_path.join("node_modules");
113+
// Remove stale symlink if exists
114+
let _ = std::fs::remove_file(&symlink_target);
115+
#[cfg(unix)]
116+
{
117+
let _ = std::os::unix::fs::symlink(nm_path, &symlink_target);
118+
}
119+
#[cfg(windows)]
120+
{
121+
let _ = std::os::windows::fs::symlink_dir(nm_path, &symlink_target);
122+
}
123+
}
124+
98125
let tsconfig_content = serde_json::json!({
99126
"compilerOptions": {
100127
"target": "ES2022",

0 commit comments

Comments
 (0)