Skip to content

Commit 784a33c

Browse files
committed
refacor(vscode): run js language server with node
1 parent 7e3135f commit 784a33c

File tree

4 files changed

+23
-43
lines changed

4 files changed

+23
-43
lines changed

editors/vscode/.vscode-test.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export default defineConfig({
5858
],
5959
env: {
6060
SINGLE_FOLDER_WORKSPACE: 'true',
61-
OXLINT_LSP_TEST: 'true',
6261
SERVER_PATH_DEV: path.resolve(import.meta.dirname, `../../apps/oxlint/dist/cli.js`),
6362
SKIP_FORMATTER_TEST: 'true',
6463
},

editors/vscode/client/PathValidator.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,5 @@ export function validateSafeBinaryPath(binary: string): boolean {
3939
}
4040
}
4141

42-
// Check if the filename contains `oxc_language_server` or `oxlint`
43-
// Malicious projects might try to point to a different binary.
44-
if (
45-
!binary.replaceAll('\\', '/').toLowerCase().split('/').pop()?.includes('oxc_language_server') &&
46-
!binary.replaceAll('\\', '/').toLowerCase().split('/').pop()?.includes('oxlint')
47-
) {
48-
return false;
49-
}
50-
5142
return true;
5243
}

editors/vscode/client/linter.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,29 @@ export async function activate(
100100
}
101101

102102
const path = await findBinary();
103-
104-
const run: Executable =
105-
process.env.OXLINT_LSP_TEST === 'true'
106-
? {
107-
command: 'node',
108-
args: [path!, '--lsp'],
109-
options: {
110-
env: serverEnv,
111-
},
112-
}
113-
: {
114-
command: path!,
115-
args: ['--lsp'],
116-
options: {
117-
// On Windows we need to run the binary in a shell to be able to execute the shell npm bin script.
118-
// Searching for the right `.exe` file inside `node_modules/` is not reliable as it depends on
119-
// the package manager used (npm, yarn, pnpm, etc) and the package version.
120-
// The npm bin script is a shell script that points to the actual binary.
121-
// Security: We validated the userDefinedBinary in `configService.getUserServerBinPath()`.
122-
shell: process.platform === 'win32',
123-
env: serverEnv,
124-
},
125-
};
103+
const isNode = path.endsWith('.js') || path.endsWith('.cjs') || path.endsWith('.mjs');
104+
105+
const run: Executable = isNode
106+
? {
107+
command: 'node',
108+
args: [path!, '--lsp'],
109+
options: {
110+
env: serverEnv,
111+
},
112+
}
113+
: {
114+
command: path!,
115+
args: ['--lsp'],
116+
options: {
117+
// On Windows we need to run the binary in a shell to be able to execute the shell npm bin script.
118+
// Searching for the right `.exe` file inside `node_modules/` is not reliable as it depends on
119+
// the package manager used (npm, yarn, pnpm, etc) and the package version.
120+
// The npm bin script is a shell script that points to the actual binary.
121+
// Security: We validated the userDefinedBinary in `configService.getUserServerBinPath()`.
122+
shell: process.platform === 'win32',
123+
env: serverEnv,
124+
},
125+
};
126126

127127
const serverOptions: ServerOptions = {
128128
run,

editors/vscode/tests/PathValidator.spec.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,4 @@ suite('validateSafeBinaryPath', () => {
3737
strictEqual(validateSafeBinaryPath('oxc_language_server^&pause'), false);
3838
strictEqual(validateSafeBinaryPath('oxc_language_server & del /f *'), false);
3939
});
40-
41-
test('should reject paths not containing oxc_language_server', () => {
42-
strictEqual(validateSafeBinaryPath('/usr/local/bin/malicious'), false);
43-
strictEqual(validateSafeBinaryPath('fake_server'), false);
44-
strictEqual(validateSafeBinaryPath(''), false);
45-
strictEqual(validateSafeBinaryPath('oxc_language'), false);
46-
strictEqual(validateSafeBinaryPath('language_server'), false);
47-
strictEqual(validateSafeBinaryPath('/oxc_language_server/malicious'), false);
48-
strictEqual(validateSafeBinaryPath('C:\\oxc_language_server\\evil.exe'), false);
49-
});
5040
});

0 commit comments

Comments
 (0)