Skip to content

Commit 41d75c4

Browse files
committed
refactor(linter/plugins): simplify callback functions for create/destroy workspace (#18761)
Simple refactor. When a NAPI function has only a single param, no need to use `FnArgs`.
1 parent 64ddbe1 commit 41d75c4

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

apps/oxlint/src-js/bindings.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ export declare function getBufferOffset(buffer: Uint8Array): number
3636

3737
/** JS callback to create a workspace. */
3838
export type JsCreateWorkspaceCb =
39-
((arg0: string) => Promise<undefined>)
39+
((arg: string) => Promise<undefined>)
4040

4141
/** JS callback to destroy a workspace. */
4242
export type JsDestroyWorkspaceCb =
43-
((arg0: string) => void)
43+
((arg: string) => void)
4444

4545
/** JS callback to lint a file. */
4646
export type JsLintFileCb =

apps/oxlint/src/js_plugins/external_linter.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,8 @@ fn wrap_create_workspace(cb: JsCreateWorkspaceCb) -> ExternalLinterCreateWorkspa
312312
Arc::new(Box::new(move |workspace_uri| {
313313
let cb = &cb;
314314
let res = tokio::task::block_in_place(|| {
315-
tokio::runtime::Handle::current().block_on(async move {
316-
cb.call_async(FnArgs::from((workspace_uri,))).await?.into_future().await
317-
})
315+
tokio::runtime::Handle::current()
316+
.block_on(async move { cb.call_async(workspace_uri).await?.into_future().await })
318317
});
319318

320319
match res {
@@ -328,7 +327,7 @@ fn wrap_create_workspace(cb: JsCreateWorkspaceCb) -> ExternalLinterCreateWorkspa
328327

329328
/// Wrap `destroyWorkspace` JS callback as a normal Rust function.
330329
fn wrap_destroy_workspace(cb: JsDestroyWorkspaceCb) -> ExternalLinterDestroyWorkspaceCb {
331-
Arc::new(Box::new(move |workspace_uri: String| {
332-
let _ = cb.call(FnArgs::from((workspace_uri,)), ThreadsafeFunctionCallMode::Blocking);
330+
Arc::new(Box::new(move |workspace_uri| {
331+
let _ = cb.call(workspace_uri, ThreadsafeFunctionCallMode::Blocking);
333332
}))
334333
}

apps/oxlint/src/run.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ pub type JsSetupRuleConfigsCb = ThreadsafeFunction<
8585
#[napi]
8686
pub type JsCreateWorkspaceCb = ThreadsafeFunction<
8787
// Arguments
88-
FnArgs<(String,)>, // Workspace URI
88+
String, // Workspace URI
8989
// Return value
9090
Promise<()>,
9191
// Arguments (repeated)
92-
FnArgs<(String,)>,
92+
String,
9393
// Error status
9494
Status,
9595
// CalleeHandled
@@ -100,11 +100,11 @@ pub type JsCreateWorkspaceCb = ThreadsafeFunction<
100100
#[napi]
101101
pub type JsDestroyWorkspaceCb = ThreadsafeFunction<
102102
// Arguments
103-
FnArgs<(String,)>, // Workspace URI
103+
String, // Workspace URI
104104
// Return value
105105
(),
106106
// Arguments (repeated)
107-
FnArgs<(String,)>,
107+
String,
108108
// Error status
109109
Status,
110110
// CalleeHandled

0 commit comments

Comments
 (0)