Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl IsolatedLintHandler {

let mut messages: Vec<DiagnosticReport> = self
.runner
.run_source(&Arc::from(path.as_os_str()), &fs)
.run_source(&[Arc::from(path.as_os_str())], &fs)
.into_iter()
.map(|message| message_to_lsp_diagnostic(message, uri, source_text, rope))
.collect();
Expand Down
30 changes: 15 additions & 15 deletions crates/oxc_linter/src/lint_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,25 +235,25 @@ impl LintRunner {
/// Returns an error if type-aware linting fails.
pub fn run_source(
&self,
file: &Arc<OsStr>,
files: &[Arc<OsStr>],
file_system: &(dyn crate::RuntimeFileSystem + Sync + Send),
) -> Vec<Message> {
let mut messages = self.lint_service.run_source(file_system, vec![Arc::clone(file)]);
let mut messages = self.lint_service.run_source(file_system, files.to_owned());

if let Some(type_aware_linter) = &self.type_aware_linter {
let tsgo_messages =
match type_aware_linter.lint_source(file, file_system, self.directives_store.map())
{
Ok(msgs) => msgs,
Err(err) => {
vec![Message::new(
OxcDiagnostic::warn(format!(
"Failed to run type-aware linting: `{err}`",
)),
PossibleFixes::None,
)]
}
};
let tsgo_messages = match type_aware_linter.lint_source(
files,
file_system,
self.directives_store.map(),
) {
Ok(msgs) => msgs,
Err(err) => {
vec![Message::new(
OxcDiagnostic::warn(format!("Failed to run type-aware linting: `{err}`",)),
PossibleFixes::None,
)]
}
};
messages.extend(tsgo_messages);
}

Expand Down
47 changes: 32 additions & 15 deletions crates/oxc_linter/src/tsgolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,29 +320,37 @@ impl TsGoLintState {
/// A human-readable error message indicating why the linting failed.
pub fn lint_source(
&self,
path: &Arc<OsStr>,
paths: &[Arc<OsStr>],
file_system: &(dyn crate::RuntimeFileSystem + Sync + Send),
disable_directives_map: Arc<Mutex<FxHashMap<PathBuf, DisableDirectives>>>,
) -> Result<Vec<Message>, String> {
if paths.is_empty() {
return Ok(vec![]);
}

let mut resolved_configs: FxHashMap<PathBuf, ResolvedLinterState> = FxHashMap::default();
let mut source_overrides = FxHashMap::default();
let mut source_overrides: FxHashMap<String, String> = FxHashMap::default();
let allocator = Allocator::default();
let Ok(source_text) = file_system.read_to_arena_str(Path::new(path.as_ref()), &allocator)
else {
return Err(format!("Failed to read source text for file: {}", path.to_string_lossy()));
};

// Clone source_text to own it for the spawned thread
let source_text_owned = source_text.to_string();
source_overrides.insert(path.to_string_lossy().to_string(), source_text_owned.clone());
// Read all sources into overrides
for path in paths {
let path_ref = Path::new(path.as_ref());
let Ok(source_text) = file_system.read_to_arena_str(path_ref, &allocator) else {
return Err(format!(
"Failed to read source text for file: {}",
path.to_string_lossy()
));
};
source_overrides.insert(path.to_string_lossy().to_string(), source_text.to_string());
}

let json_input = self.json_input(
std::slice::from_ref(path),
Some(source_overrides),
&mut resolved_configs,
);
let json_input =
self.json_input(paths, Some(source_overrides.clone()), &mut resolved_configs);

// Get the file name of the first path for internal diagnostic filtering
let path_file_name =
Path::new(path.as_ref()).file_name().unwrap_or_default().to_os_string();
Path::new(paths[0].as_ref()).file_name().unwrap_or_default().to_os_string();

let mut child = self.spawn_tsgolint(&json_input)?;
let handler = std::thread::spawn(move || {
let stdout = child.stdout.take().expect("Failed to open tsgolint stdout");
Expand Down Expand Up @@ -390,6 +398,15 @@ impl TsGoLintState {
continue;
}

// Use the corresponding source override text
let Some(source_text_owned) = source_overrides
.get(&path.to_string_lossy().to_string())
.cloned()
else {
// should never happen, because we populated source_overrides above
continue;
};

let mut message = Message::from_tsgo_lint_diagnostic(
tsgolint_diagnostic,
&source_text_owned,
Expand Down
Loading