Skip to content
Closed
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
4 changes: 3 additions & 1 deletion crates/oxc_language_server/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ impl IsolatedLintHandler {
return Some(Self::wrap_diagnostics(path, &original_source_text, reports, start));
};

let use_cfg = linter.rules().iter().any(|it| it.rule.use_cfg());

let program = allocator.alloc(ret.program);
let semantic_ret = SemanticBuilder::new(javascript_source_text, source_type)
.with_trivias(ret.trivias)
.with_cfg(true)
.with_cfg(use_cfg)
.with_check_syntax_error(true)
.build(program);

Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ impl Default for Linter {
}

impl Linter {
pub fn rules(&self) -> &Vec<RuleWithSeverity> {
&self.rules
}

/// # Errors
///
/// Returns `Err` if there are any errors parsing the configuration file.
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,12 @@ impl Runtime {

let trivias = ret.trivias;

let use_cfg = self.linter.rules.iter().any(|it| it.rule.use_cfg());

// Build the module record to unblock other threads from waiting for too long.
// The semantic model is not built at this stage.
let semantic_builder = SemanticBuilder::new(source_text, source_type)
.with_cfg(true)
.with_cfg(use_cfg)
.with_trivias(trivias)
.with_check_syntax_error(check_syntax_errors)
.build_module_record(path.to_path_buf(), program);
Expand Down