Skip to content

Commit

Permalink
added support for ruby (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
karan-ydv committed Jun 24, 2024
1 parent 94b0425 commit d74f768
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enter testcases.
- Go
- Haskell
- Python
- Ruby
- Java
- JavaScript (Node.js)

Expand Down
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@
"default": "python3",
"description": "Command used to run python files. Example 'py', 'python3', 'pypy3', etc."
},
"cph.language.ruby.Args": {
"title": "Compilation flags for ruby",
"type": "string",
"default": "",
"description": "Space seperated additional flags passed to ruby while compiling your file."
},
"cph.language.ruby.SubmissionCompiler": {
"type": "string",
"default": "Ruby 3.2.2",
"enum": [
"Ruby 3.2.2"
],
"description": "The compiler chosen in the drop down during Codeforces submission for python"
},
"cph.language.ruby.Command": {
"type": "string",
"default": "ruby",
"description": "Command used to run ruby files."
},
"cph.language.rust.Args": {
"title": "Compilation flags for Rust",
"type": "string",
Expand Down Expand Up @@ -266,13 +285,14 @@
"python",
"rust",
"js",
"java"
"java",
"ruby"
],
"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 js python c rust",
"default": "cpp java js python c rust ruby",
"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
17 changes: 15 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default {
c: 'c',
cpp: 'cpp',
python: 'py',
ruby: 'rb',
rust: 'rs',
java: 'java',
js: 'js',
Expand All @@ -21,6 +22,7 @@ export default {
c: 'gcc',
cpp: 'g++',
python: 'python',
ruby: 'ruby',
rust: 'rustc',
java: 'javac',
js: 'node',
Expand All @@ -44,11 +46,22 @@ export default {
'Python 3.8.10': 31,
'PyPy 2.7.13 (7.3.0)': 40,
'Python 2.7.18': 7,
'Ruby 3.2.2': 67,
'GNU GCC C11 5.1.0': 43,
'Go 1.19.5': 32,
'Rust 1.66.0 (2021)': 75,
'Haskell GHC 8.10.1': 12,
},
supportedExtensions: ['py', 'cpp', 'rs', 'c', 'java', 'js', 'go', 'hs'],
skipCompile: ['py', 'js'],
supportedExtensions: [
'py',
'cpp',
'rs',
'c',
'java',
'js',
'go',
'hs',
'rb',
],
skipCompile: ['py', 'js', 'rb'],
};
8 changes: 8 additions & 0 deletions src/executions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export const runTestCase = (
);
break;
}
case 'ruby': {
process = spawn(
language.compiler,
[binPath, ...language.args],
spawnOpts,
);
break;
}
case 'js': {
process = spawn(
language.compiler,
Expand Down
10 changes: 10 additions & 0 deletions src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export const getCArgsPref = (): string[] =>
export const getPythonArgsPref = (): string[] =>
getPreference('language.python.Args').split(' ') || [];

export const getRubyArgsPref = (): string[] =>
getPreference('language.ruby.Args').split(' ').filter(Boolean) || [];

export const getHaskellArgsPref = (): string[] =>
getPreference('language.haskell.Args').split(' ') || [];

Expand Down Expand Up @@ -96,6 +99,8 @@ export const getCppCommand = (): string =>
getPreference('language.cpp.Command') || 'g++';
export const getPythonCommand = (): string =>
getPreference('language.python.Command') || 'python3';
export const getRubyCommand = (): string =>
getPreference('language.ruby.Command') || 'ruby';
export const getRustCommand = (): string =>
getPreference('language.rust.Command') || 'rustc';
export const getJavaCommand = (): string =>
Expand Down Expand Up @@ -145,6 +150,11 @@ export const getLanguageId = (srcPath: string): number => {
break;
}

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

case '.go': {
compiler = getPreference('language.go.SubmissionCompiler');
break;
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export type prefSection =
| 'language.python.Args'
| 'language.python.SubmissionCompiler'
| 'language.python.Command'
| 'language.ruby.Args'
| 'language.ruby.SubmissionCompiler'
| 'language.ruby.Command'
| 'language.haskell.Args'
| 'language.haskell.SubmissionCompiler'
| 'language.haskell.Command'
Expand All @@ -49,6 +52,7 @@ export type Language = {

export type LangNames =
| 'python'
| 'ruby'
| 'c'
| 'cpp'
| 'rust'
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getCArgsPref,
getCppArgsPref,
getPythonArgsPref,
getRubyArgsPref,
getRustArgsPref,
getJavaArgsPref,
getJsArgsPref,
Expand All @@ -18,6 +19,7 @@ import {
getCCommand,
getCppCommand,
getPythonCommand,
getRubyCommand,
getRustCommand,
getJavaCommand,
getJsCommand,
Expand Down Expand Up @@ -70,6 +72,14 @@ export const getLanguage = (srcPath: string): Language => {
skipCompile: true,
};
}
case 'ruby': {
return {
name: langName,
args: [...getRubyArgsPref()],
compiler: getRubyCommand(),
skipCompile: true,
};
}
case 'rust': {
return {
name: langName,
Expand Down

0 comments on commit d74f768

Please sign in to comment.