Skip to content

Commit

Permalink
Changed warning when using .mirrord config folder to info. closes #29 (
Browse files Browse the repository at this point in the history
…#87)

* Changed warning when using .mirrord config folder to info.

* Improve messages. // Rename confusing var. // Remove duplicated else if/else clause.

* No notification when running without config file.

* Add new prompt to disable using env var config.

* Notify we're using a default config.

* docs for no config specified

Co-authored-by: t4lz <[email protected]>

* Info only when single file.

* new specific action

* better message

Co-authored-by: t4lz <[email protected]>

* remove unused import

* changelog

---------

Co-authored-by: t4lz <[email protected]>
  • Loading branch information
meowjesty and t4lz authored Jan 3, 2024
1 parent 870152e commit c02cae4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions changelog.d/29.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed notifications when loading config file to be less confusing.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,21 @@
"default": true,
"description": "Show a notification when mirrord uses active configuration."
},
"mirrord.promptUsingEnvVarConfig": {
"type": "boolean",
"default": true,
"description": "Show a notification when mirrord uses env var configuration."
},
"mirrord.promptUsingDefaultConfig": {
"type": "boolean",
"default": true,
"description": "Show a notification when mirrord uses default configuration."
},
"mirrord.promptUsingDefaultConfigSingleFileNoFolder": {
"type": "boolean",
"default": true,
"description": "Show a notification when mirrord uses default configuration when running vscode with a single file (no folder)."
},
"mirrord.promptTargetless": {
"type": "boolean",
"default": true,
Expand Down
53 changes: 30 additions & 23 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,43 +296,50 @@ export class MirrordConfigManager {
if (this.active) {
// User has selected a config (via active config button).
new NotificationBuilder()
.withMessage("using active mirrord configuration")
.withMessage("Using active mirrord configuration.")
.withOpenFileAction(this.active)
.withDisableAction("promptUsingActiveConfig")
.info();

return this.active;
} else if (config.env?.["MIRRORD_CONFIG_FILE"]) {
// Get the config path from the env var.
return vscode.Uri.parse(`file://${config.env?.["MIRRORD_CONFIG_FILE"]}`, true);
const configFromEnv = vscode.Uri.parse(`file://${config.env?.["MIRRORD_CONFIG_FILE"]}`, true);

new NotificationBuilder()
.withMessage(`Using mirrord configuration from env var "MIRRORD_CONFIG_FILE".`)
.withOpenFileAction(configFromEnv)
.withDisableAction("promptUsingEnvVarConfig")
.info();

return configFromEnv;

} else if (folder) {
let predefinedConfig = await MirrordConfigManager.getDefaultConfig(folder);
if (predefinedConfig) {
const configFromMirrordFolder = await MirrordConfigManager.getDefaultConfig(folder);

if (configFromMirrordFolder) {
new NotificationBuilder()
.withMessage("using a default mirrord config")
.withOpenFileAction(predefinedConfig)
.withMessage(`Using mirrord configuration from ".mirrord" folder.`)
.withOpenFileAction(configFromMirrordFolder)
.withDisableAction("promptUsingDefaultConfig")
.warning();
return predefinedConfig;
.info();

return configFromMirrordFolder;
} else {
// There is no configuration file in a .mirrord directory and no configuration file was specified
// via "active configuration" extension setting or environment variable. This is a valid case.
// mirrord will run without a configuration file.
return null;
}
} else {
folder = vscode.workspace.workspaceFolders?.[0];
if (!folder) {
throw new Error("mirrord requires an open folder in the workspace");
}
// User probably openend vscode in a single file, no folder is loaded and they have
// not set up the `MIRRORD_CONFIG_FILE` env var.
new NotificationBuilder()
.withMessage(`No folder open in editor - so not using a configuration file even if one exists.`)
.withDisableAction("promptUsingDefaultConfigSingleFileNoFolder")
.info();

let predefinedConfig = await MirrordConfigManager.getDefaultConfig(folder);
if (predefinedConfig) {
new NotificationBuilder()
.withMessage(`using a default mirrord config from folder ${folder.name} `)
.withOpenFileAction(predefinedConfig)
.withDisableAction("promptUsingDefaultConfig")
.warning();
return predefinedConfig;
} else {
return null;
}
return null;
}
}
}
4 changes: 2 additions & 2 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ async function main(
let cliPath = await getMirrordBinary(false);

if (!cliPath) {
mirrordFailure(`Couldn't download mirrord binaries or find local one in path`);
return null;
mirrordFailure(`Couldn't download mirrord binaries or find local one in path`);
return null;
}

let mirrordApi = new MirrordAPI(cliPath);
Expand Down

0 comments on commit c02cae4

Please sign in to comment.