From 63234ae6f65ca8d52aa2f572b2829aa281ad4bfb Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 18 Aug 2023 22:45:21 +0800 Subject: [PATCH 1/6] Add support for JavaScript(Node.js) --- README.md | 1 + package.json | 15 ++++++++++++++- src/compiler.ts | 2 +- src/config.ts | 7 +++++-- src/executions.ts | 8 ++++++++ src/preferences.ts | 7 +++++++ src/types.ts | 4 +++- src/utils.ts | 9 +++++++++ 8 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 129907a..0a74972 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ enter testcases. - Go - Python - Java +- JavaScript (Node.js) ## Contributing diff --git a/package.json b/package.json index ec09d4f..f6b7cae 100644 --- a/package.json +++ b/package.json @@ -210,6 +210,19 @@ "default": "javac", "description": "Command used to compile java files." }, + "cph.language.javascript.SubmissionCompiler": { + "type": "string", + "default": "Node.js 12.16.3", + "enum": [ + "Node.js 12.16.3" + ], + "description": "The compiler chosen in the drop down during Codeforces submission for Node.js" + }, + "cph.language.javascript.Command": { + "type": "string", + "default": "node", + "description": "Command used to compile .js files." + }, "cph.general.firstTime": { "title": "Show welcome message", "type": "boolean", @@ -232,7 +245,7 @@ }, "cph.general.menuChoices": { "type": "string", - "default": "cpp java python c rust", + "default": "cpp java javascript python c rust", "description": "Space separated languages, in top to bottom order, shown in menu when a problem is imported via Competitive Companion. Example 'java python' would show java on top, followed by python." }, "cph.general.useShortCodeForcesName": { diff --git a/src/compiler.ts b/src/compiler.ts index c5dd72d..18dc8bc 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -41,7 +41,7 @@ export const getBinSaveLocation = (srcPath: string): string => { }; /** - * Get the complete lsit of required arguments to be passed to the compiler. + * Get the complete list of required arguments to be passed to the compiler. * Loads additional args from preferences if available. * * @param language The Language object for the source code diff --git a/src/config.ts b/src/config.ts index 4166992..2dda093 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,6 +12,7 @@ export default { python: 'py', rust: 'rs', java: 'java', + javascript: 'js', go: 'go', }, compilers: { @@ -20,6 +21,7 @@ export default { python: 'python', rust: 'rustc', java: 'javac', + javascript: 'node', go: 'go', }, compilerToId: { @@ -33,6 +35,7 @@ export default { 'Clang++17 Diagnostics': 52, 'Java 11.0.6': 60, 'Java 1.8.0_241': 36, + 'Node.js 12.16.3': 55, 'PyPy 3.6 (7.2.0)': 41, 'Python 3.7.2': 31, 'PyPy 2.7 (7.2.0)': 40, @@ -41,6 +44,6 @@ export default { 'Go 1.19.5': 32, 'Rust 1.66.0 (2021)': 75, }, - supportedExtensions: ['py', 'cpp', 'rs', 'c', 'java', 'go'], - skipCompile: ['py'], + supportedExtensions: ['py', 'cpp', 'rs', 'c', 'java', 'js', 'go'], + skipCompile: ['py', 'js'], }; diff --git a/src/executions.ts b/src/executions.ts index d281718..ae801f8 100644 --- a/src/executions.ts +++ b/src/executions.ts @@ -59,6 +59,14 @@ export const runTestCase = ( ); break; } + case 'javascript': { + process = spawn( + language.compiler, + [binPath, ...language.args], + // spawnOpts, // `spawnOpts.env` will make PATH be empty, then can't find `node` command + ); + break; + } case 'java': { const args: string[] = []; if (onlineJudgeEnv) { diff --git a/src/preferences.ts b/src/preferences.ts index d6afa1e..fba05fb 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -94,6 +94,8 @@ export const getRustCommand = (): string => getPreference('language.rust.Command') || 'rustc'; export const getJavaCommand = (): string => getPreference('language.java.Command') || 'javac'; +export const getJavaScriptCommand = (): string => + getPreference('language.javascript.Command') || 'node'; export const getGoCommand = (): string => getPreference('language.go.Command') || 'go'; @@ -114,6 +116,11 @@ export const getLanguageId = (srcPath: string): number => { compiler = getPreference('language.java.SubmissionCompiler'); break; } + + case '.js': { + compiler = getPreference('language.javascript.SubmissionCompiler'); + break; + } case '.c': { compiler = getPreference('language.c.SubmissionCompiler'); diff --git a/src/types.ts b/src/types.ts index c53c130..39051a2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,6 +23,8 @@ export type prefSection = | 'language.java.Args' | 'language.java.SubmissionCompiler' | 'language.java.Command' + | 'language.javascript.SubmissionCompiler' + | 'language.javascript.Command' | 'language.python.Args' | 'language.python.SubmissionCompiler' | 'language.python.Command' @@ -37,7 +39,7 @@ export type Language = { skipCompile: boolean; }; -export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'go'; +export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'javascript' | 'go'; export type TestCase = { input: string; diff --git a/src/utils.ts b/src/utils.ts index ca70a4b..c93e56a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -18,6 +18,7 @@ import { getPythonCommand, getRustCommand, getJavaCommand, + getJavaScriptCommand, getGoCommand, } from './preferences'; import { Language, Problem } from './types'; @@ -81,6 +82,14 @@ export const getLanguage = (srcPath: string): Language => { skipCompile: false, }; } + case 'javascript': { + return { + name: langName, + args: [], + compiler: getJavaScriptCommand(), + skipCompile: true, + }; + } case 'go': { return { name: langName, From 4912e2ae50aea1f5acf5218e76729302e519c842 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Fri, 18 Aug 2023 22:46:00 +0800 Subject: [PATCH 2/6] Fix preLaunchTask is commented --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 14fcd4c..4203e3f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,7 @@ "args": [ "--extensionDevelopmentPath=${workspaceFolder}" ], - // "preLaunchTask": "npm: webpack", + "preLaunchTask": "npm: webpack", }, { "name": "Extension Tests", From 9fc0f8d3bb605ab89b6e8270773cb13236789ef1 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Tue, 29 Aug 2023 10:17:52 +0800 Subject: [PATCH 3/6] Fix defaultLanguage when creating file --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index f6b7cae..266a346 100644 --- a/package.json +++ b/package.json @@ -239,6 +239,7 @@ "cpp", "python", "rust", + "javascript", "java" ], "description": "The default language for problems imported via Competitive Companion (None will give option to select language on importing problem every time)" From 0e97f72bbf477387a17bbebacd0259118f906e2f Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Tue, 21 Nov 2023 16:24:21 +0000 Subject: [PATCH 4/6] Rename as js --- package.json | 4 ++-- src/config.ts | 6 +++--- src/executions.ts | 5 +++-- src/types.ts | 2 +- src/utils.ts | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 266a346..2a6ba7f 100644 --- a/package.json +++ b/package.json @@ -239,14 +239,14 @@ "cpp", "python", "rust", - "javascript", + "js", "java" ], "description": "The default language for problems imported via Competitive Companion (None will give option to select language on importing problem every time)" }, "cph.general.menuChoices": { "type": "string", - "default": "cpp java javascript python c rust", + "default": "cpp java js python c rust", "description": "Space separated languages, in top to bottom order, shown in menu when a problem is imported via Competitive Companion. Example 'java python' would show java on top, followed by python." }, "cph.general.useShortCodeForcesName": { diff --git a/src/config.ts b/src/config.ts index 2dda093..0598037 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,7 +12,7 @@ export default { python: 'py', rust: 'rs', java: 'java', - javascript: 'js', + js: 'js', go: 'go', }, compilers: { @@ -21,7 +21,7 @@ export default { python: 'python', rust: 'rustc', java: 'javac', - javascript: 'node', + js: 'node', go: 'go', }, compilerToId: { @@ -35,7 +35,7 @@ export default { 'Clang++17 Diagnostics': 52, 'Java 11.0.6': 60, 'Java 1.8.0_241': 36, - 'Node.js 12.16.3': 55, + 'Node.js 15.8.0 (64bit)': 55, 'PyPy 3.6 (7.2.0)': 41, 'Python 3.7.2': 31, 'PyPy 2.7 (7.2.0)': 40, diff --git a/src/executions.ts b/src/executions.ts index ae801f8..7e3da96 100644 --- a/src/executions.ts +++ b/src/executions.ts @@ -32,6 +32,7 @@ export const runTestCase = ( const spawnOpts = { timeout: config.timeout, env: { + ...global.process.env, DEBUG: 'true', CPH: 'true', }, @@ -59,11 +60,11 @@ export const runTestCase = ( ); break; } - case 'javascript': { + case 'js': { process = spawn( language.compiler, [binPath, ...language.args], - // spawnOpts, // `spawnOpts.env` will make PATH be empty, then can't find `node` command + spawnOpts, ); break; } diff --git a/src/types.ts b/src/types.ts index 39051a2..f37776d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -39,7 +39,7 @@ export type Language = { skipCompile: boolean; }; -export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'javascript' | 'go'; +export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'js' | 'go'; export type TestCase = { input: string; diff --git a/src/utils.ts b/src/utils.ts index c93e56a..4b92b05 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -82,7 +82,7 @@ export const getLanguage = (srcPath: string): Language => { skipCompile: false, }; } - case 'javascript': { + case 'js': { return { name: langName, args: [], From 61583ab2d9d3dabaf64962aa52ff63481a617b50 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Tue, 21 Nov 2023 16:27:32 +0000 Subject: [PATCH 5/6] Update Node.js version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2a6ba7f..36974b3 100644 --- a/package.json +++ b/package.json @@ -212,9 +212,9 @@ }, "cph.language.javascript.SubmissionCompiler": { "type": "string", - "default": "Node.js 12.16.3", + "default": "Node.js 15.8.0 (64bit)", "enum": [ - "Node.js 12.16.3" + "Node.js 15.8.0 (64bit)" ], "description": "The compiler chosen in the drop down during Codeforces submission for Node.js" }, From 07edf41ce2f359597883f8cc7f53c04fe979448f Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Wed, 22 Nov 2023 10:17:15 +0800 Subject: [PATCH 6/6] Support to config js args --- package.json | 12 +++++++++--- src/preferences.ts | 11 +++++++---- src/types.ts | 5 +++-- src/utils.ts | 7 ++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 36974b3..511d46b 100644 --- a/package.json +++ b/package.json @@ -210,15 +210,21 @@ "default": "javac", "description": "Command used to compile java files." }, - "cph.language.javascript.SubmissionCompiler": { + "cph.language.js.Args": { + "title": "Compilation flags for JavaScript", + "type": "string", + "default": "", + "description": "Space seperated additional flags passed to node (for JavaScript) while compiling your file. Example '--abort-on-uncaught-exception'" + }, + "cph.language.js.SubmissionCompiler": { "type": "string", "default": "Node.js 15.8.0 (64bit)", "enum": [ "Node.js 15.8.0 (64bit)" ], - "description": "The compiler chosen in the drop down during Codeforces submission for Node.js" + "description": "The compiler chosen in the drop down during Codeforces submission for js" }, - "cph.language.javascript.Command": { + "cph.language.js.Command": { "type": "string", "default": "node", "description": "Command used to compile .js files." diff --git a/src/preferences.ts b/src/preferences.ts index fba05fb..702491d 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -59,6 +59,9 @@ export const getRustArgsPref = (): string[] => export const getJavaArgsPref = (): string[] => getPreference('language.java.Args').split(' ') || []; +export const getJsArgsPref = (): string[] => + getPreference('language.js.Args').split(' ') || []; + export const getGoArgsPref = (): string[] => getPreference('language.go.Args').split(' ') || []; @@ -94,8 +97,8 @@ export const getRustCommand = (): string => getPreference('language.rust.Command') || 'rustc'; export const getJavaCommand = (): string => getPreference('language.java.Command') || 'javac'; -export const getJavaScriptCommand = (): string => - getPreference('language.javascript.Command') || 'node'; +export const getJsCommand = (): string => + getPreference('language.js.Command') || 'node'; export const getGoCommand = (): string => getPreference('language.go.Command') || 'go'; @@ -116,9 +119,9 @@ export const getLanguageId = (srcPath: string): number => { compiler = getPreference('language.java.SubmissionCompiler'); break; } - + case '.js': { - compiler = getPreference('language.javascript.SubmissionCompiler'); + compiler = getPreference('language.js.SubmissionCompiler'); break; } diff --git a/src/types.ts b/src/types.ts index f37776d..306fb6e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,8 +23,9 @@ export type prefSection = | 'language.java.Args' | 'language.java.SubmissionCompiler' | 'language.java.Command' - | 'language.javascript.SubmissionCompiler' - | 'language.javascript.Command' + | 'language.js.Args' + | 'language.js.SubmissionCompiler' + | 'language.js.Command' | 'language.python.Args' | 'language.python.SubmissionCompiler' | 'language.python.Command' diff --git a/src/utils.ts b/src/utils.ts index 4b92b05..15d2738 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -12,13 +12,14 @@ import { getPythonArgsPref, getRustArgsPref, getJavaArgsPref, + getJsArgsPref, getGoArgsPref, getCCommand, getCppCommand, getPythonCommand, getRustCommand, getJavaCommand, - getJavaScriptCommand, + getJsCommand, getGoCommand, } from './preferences'; import { Language, Problem } from './types'; @@ -85,8 +86,8 @@ export const getLanguage = (srcPath: string): Language => { case 'js': { return { name: langName, - args: [], - compiler: getJavaScriptCommand(), + args: [...getJsArgsPref()], + compiler: getJsCommand(), skipCompile: true, }; }