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

Repl command suffix #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Since around GHC 8, the compiler GHC and its interactive REPL GHCi has gained va

Change the options in workspace settings instead of user settings if you want to apply the settings to a workspace locally.

- `ghcSimple.commandSuffix`: REPL command suffix

Arbitrary string appended to the REPL command line (e.g. `ghci`, `cabal new-repl`, `stack ghci`).

- `ghcSimple.useObjectCode`: Speed up GHCi reloads using `-fobject-code`

Enabled by default. Load everything with `-fobject-code` first before loading needed files with `-fbyte-code`. This way only changed files need to be recompiled, which greatly speeds up GHCi on large projects.
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
"ghcSimple.workspaceType": {
"type": "string",
"default": "detect",
"description": "Workspace type, 'bare' means use GHCi directly",
"scope": "resource",
"description": "Workspace type, 'bare' means use GHCi directly",
"enum": [
"detect",
"stack",
Expand All @@ -112,6 +112,12 @@
"bare"
]
},
"ghcSimple.commandSuffix": {
"type": "string",
"default": "",
"scope": "resource",
"description": "Arbitrary string appended to REPL command"
},
"ghcSimple.startupCommands.all": {
"type": "array",
"items": {
Expand Down
15 changes: 13 additions & 2 deletions src/extension-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ function getWorkspaceType(ext: ExtensionState, folder: vscode.WorkspaceFolder):
return ext.workspaceTypeMap.get(folder);
}

function splitArgs(argStr: string): string[] {
if (argStr === "") return [];
else return argStr.split(" ");
}

export async function startSession(ext: ExtensionState, doc: vscode.TextDocument): Promise<Session> {
const folder = vscode.workspace.getWorkspaceFolder(doc.uri);
const type = folder === undefined
Expand All @@ -27,16 +32,22 @@ export async function startSession(ext: ExtensionState, doc: vscode.TextDocument
const session = (() => {
if (-1 !== ['stack', 'cabal', 'cabal new', 'cabal v2'].indexOf(type)) {
// stack or cabal
const cmdSuffix =
vscode.workspace.getConfiguration('ghcSimple', folder.uri).commandSuffix;

if (! ext.workspaceManagers.has(folder))
ext.workspaceManagers.set(folder, new Session(ext, type, 'workspace', folder.uri));
ext.workspaceManagers.set(folder,
new Session(ext, type, splitArgs(cmdSuffix), 'workspace', folder.uri));

return ext.workspaceManagers.get(folder);
} else {
// bare or bare-stack
const cmdSuffix =
vscode.workspace.getConfiguration('ghcSimple', doc.uri).commandSuffix;

if (! ext.documentManagers.has(doc))
ext.documentManagers.set(doc, new Session(ext, type, 'file', doc.uri));
ext.documentManagers.set(doc,
new Session(ext, type, splitArgs(cmdSuffix), 'file', doc.uri));

return ext.documentManagers.get(doc);
}
Expand Down
5 changes: 5 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class Session implements vscode.Disposable {
constructor(
public ext: ExtensionState,
public workspaceType: HaskellWorkspaceType,
public cmdSuffix: string[],
public resourceType: 'workspace' | 'file',
public resource: vscode.Uri) {
this.ghci = null;
Expand Down Expand Up @@ -54,6 +55,10 @@ export class Session implements vscode.Disposable {
return ['ghci'];
})();

for (const arg of this.cmdSuffix) {
cmd.push(arg);
}

this.ext.outputChannel.appendLine(`Starting GHCi with: ${JSON.stringify(cmd)}`);
this.ext.outputChannel.appendLine(
`(Under ${
Expand Down