Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JavaScript(Node.js) #360

Merged
merged 6 commits into from
Nov 22, 2023
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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
// "preLaunchTask": "npm: webpack",
"preLaunchTask": "npm: webpack",
},
{
"name": "Extension Tests",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enter testcases.
- Go
- Python
- Java
- JavaScript (Node.js)

## Contributing

Expand Down
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@
"default": "javac",
"description": "Command used to compile java files."
},
"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 js"
},
"cph.language.js.Command": {
"type": "string",
"default": "node",
"description": "Command used to compile .js files."
},
"cph.general.firstTime": {
"title": "Show welcome message",
"type": "boolean",
Expand All @@ -226,13 +245,14 @@
"cpp",
"python",
"rust",
"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 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": {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
agrawal-d marked this conversation as resolved.
Show resolved Hide resolved
* Loads additional args from preferences if available.
*
* @param language The Language object for the source code
Expand Down
7 changes: 5 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
python: 'py',
rust: 'rs',
java: 'java',
js: 'js',
go: 'go',
},
compilers: {
Expand All @@ -20,6 +21,7 @@ export default {
python: 'python',
rust: 'rustc',
java: 'javac',
js: 'node',
go: 'go',
},
compilerToId: {
Expand All @@ -33,6 +35,7 @@ export default {
'Clang++17 Diagnostics': 52,
'Java 11.0.6': 60,
'Java 1.8.0_241': 36,
'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,
Expand All @@ -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'],
};
9 changes: 9 additions & 0 deletions src/executions.ts
chinesedfan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const runTestCase = (
const spawnOpts = {
timeout: config.timeout,
env: {
...global.process.env,
DEBUG: 'true',
CPH: 'true',
},
Expand Down Expand Up @@ -59,6 +60,14 @@ export const runTestCase = (
);
break;
}
case 'js': {
process = spawn(
language.compiler,
[binPath, ...language.args],
spawnOpts,
);
break;
}
case 'java': {
const args: string[] = [];
if (onlineJudgeEnv) {
Expand Down
10 changes: 10 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ') || [];

Expand Down Expand Up @@ -94,6 +97,8 @@ export const getRustCommand = (): string =>
getPreference('language.rust.Command') || 'rustc';
export const getJavaCommand = (): string =>
getPreference('language.java.Command') || 'javac';
export const getJsCommand = (): string =>
getPreference('language.js.Command') || 'node';
export const getGoCommand = (): string =>
getPreference('language.go.Command') || 'go';

Expand All @@ -115,6 +120,11 @@ export const getLanguageId = (srcPath: string): number => {
break;
}

case '.js': {
compiler = getPreference('language.js.SubmissionCompiler');
break;
}

case '.c': {
compiler = getPreference('language.c.SubmissionCompiler');
break;
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export type prefSection =
| 'language.java.Args'
| 'language.java.SubmissionCompiler'
| 'language.java.Command'
| 'language.js.Args'
| 'language.js.SubmissionCompiler'
| 'language.js.Command'
| 'language.python.Args'
| 'language.python.SubmissionCompiler'
| 'language.python.Command'
Expand All @@ -37,7 +40,7 @@ export type Language = {
skipCompile: boolean;
};

export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'go';
export type LangNames = 'python' | 'c' | 'cpp' | 'rust' | 'java' | 'js' | 'go';

export type TestCase = {
input: string;
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {
getPythonArgsPref,
getRustArgsPref,
getJavaArgsPref,
getJsArgsPref,
getGoArgsPref,
getCCommand,
getCppCommand,
getPythonCommand,
getRustCommand,
getJavaCommand,
getJsCommand,
getGoCommand,
} from './preferences';
import { Language, Problem } from './types';
Expand Down Expand Up @@ -81,6 +83,14 @@ export const getLanguage = (srcPath: string): Language => {
skipCompile: false,
};
}
case 'js': {
return {
name: langName,
args: [...getJsArgsPref()],
compiler: getJsCommand(),
skipCompile: true,
};
}
case 'go': {
return {
name: langName,
Expand Down
Loading