Skip to content

Commit 0f422a0

Browse files
Merge pull request #4235 from PowerShell/andschwa/settings
Refactor `settings.ts`
2 parents 5cae711 + 1046278 commit 0f422a0

18 files changed

+215
-319
lines changed

package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,15 @@
573573
},
574574
"powershell.powerShellAdditionalExePaths": {
575575
"type": "object",
576+
"default": {},
576577
"description": "Specifies a list of versionName / exePath pairs where exePath points to a non-standard install location for PowerShell and versionName can be used to reference this path with the powershell.powerShellDefaultVersion setting.",
577578
"additionalProperties": {
578579
"type": "string"
579580
}
580581
},
581582
"powershell.powerShellDefaultVersion": {
582583
"type": "string",
584+
"default": "",
583585
"description": "Specifies the PowerShell version name, as displayed by the 'PowerShell: Show Session Menu' command, used when the extension loads e.g \"Windows PowerShell (x86)\" or \"PowerShell Core 7 (x64)\". You can specify additional PowerShell executables by using the \"powershell.powerShellAdditionalExePaths\" setting."
584586
},
585587
"powershell.powerShellExePath": {
@@ -639,7 +641,8 @@
639641
"powershell.bugReporting.project": {
640642
"type": "string",
641643
"default": "https://github.com/PowerShell/vscode-powershell",
642-
"description": "Specifies the URL of the GitHub project in which to generate bug reports."
644+
"description": "Specifies the URL of the GitHub project in which to generate bug reports.",
645+
"deprecationMessage": "This setting was never meant to be changed!"
643646
},
644647
"powershell.helpCompletion": {
645648
"type": "string",
@@ -653,7 +656,7 @@
653656
},
654657
"powershell.cwd": {
655658
"type": "string",
656-
"default": null,
659+
"default": "",
657660
"description": "An explicit start path where the PowerShell Extension Terminal will be launched. Both the PowerShell process's and the shell's location will be set to this directory. A fully resolved path must be provided!"
658661
},
659662
"powershell.scriptAnalysis.enable": {
@@ -811,12 +814,13 @@
811814
},
812815
"powershell.integratedConsole.forceClearScrollbackBuffer": {
813816
"type": "boolean",
817+
"default": false,
814818
"description": "Use the vscode API to clear the terminal since that's the only reliable way to clear the scrollback buffer. Turn this on if you're used to 'Clear-Host' clearing scroll history as well as clear-terminal-via-lsp."
815819
},
816820
"powershell.integratedConsole.suppressStartupBanner": {
817821
"type": "boolean",
818822
"default": false,
819-
"description": "Do not show the Powershell Extension Terminal banner on launch"
823+
"description": "Do not show the PowerShell Extension Terminal banner on launch."
820824
},
821825
"powershell.debugging.createTemporaryIntegratedConsole": {
822826
"type": "boolean",
@@ -825,6 +829,7 @@
825829
},
826830
"powershell.developer.bundledModulesPath": {
827831
"type": "string",
832+
"default": "../../PowerShellEditorServices/module",
828833
"description": "Specifies an alternate path to the folder containing modules that are bundled with the PowerShell extension (i.e. PowerShell Editor Services, PSScriptAnalyzer, Plaster)"
829834
},
830835
"powershell.developer.editorServicesLogLevel": {

src/features/Console.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { NotificationType, RequestType } from "vscode-languageclient";
66
import { LanguageClient } from "vscode-languageclient/node";
77
import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/checkboxQuickPick";
88
import { Logger } from "../logging";
9-
import Settings = require("../settings");
9+
import { getSettings } from "../settings";
1010
import { LanguageClientConsumer } from "../languageClientConsumer";
1111

1212
export const EvaluateRequestType = new RequestType<IEvaluateRequestArguments, void, void>("evaluate");
@@ -182,7 +182,7 @@ export class ConsoleFeature extends LanguageClientConsumer {
182182
// We need to honor the focusConsoleOnExecute setting here too. However, the boolean that `show`
183183
// takes is called `preserveFocus` which when `true` the terminal will not take focus.
184184
// This is the inverse of focusConsoleOnExecute so we have to inverse the boolean.
185-
vscode.window.activeTerminal.show(!Settings.load().integratedConsole.focusConsoleOnExecute);
185+
vscode.window.activeTerminal.show(!getSettings().integratedConsole.focusConsoleOnExecute);
186186
await vscode.commands.executeCommand("workbench.action.terminal.scrollToBottom");
187187

188188
return;

src/features/DebugSession.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { LanguageClient } from "vscode-languageclient/node";
1111
import { getPlatformDetails, OperatingSystem } from "../platform";
1212
import { PowerShellProcess } from "../process";
1313
import { IEditorServicesSessionDetails, SessionManager, SessionStatus } from "../session";
14-
import Settings = require("../settings");
14+
import { getSettings } from "../settings";
1515
import { Logger } from "../logging";
1616
import { LanguageClientConsumer } from "../languageClientConsumer";
1717
import path = require("path");
@@ -169,7 +169,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
169169
// setting. Otherwise, the launch config value overrides the setting.
170170
//
171171
// Also start the temporary process and console for this configuration.
172-
const settings = Settings.load();
172+
const settings = getSettings();
173173
config.createTemporaryIntegratedConsole =
174174
config.createTemporaryIntegratedConsole ??
175175
settings.debugging.createTemporaryIntegratedConsole;

src/features/ExtensionCommands.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "vscode-languageclient";
1111
import { LanguageClient } from "vscode-languageclient/node";
1212
import { Logger } from "../logging";
13-
import Settings = require("../settings");
13+
import { getSettings } from "../settings";
1414
import { LanguageClientConsumer } from "../languageClientConsumer";
1515

1616
export interface IExtensionCommand {
@@ -260,7 +260,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
260260
() => {
261261
// We check to see if they have TrueClear on. If not, no-op because the
262262
// overriden Clear-Host already calls [System.Console]::Clear()
263-
if (Settings.load().integratedConsole.forceClearScrollbackBuffer) {
263+
if (getSettings().integratedConsole.forceClearScrollbackBuffer) {
264264
void vscode.commands.executeCommand("workbench.action.terminal.clear");
265265
}
266266
})

src/features/GenerateBugReport.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import os = require("os");
55
import vscode = require("vscode");
66
import child_process = require("child_process");
77
import { SessionManager } from "../session";
8-
import Settings = require("../settings");
98

109
const queryStringPrefix = "?";
1110

12-
const settings = Settings.load();
13-
const project = settings.bugReporting.project;
11+
const project = "https://github.com/PowerShell/vscode-powershell";
1412
const issuesUrl = `${project}/issues/new`;
1513

1614
const extensions =

src/features/GetCommands.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { RequestType0 } from "vscode-languageclient";
66
import { LanguageClient } from "vscode-languageclient/node";
77
import { Logger } from "../logging";
88
import { LanguageClientConsumer } from "../languageClientConsumer";
9+
import { getSettings } from "../settings";
910

1011
interface ICommand {
1112
name: string;
@@ -68,8 +69,8 @@ export class GetCommandsFeature extends LanguageClientConsumer {
6869
return;
6970
}
7071
await this.languageClient.sendRequest(GetCommandRequestType).then((result) => {
71-
const SidebarConfig = vscode.workspace.getConfiguration("powershell.sideBar");
72-
const excludeFilter = (SidebarConfig.CommandExplorerExcludeFilter).map((filter: string) => filter.toLowerCase());
72+
const exclusions = getSettings().sideBar.CommandExplorerExcludeFilter;
73+
const excludeFilter = exclusions.map((filter: string) => filter.toLowerCase());
7374
result = result.filter((command) => (excludeFilter.indexOf(command.moduleName.toLowerCase()) === -1));
7475
this.commandsExplorerProvider.powerShellCommands = result.map(toCommand);
7576
this.commandsExplorerProvider.refresh();

src/features/HelpCompletion.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "vscode";
88
import { RequestType } from "vscode-languageclient";
99
import { LanguageClient } from "vscode-languageclient/node";
10-
import Settings = require("../settings");
10+
import { Settings, CommentType, getSettings } from "../settings";
1111
import { LanguageClientConsumer } from "../languageClientConsumer";
1212

1313
// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -27,13 +27,13 @@ enum SearchState { Searching, Locked, Found }
2727
export class HelpCompletionFeature extends LanguageClientConsumer {
2828
private helpCompletionProvider: HelpCompletionProvider | undefined;
2929
private disposable: Disposable | undefined;
30-
private settings: Settings.ISettings;
30+
private settings: Settings;
3131

3232
constructor() {
3333
super();
34-
this.settings = Settings.load();
34+
this.settings = getSettings();
3535

36-
if (this.settings.helpCompletion !== Settings.CommentType.Disabled) {
36+
if (this.settings.helpCompletion !== CommentType.Disabled) {
3737
this.helpCompletionProvider = new HelpCompletionProvider();
3838
this.disposable = workspace.onDidChangeTextDocument(async (e) => { await this.onEvent(e); });
3939
}
@@ -125,11 +125,11 @@ class HelpCompletionProvider {
125125
private lastChangeRange: Range | undefined;
126126
private lastDocument: TextDocument | undefined;
127127
private langClient: LanguageClient | undefined;
128-
private settings: Settings.ISettings;
128+
private settings: Settings;
129129

130130
constructor() {
131131
this.triggerFinderHelpComment = new TriggerFinder("##");
132-
this.settings = Settings.load();
132+
this.settings = getSettings();
133133
}
134134

135135
public get triggerFound(): boolean {
@@ -161,7 +161,7 @@ class HelpCompletionProvider {
161161
const result = await this.langClient.sendRequest(CommentHelpRequestType, {
162162
documentUri: doc.uri.toString(),
163163
triggerPosition: triggerStartPos,
164-
blockComment: this.settings.helpCompletion === Settings.CommentType.BlockComment,
164+
blockComment: this.settings.helpCompletion === CommentType.BlockComment,
165165
});
166166

167167
if (result.content.length === 0) {

src/features/ISECompatibility.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT License.
33

44
import * as vscode from "vscode";
5-
import * as Settings from "../settings";
5+
import { getSettings } from "../settings";
66

77
interface ISetting {
88
path: string;
@@ -63,7 +63,7 @@ export class ISECompatibilityFeature implements vscode.Disposable {
6363
// Show the PowerShell view container which has the Command Explorer view
6464
await vscode.commands.executeCommand("workbench.view.extension.PowerShell");
6565

66-
if (!Settings.load().sideBar.CommandExplorerVisibility) {
66+
if (!getSettings().sideBar.CommandExplorerVisibility) {
6767
// Hide the explorer if the setting says so.
6868
await vscode.commands.executeCommand("workbench.action.toggleSidebarVisibility");
6969
}

src/features/PesterTests.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as path from "path";
55
import vscode = require("vscode");
66
import { SessionManager } from "../session";
7-
import Settings = require("../settings");
7+
import { getSettings } from "../settings";
88
import utils = require("../utils");
99

1010
enum LaunchType {
@@ -83,7 +83,7 @@ export class PesterTestsFeature implements vscode.Disposable {
8383
lineNum?: number,
8484
outputPath?: string): vscode.DebugConfiguration {
8585

86-
const settings = Settings.load();
86+
const settings = getSettings();
8787

8888
// Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
8989
// special chars like & $ @ () [], we do have to double up the interior single quotes.

src/features/RunCode.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import vscode = require("vscode");
55
import { SessionManager } from "../session";
6-
import Settings = require("../settings");
6+
import { getSettings } from "../settings";
77

88
enum LaunchType {
99
Debug,
@@ -46,7 +46,7 @@ export class RunCodeFeature implements vscode.Disposable {
4646
}
4747

4848
function createLaunchConfig(launchType: LaunchType, commandToRun: string, args: string[]) {
49-
const settings = Settings.load();
49+
const settings = getSettings();
5050

5151
const launchConfig = {
5252
request: "launch",

src/features/UpdatePowerShell.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { MessageItem, ProgressLocation, window } from "vscode";
1414
import { LanguageClient } from "vscode-languageclient/node";
1515
import { Logger } from "../logging";
1616
import { SessionManager } from "../session";
17-
import * as Settings from "../settings";
17+
import { changeSetting } from "../settings";
1818
import { isMacOS, isWindows } from "../utils";
1919
import { EvaluateRequestType } from "./Console";
2020

@@ -195,7 +195,7 @@ export async function InvokePowerShellUpdateCheck(
195195

196196
// Never choice.
197197
case 2:
198-
await Settings.change("promptToUpdatePowerShell", false, true, logger);
198+
await changeSetting("promptToUpdatePowerShell", false, true, logger);
199199
break;
200200
default:
201201
break;

src/main.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { ShowHelpFeature } from "./features/ShowHelp";
2626
import { SpecifyScriptArgsFeature } from "./features/DebugSession";
2727
import { Logger } from "./logging";
2828
import { SessionManager } from "./session";
29-
import Settings = require("./settings");
29+
import { LogLevel, getSettings, validateCwdSetting } from "./settings";
3030
import { PowerShellLanguageId } from "./utils";
3131
import { LanguageClientConsumer } from "./languageClientConsumer";
3232

@@ -51,7 +51,7 @@ const documentSelector: DocumentSelector = [
5151

5252
export async function activate(context: vscode.ExtensionContext): Promise<IPowerShellExtensionClient> {
5353
const logLevel = vscode.workspace.getConfiguration(`${PowerShellLanguageId}.developer`)
54-
.get<string>("editorServicesLogLevel", "Normal");
54+
.get<string>("editorServicesLogLevel", LogLevel.Normal);
5555
logger = new Logger(logLevel, context.globalStorageUri);
5656

5757
telemetryReporter = new TelemetryReporter(PackageJSON.name, PackageJSON.version, AI_KEY);
@@ -65,8 +65,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
6565
}
6666

6767
// Load and validate settings (will prompt for 'cwd' if necessary).
68-
await Settings.validateCwdSetting(logger);
69-
const settings = Settings.load();
68+
await validateCwdSetting(logger);
69+
const settings = getSettings();
7070
logger.writeDiagnostic(`Loaded settings:\n${JSON.stringify(settings, undefined, 2)}`);
7171

7272
languageConfigurationDisposable = vscode.languages.setLanguageConfiguration(

src/platform.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as os from "os";
55
import * as path from "path";
66
import * as process from "process";
77
import { integer } from "vscode-languageserver-protocol";
8-
import { IPowerShellAdditionalExePathSettings } from "./settings";
8+
import { PowerShellAdditionalExePathSettings } from "./settings";
99

1010
// This uses require so we can rewire it in unit tests!
1111
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-var-requires
@@ -79,7 +79,7 @@ export class PowerShellExeFinder {
7979
private readonly platformDetails: IPlatformDetails;
8080

8181
// Additional configured PowerShells
82-
private readonly additionalPSExeSettings: IPowerShellAdditionalExePathSettings;
82+
private readonly additionalPSExeSettings: PowerShellAdditionalExePathSettings;
8383

8484
private winPS: IPossiblePowerShellExe | undefined;
8585

@@ -92,7 +92,7 @@ export class PowerShellExeFinder {
9292
*/
9393
constructor(
9494
platformDetails?: IPlatformDetails,
95-
additionalPowerShellExes?: IPowerShellAdditionalExePathSettings) {
95+
additionalPowerShellExes?: PowerShellAdditionalExePathSettings) {
9696

9797
this.platformDetails = platformDetails ?? getPlatformDetails();
9898
this.additionalPSExeSettings = additionalPowerShellExes ?? {};

src/process.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class PowerShellProcess {
3131
private logger: Logger,
3232
private startPsesArgs: string,
3333
private sessionFilePath: vscode.Uri,
34-
private sessionSettings: Settings.ISettings) {
34+
private sessionSettings: Settings.Settings) {
3535

3636
this.onExited = this.onExitedEmitter.event;
3737
}
@@ -46,7 +46,7 @@ export class PowerShellProcess {
4646
"PowerShellEditorServices/PowerShellEditorServices.psd1");
4747

4848
const featureFlags =
49-
this.sessionSettings.developer.featureFlags !== undefined
49+
this.sessionSettings.developer.featureFlags.length > 0
5050
? this.sessionSettings.developer.featureFlags.map((f) => `'${f}'`).join(", ")
5151
: "";
5252

0 commit comments

Comments
 (0)