@@ -57,13 +57,12 @@ fn parse_compiler_diagnostic(msg string) ?inspections.Report {
5757 }
5858}
5959
60- fn exec_compiler_diagnostics (compiler_path string , uri lsp.DocumentUri) ? []inspections.Report {
61- dir_path := uri.dir_path ()
60+ fn exec_compiler_diagnostics (compiler_path string , uri lsp.DocumentUri, project_root string ) ? []inspections.Report {
6261 filepath := uri.path ()
63- is_module := ! filepath.ends_with ('.vv' )
64- input_path := if is_module { dir_path } else { filepath }
62+ is_script := filepath.ends_with ('.vsh' ) || filepath.ends_with ('.vv' )
6563
66- res := os.execute ('${compiler_path} -enable-globals -shared -check ${input_path} ' )
64+ check_target := if is_script { filepath } else { project_root }
65+ res := os.execute ('${compiler_path} -enable-globals -shared -check ${check_target} ' )
6766
6867 if res.exit_code == 0 {
6968 return none
@@ -72,6 +71,7 @@ fn exec_compiler_diagnostics(compiler_path string, uri lsp.DocumentUri) ?[]inspe
7271 output_lines := res.output.split_into_lines ().map (term.strip_ansi (it ))
7372 errors := split_lines_to_errors (output_lines)
7473
74+ current_file_abs := os.real_path (filepath)
7575 mut reports := []inspections.Report{}
7676
7777 for error in errors {
@@ -82,29 +82,14 @@ fn exec_compiler_diagnostics(compiler_path string, uri lsp.DocumentUri) ?[]inspe
8282 continue
8383 }
8484
85- file_dir_path := os.dir (report.filepath)
86-
87- report_filepath := if os.is_abs_path (file_dir_path) {
88- // do nothing
89- report.filepath
90- } else if file_dir_path == '..' {
91- os.join_path_single (dir_path, report.filepath)
92- } else if start_idx := dir_path.last_index (file_dir_path) {
93- // reported file appears to be in a subdirectory of dir_path
94- dir_path[..start_idx] + report.filepath
95- } else {
96- // reported file appears to be in a parent directory of dir_path
97- os.join_path_single (dir_path, report.filepath)
98- }
99-
100- // ignore errors in other files
101- if report_filepath != uri.path () {
85+ report_file_abs := os.real_path (report.filepath)
86+ if os.to_slash (report_file_abs) != os.to_slash (current_file_abs) {
10287 continue
10388 }
10489
10590 reports << inspections.Report{
10691 ...report
107- filepath: report_filepath
92+ filepath: filepath
10893 }
10994 }
11095 return reports
0 commit comments