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
6 changes: 3 additions & 3 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,15 @@ impl Runner for LintRunner {

// Spawn linting in another thread so diagnostics can be printed immediately from diagnostic_service.run.
rayon::spawn(move || {
let mut lint_service =
LintService::new(&linter, allocator_pool, options).with_paths(paths);
let mut lint_service = LintService::new(linter, allocator_pool, options);
let _ = lint_service.with_paths(paths);

// Use `RawTransferFileSystem` if `oxlint2` feature is enabled.
// This reads the source text into start of allocator, instead of the end.
#[cfg(all(feature = "oxlint2", not(feature = "disable_oxlint2")))]
{
use crate::raw_fs::RawTransferFileSystem;
lint_service = lint_service.with_file_system(Box::new(RawTransferFileSystem));
let _ = lint_service.with_file_system(Box::new(RawTransferFileSystem));
}

lint_service.run(&tx_error);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Canvas } from '@react-three/fiber';
// PR status
debugger;

export function ThreeDMain() {
return (
<Canvas
frameloop="demand"
resize={{ debounce: 2 }}
shadows
gl={{ antialias: true, preserveDrawingBuffer: true }}
camera={{
position: [1.5, 0.5, 3.2],
fov: 10,
near: 0.1,
far: 50,
}}
key={1}
>
</Canvas>
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"devPackages": {},
"devDependencies": {
"@react-three/fiber": "^9.1.4",
"three": "^0.178.0"
}
}
48 changes: 29 additions & 19 deletions crates/oxc_language_server/src/linter/isolated_lint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use tower_lsp_server::{

use oxc_allocator::{Allocator, AllocatorPool};
use oxc_linter::{
LINTABLE_EXTENSIONS, LintService, LintServiceOptions, Linter, MessageWithPosition,
loader::Loader, read_to_arena_str,
ConfigStore, LINTABLE_EXTENSIONS, LintOptions, LintService, LintServiceOptions, Linter,
MessageWithPosition, loader::Loader, read_to_arena_str,
};
use oxc_linter::{RuntimeFileSystem, read_to_string};

Expand All @@ -29,8 +29,7 @@ pub struct IsolatedLintHandlerOptions {
}

pub struct IsolatedLintHandler {
linter: Linter,
options: IsolatedLintHandlerOptions,
service: LintService,
}

pub struct IsolatedLintHandlerFileSystem {
Expand Down Expand Up @@ -63,11 +62,25 @@ impl RuntimeFileSystem for IsolatedLintHandlerFileSystem {
}

impl IsolatedLintHandler {
pub fn new(linter: Linter, options: IsolatedLintHandlerOptions) -> Self {
Self { linter, options }
pub fn new(
lint_options: LintOptions,
config_store: ConfigStore,
options: &IsolatedLintHandlerOptions,
) -> Self {
let linter = Linter::new(lint_options, config_store);
let lint_service_options = LintServiceOptions::new(options.root_path.clone())
.with_cross_module(options.use_cross_module);

let service = LintService::new(linter, AllocatorPool::default(), lint_service_options);

Self { service }
}

pub fn run_single(&self, uri: &Uri, content: Option<String>) -> Option<Vec<DiagnosticReport>> {
pub fn run_single(
&mut self,
uri: &Uri,
content: Option<String>,
) -> Option<Vec<DiagnosticReport>> {
let path = uri.to_file_path()?;

if !Self::should_lint_path(&path) {
Expand Down Expand Up @@ -124,7 +137,7 @@ impl IsolatedLintHandler {
}

fn lint_path<'a>(
&self,
&mut self,
allocator: &'a Allocator,
path: &Path,
source_text: Option<String>,
Expand All @@ -138,17 +151,14 @@ impl IsolatedLintHandler {

debug!("lint {}", path.display());

let lint_service_options = LintServiceOptions::new(self.options.root_path.clone())
.with_cross_module(self.options.use_cross_module);

let mut lint_service =
LintService::new(&self.linter, AllocatorPool::default(), lint_service_options)
.with_file_system(Box::new(IsolatedLintHandlerFileSystem::new(
path.to_path_buf(),
source_text,
)))
.with_paths(vec![Arc::from(path.as_os_str())]);
let result = lint_service.run_source(allocator);
let result = self
.service
.with_file_system(Box::new(IsolatedLintHandlerFileSystem::new(
path.to_path_buf(),
source_text,
)))
.with_paths(vec![Arc::from(path.as_os_str())])
.run_source(allocator);

Some(result)
}
Expand Down
24 changes: 13 additions & 11 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use globset::Glob;
use ignore::gitignore::Gitignore;
use log::{debug, warn};
use rustc_hash::{FxBuildHasher, FxHashMap};
use tokio::sync::Mutex;
use tower_lsp_server::lsp_types::Uri;

use oxc_linter::{
AllowWarnDeny, Config, ConfigStore, ConfigStoreBuilder, LintOptions, Linter, Oxlintrc,
};
use oxc_linter::{AllowWarnDeny, Config, ConfigStore, ConfigStoreBuilder, LintOptions, Oxlintrc};
use tower_lsp_server::UriExt;

use crate::linter::{
Expand All @@ -22,7 +21,7 @@ use crate::{ConcurrentHashMap, OXC_CONFIG_FILE, Options};
use super::config_walker::ConfigWalker;

pub struct ServerLinter {
isolated_linter: Arc<IsolatedLintHandler>,
isolated_linter: Arc<Mutex<IsolatedLintHandler>>,
gitignore_glob: Vec<Gitignore>,
pub extended_paths: Vec<PathBuf>,
}
Expand Down Expand Up @@ -85,15 +84,14 @@ impl ServerLinter {
},
);

let linter = Linter::new(lint_options, config_store);

let isolated_linter = IsolatedLintHandler::new(
linter,
IsolatedLintHandlerOptions { use_cross_module, root_path: root_path.to_path_buf() },
lint_options,
config_store,
&IsolatedLintHandlerOptions { use_cross_module, root_path: root_path.to_path_buf() },
);

Self {
isolated_linter: Arc::new(isolated_linter),
isolated_linter: Arc::new(Mutex::new(isolated_linter)),
gitignore_glob: Self::create_ignore_glob(&root_path, &oxlintrc),
extended_paths,
}
Expand Down Expand Up @@ -200,12 +198,16 @@ impl ServerLinter {
false
}

pub fn run_single(&self, uri: &Uri, content: Option<String>) -> Option<Vec<DiagnosticReport>> {
pub async fn run_single(
&self,
uri: &Uri,
content: Option<String>,
) -> Option<Vec<DiagnosticReport>> {
if self.is_ignored(uri) {
return None;
}

self.isolated_linter.run_single(uri, content)
self.isolated_linter.lock().await.run_single(uri, content)
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_language_server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl WorkspaceWorker {
return None;
};

server_linter.run_single(uri, content)
server_linter.run_single(uri, content).await
}

fn update_diagnostics(&self, uri: &Uri, diagnostics: &[DiagnosticReport]) {
Expand All @@ -178,7 +178,8 @@ impl WorkspaceWorker {
};

for uri in self.diagnostics_report_map.pin_owned().keys() {
if let Some(diagnostics) = server_linter.run_single(&Uri::from_str(uri).unwrap(), None)
if let Some(diagnostics) =
server_linter.run_single(&Uri::from_str(uri).unwrap(), None).await
{
self.diagnostics_report_map.pin().insert(uri.clone(), diagnostics.clone());
diagnostics_map.pin().insert(uri.clone(), diagnostics);
Expand Down
18 changes: 9 additions & 9 deletions crates/oxc_linter/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ impl LintServiceOptions {
}
}

pub struct LintService<'l> {
runtime: Runtime<'l>,
pub struct LintService {
runtime: Runtime,
}

impl<'l> LintService<'l> {
impl LintService {
pub fn new(
linter: &'l Linter,
linter: Linter,
allocator_pool: oxc_allocator::AllocatorPool,
options: LintServiceOptions,
) -> Self {
Expand All @@ -77,16 +77,16 @@ impl<'l> LintService<'l> {

#[must_use]
pub fn with_file_system(
mut self,
&mut self,
file_system: Box<dyn RuntimeFileSystem + Sync + Send>,
) -> Self {
self.runtime = self.runtime.with_file_system(file_system);
) -> &mut Self {
self.runtime.with_file_system(file_system);
self
}

#[must_use]
pub fn with_paths(mut self, paths: Vec<Arc<OsStr>>) -> Self {
self.runtime = self.runtime.with_paths(paths);
pub fn with_paths(&mut self, paths: Vec<Arc<OsStr>>) -> &mut Self {
self.runtime.with_paths(paths);
self
}

Expand Down
14 changes: 7 additions & 7 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ use crate::{
#[cfg(feature = "language_server")]
use crate::fixer::MessageWithPosition;

pub struct Runtime<'l> {
pub struct Runtime {
cwd: Box<Path>,
/// All paths to lint
paths: IndexSet<Arc<OsStr>, FxBuildHasher>,
pub(super) linter: &'l Linter,
pub(super) linter: Linter,
resolver: Option<Resolver>,

pub(super) file_system: Box<dyn RuntimeFileSystem + Sync + Send>,
Expand Down Expand Up @@ -176,9 +176,9 @@ impl RuntimeFileSystem for OsFileSystem {
}
}

impl<'l> Runtime<'l> {
impl Runtime {
pub(super) fn new(
linter: &'l Linter,
linter: Linter,
allocator_pool: AllocatorPool,
options: LintServiceOptions,
) -> Self {
Expand All @@ -196,14 +196,14 @@ impl<'l> Runtime<'l> {
}

pub fn with_file_system(
mut self,
&mut self,
file_system: Box<dyn RuntimeFileSystem + Sync + Send>,
) -> Self {
) -> &Self {
self.file_system = file_system;
self
}

pub fn with_paths(mut self, paths: Vec<Arc<OsStr>>) -> Self {
pub fn with_paths(&mut self, paths: Vec<Arc<OsStr>>) -> &Self {
self.paths = paths.into_iter().collect();
self
}
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ impl Tester {
let cwd = self.current_working_directory.clone();
let paths = vec![Arc::<OsStr>::from(path_to_lint.as_os_str())];
let options = LintServiceOptions::new(cwd).with_cross_module(self.plugins.has_import());
let mut lint_service = LintService::new(&linter, AllocatorPool::default(), options)
let mut lint_service = LintService::new(linter, AllocatorPool::default(), options);
let _ = lint_service
.with_file_system(Box::new(TesterFileSystem::new(
path_to_lint,
source_text.to_string(),
Expand Down
Loading