From 7965e97c9d678230a41c937c968b89690bdb364c Mon Sep 17 00:00:00 2001 From: Karan Yadav Date: Mon, 4 Mar 2024 01:40:36 +0530 Subject: [PATCH] added support for ruby --- README.md | 1 + package.json | 24 ++++++++++++++++++++++-- src/config.ts | 17 +++++++++++++++-- src/executions.ts | 8 ++++++++ src/preferences.ts | 10 ++++++++++ src/types.ts | 4 ++++ src/utils.ts | 10 ++++++++++ 7 files changed, 70 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ac99477..dcdc073 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ enter testcases. - Go - Haskell - Python +- Ruby - Java - JavaScript (Node.js) diff --git a/package.json b/package.json index c7d5525..33627aa 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/config.ts b/src/config.ts index 8d6c408..70161ac 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,6 +11,7 @@ export default { c: 'c', cpp: 'cpp', python: 'py', + ruby: 'rb', rust: 'rs', java: 'java', js: 'js', @@ -21,6 +22,7 @@ export default { c: 'gcc', cpp: 'g++', python: 'python', + ruby: 'ruby', rust: 'rustc', java: 'javac', js: 'node', @@ -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'], }; diff --git a/src/executions.ts b/src/executions.ts index 6068ca2..7b20fa4 100644 --- a/src/executions.ts +++ b/src/executions.ts @@ -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, diff --git a/src/preferences.ts b/src/preferences.ts index 4a04e97..4ff7503 100644 --- a/src/preferences.ts +++ b/src/preferences.ts @@ -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(' ') || []; @@ -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 => @@ -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; diff --git a/src/types.ts b/src/types.ts index f7c3ff2..533429c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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' @@ -49,6 +52,7 @@ export type Language = { export type LangNames = | 'python' + | 'ruby' | 'c' | 'cpp' | 'rust' diff --git a/src/utils.ts b/src/utils.ts index 5ce6b06..012078a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -10,6 +10,7 @@ import { getCArgsPref, getCppArgsPref, getPythonArgsPref, + getRubyArgsPref, getRustArgsPref, getJavaArgsPref, getJsArgsPref, @@ -18,6 +19,7 @@ import { getCCommand, getCppCommand, getPythonCommand, + getRubyCommand, getRustCommand, getJavaCommand, getJsCommand, @@ -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,