Skip to content

Commit

Permalink
Support for Haskell (hs, ghc)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNiklas committed Dec 9, 2023
1 parent 349cd00 commit c0e681a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ enter testcases.
- C
- Rust
- Go
- Haskell
- Python
- Java
- JavaScript (Node.js)
Expand Down
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,25 @@
"default": "go",
"description": "Command used to compile .go files."
},
"cph.language.haskell.Args": {
"title": "Compilation flags for .hs files",
"type": "string",
"default": "",
"description": "Space seperated additional flags passed to go while compiling your file."
},
"cph.language.haskell.SubmissionCompiler": {
"type": "string",
"default": "Haskell GHC 8.10.1",
"enum": [
"Haskell GHC 8.10.1"
],
"description": "The compiler chosen in the drop down during Codeforces submission for haskell"
},
"cph.language.haskell.Command": {
"type": "string",
"default": "ghc",
"description": "Command used to compile .hs files."
},
"cph.language.java.Args": {
"title": "Compilation flags for Java",
"type": "string",
Expand Down
11 changes: 11 additions & 0 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ const getFlags = (language: Language, srcPath: string): string[] => {
ret = [srcPath, '-d', binDir, ...args];
break;
}
case 'hs': {
ret = [
srcPath,
'-o',
getBinSaveLocation(srcPath),
'-outputdir',
'/tmp/ghc/',
...args,
];
break;
}
default: {
ret = [];
break;
Expand Down
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default {
java: 'java',
js: 'js',
go: 'go',
hs: 'hs',
},
compilers: {
c: 'gcc',
Expand All @@ -24,6 +25,7 @@ export default {
java: 'javac',
js: 'node',
go: 'go',
hs: 'hs',
},
compilerToId: {
'GNU G++17 7.3.0': 54,
Expand All @@ -45,7 +47,8 @@ export default {
'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'],
supportedExtensions: ['py', 'cpp', 'rs', 'c', 'java', 'js', 'go', 'hs'],
skipCompile: ['py', 'js'],
};
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 getHaskellArgsPref = (): string[] =>
getPreference('language.haskell.Args').split(' ') || [];

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

Expand Down Expand Up @@ -101,6 +104,8 @@ export const getJsCommand = (): string =>
getPreference('language.js.Command') || 'node';
export const getGoCommand = (): string =>
getPreference('language.go.Command') || 'go';
export const getHaskellCommand = (): string =>
getPreference('language.haskell.Command') || 'ghc';

export const getMenuChoices = (): string[] =>
getPreference('general.menuChoices').split(' ');
Expand Down Expand Up @@ -144,6 +149,11 @@ export const getLanguageId = (srcPath: string): number => {
compiler = getPreference('language.go.SubmissionCompiler');
break;
}

case '.hs': {
compiler = getPreference('language.haskell.SubmissionCompiler');
break;
}
}
if (compiler == null) return -1;
for (const [_compiler, id] of Object.entries(config.compilerToId)) {
Expand Down
13 changes: 12 additions & 1 deletion 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.haskell.Args'
| 'language.haskell.SubmissionCompiler'
| 'language.haskell.Command'
| 'general.retainWebviewContext'
| 'general.autoShowJudge'
| 'general.defaultLanguageTemplateFileLocation';
Expand All @@ -44,7 +47,15 @@ export type Language = {
skipCompile: boolean;
};

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

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 @@ -14,13 +14,15 @@ import {
getJavaArgsPref,
getJsArgsPref,
getGoArgsPref,
getHaskellArgsPref,
getCCommand,
getCppCommand,
getPythonCommand,
getRustCommand,
getJavaCommand,
getJsCommand,
getGoCommand,
getHaskellCommand,
} from './preferences';
import { Language, Problem } from './types';
import telmetry from './telmetry';
Expand Down Expand Up @@ -100,6 +102,14 @@ export const getLanguage = (srcPath: string): Language => {
skipCompile: false,
};
}
case 'hs': {
return {
name: langName,
args: [...getHaskellArgsPref()],
compiler: getHaskellCommand(),
skipCompile: false,
};
}
}
throw new Error('Invalid State');
};
Expand Down

0 comments on commit c0e681a

Please sign in to comment.