-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VSC: add runner state object and integrate VS Code user configuration
- Loading branch information
Showing
6 changed files
with
151 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
build/ | ||
target/ | ||
|
||
examples/ | ||
|
||
*.md | ||
*.svg | ||
|
||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024 Jack Bennett. | ||
* All Rights Reserved. | ||
* | ||
* See the LICENCE file for more information. | ||
*/ | ||
|
||
import { Runner } from "./runner"; | ||
import * as userConfig from "./userConfig"; | ||
|
||
/** | ||
* A state object from which multiple command runners can be created to use shared configuration. | ||
*/ | ||
export class RunnerState { | ||
/** | ||
* Path to `devinit` - may just be the term 'devinit' itself, if we are using PATH. | ||
*/ | ||
private execPath!: string; | ||
|
||
/** | ||
* Path to the `devinitrc.yml` config file to read, or undefined to use system defaults | ||
*/ | ||
private configPath: string | undefined; | ||
|
||
/** | ||
* Initialise the runner state object | ||
*/ | ||
public constructor() { | ||
this.updateUserConfigProperties(); | ||
} | ||
|
||
/** | ||
* Update the properties in the runner state which are based on the user's VS Code configuration. | ||
* This should be done when config changes (via listening to `vscode.workspace.onDidChangeConfiguration()`) | ||
*/ | ||
public updateUserConfigProperties() { | ||
let execPath = userConfig.getExecutablePath(); | ||
this.execPath = (execPath.length > 0) ? execPath : "devinit"; | ||
|
||
let configPath = userConfig.getConfigPath(); | ||
this.configPath = (configPath.length > 0) ? configPath : undefined; | ||
} | ||
|
||
/** | ||
* Build a Runner object from the shared configuration in this state object. | ||
* @returns New command runner instance | ||
*/ | ||
public buildRunner(): Runner { | ||
let runner = new Runner() | ||
.setExecPath(this.execPath); | ||
|
||
if (this.configPath !== undefined) { | ||
runner.setConfigPath(this.configPath); | ||
} | ||
|
||
return runner; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright (c) 2024 Jack Bennett. | ||
* All Rights Reserved. | ||
* | ||
* See the LICENCE file for more information. | ||
*/ | ||
|
||
import * as vscode from "vscode"; | ||
|
||
export function getExecutablePath(): string { | ||
return getConfig().get<string>("devinit.environment.executablePath")!; | ||
} | ||
|
||
export function getConfigPath(): string { | ||
return getConfig().get<string>("devinit.environment.configurationFile")!; | ||
} | ||
|
||
function getConfig() { | ||
return vscode.workspace.getConfiguration(); | ||
} |