Skip to content

Commit

Permalink
Merge pull request #6 from Release-Candidate/feature-make-repl-start-…
Browse files Browse the repository at this point in the history
…delay-configurable

Make delay after starting the terminal configurable, add popup on configuration changes
  • Loading branch information
Release-Candidate authored Jun 26, 2023
2 parents d109c09 + 3a7d7da commit 1416c97
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Chez Scheme REPL for Visual Studio Code Changelog

## Version 0.4.0 (2023-06-26)

- Make the delay between starting the terminal for the interactive REPL and sending data to this terminal configurable. Configuration value `chezScheme.replDelay`. See [#5](https://github.com/Release-Candidate/vscode-scheme-repl/issues/5).
- If the extension's configuration has changed, pop up a window asking the user to reload the extension to activate the changes.

## Version 0.3.0 (2023-06-26)

### Bugfixes
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ The following list of extensions is recognized as a Chez Scheme source file:
## Configuration

- `chezScheme.schemePath` - Path to the Chez Scheme executable `scheme`. Can be either an absolute path or relative to the workspace root. Default: `scheme`, which works if `scheme` is in your `PATH`.
- `chezScheme.replDelay` - The delay in milliseconds `ms` to wait after starting a terminal for the interactive REPL until sending sources to it. Default: 1000ms, 1s.
- `chezScheme.waiterPrompt` - The string to display as an interactive REPL prompt. Default: `λ>`.

## VS Code Scheme specific configuration
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-scheme-repl",
"displayName": "Chez Scheme REPL",
"version": "0.3.0",
"version": "0.4.0",
"preview": false,
"publisher": "release-candidate",
"description": "Support for Chez Scheme: Highlighting, autocompletion, documentation on hover and syntax checks.",
Expand Down Expand Up @@ -222,6 +222,11 @@
"default": "scheme",
"markdownDescription": "Path to the Chez Scheme executable `scheme`. Can be either an absolute path or relative to the workspace root. Default: `scheme`, which works if `scheme` is in your `PATH`."
},
"chezScheme.replDelay": {
"type": "integer",
"default": 1000,
"markdownDescription": "The delay in milliseconds `ms` to wait after starting a terminal for the interactive REPL until sending sources to it. Default: 1000ms, 1s."
},
"chezScheme.waiterPrompt": {
"type": "string",
"default": "λ>",
Expand Down
26 changes: 24 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,41 @@ export const cfgREPLPath = "schemePath";
*/
export const cfgREPLDefaultPath = replCommand;

/**
* The configuration key for the REPL start delay.
*/
export const cfgREPLDelay = "replDelay";

/**
* The default value of `cfgREPLDelay`.
*/
export const cfgREPLDefaultDelay = replSleepTime;

/**
* Return the configuration value for `replDelay`.
* @param config The configuration object to use.
* @returns The configuration value for `replDelay`.
*/
export function getCfgREPLDelay(config: vscode.WorkspaceConfiguration): number {
return config.get<number>(cfgREPLDelay) || cfgREPLDefaultDelay;
}

/**
* The string to use as the Chez REPL prompt.
*/
export const cfgREPLPrompt = "waiterPrompt";

/**
* The default value of `cfgREPLPrompt`.
*/
export const cfgREPLDefaultPrompt = replPrompt;

/**
* Return the configuration value for `schemePath`.
* @param config The configuration object to use.
* @returns The configuration value for `schemePath`.
*/
export function getCfgREPLPath(config: vscode.WorkspaceConfiguration) {
export function getCfgREPLPath(config: vscode.WorkspaceConfiguration): string {
return config.get<string>(cfgREPLPath) || cfgREPLDefaultPath;
}

Expand All @@ -230,7 +252,7 @@ export function getCfgREPLPath(config: vscode.WorkspaceConfiguration) {
*/
export function getCfgREPLPromptFunction(
config: vscode.WorkspaceConfiguration
) {
): string {
const promptString =
config.get<string>(cfgREPLPrompt) || cfgREPLDefaultPrompt;
return setREPLPrompt(promptString);
Expand Down
26 changes: 26 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function activate(context: vscode.ExtensionContext) {
* Setup the extension.
* @param env The extension's environment.
*/
// eslint-disable-next-line max-statements
async function setupExtension(env: h.Env) {
const editorChangedSubscription = vscode.window.onDidChangeActiveTextEditor(
(editor) => {
Expand All @@ -74,6 +75,11 @@ async function setupExtension(env: h.Env) {

subscribeOnSave(env);

const configSubscription = vscode.workspace.onDidChangeConfiguration((e) =>
configChanged(env, e)
);
env.context.subscriptions.push(configSubscription);

const symbolSubscription = vscode.languages.registerDocumentSymbolProvider(
c.languageName,
{ provideDocumentSymbols }
Expand Down Expand Up @@ -286,3 +292,23 @@ function registerTextEditorCommand(
);
env.context.subscriptions.push(subscription);
}

/**
* Called, if the configuration has changed.
* @param env The extension's environment.
* @param e The change event.
*/
function configChanged(env: h.Env, e: vscode.ConfigurationChangeEvent) {
if (e.affectsConfiguration(c.cfgSection)) {
env.outChannel.appendLine(`Config changed!`);
vscode.window
.showInformationMessage(
"The configuration has changed!\nReload the window for the changes to take effect.",
"Reload Now"
)
// eslint-disable-next-line no-unused-vars
.then((_) =>
vscode.commands.executeCommand("workbench.action.reloadWindow")
);
}
}
2 changes: 1 addition & 1 deletion src/paneREPL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export async function createREPL(
location: { viewColumn: vscode.ViewColumn.Beside, preserveFocus: true },
});
terminal.sendText(`${c.getCfgREPLPath(config)}`);
await help.sleep(c.replSleepTime);
await help.sleep(c.getCfgREPLDelay(config));
terminal.sendText(`${c.getCfgREPLPromptFunction(config)}`);
return terminal;
}

0 comments on commit 1416c97

Please sign in to comment.