Skip to content

Refactor settings.ts #4235

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

Merged
merged 9 commits into from
Nov 3, 2022
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,15 @@
},
"powershell.powerShellAdditionalExePaths": {
"type": "object",
"default": {},
"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.",
"additionalProperties": {
"type": "string"
}
},
"powershell.powerShellDefaultVersion": {
"type": "string",
"default": "",
"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."
},
"powershell.powerShellExePath": {
Expand Down Expand Up @@ -639,7 +641,8 @@
"powershell.bugReporting.project": {
"type": "string",
"default": "https://github.com/PowerShell/vscode-powershell",
"description": "Specifies the URL of the GitHub project in which to generate bug reports."
"description": "Specifies the URL of the GitHub project in which to generate bug reports.",
"deprecationMessage": "This setting was never meant to be changed!"
},
"powershell.helpCompletion": {
"type": "string",
Expand All @@ -653,7 +656,7 @@
},
"powershell.cwd": {
"type": "string",
"default": null,
"default": "",
"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!"
},
"powershell.scriptAnalysis.enable": {
Expand Down Expand Up @@ -811,12 +814,13 @@
},
"powershell.integratedConsole.forceClearScrollbackBuffer": {
"type": "boolean",
"default": false,
"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."
},
"powershell.integratedConsole.suppressStartupBanner": {
"type": "boolean",
"default": false,
"description": "Do not show the Powershell Extension Terminal banner on launch"
"description": "Do not show the PowerShell Extension Terminal banner on launch."
},
"powershell.debugging.createTemporaryIntegratedConsole": {
"type": "boolean",
Expand All @@ -825,6 +829,7 @@
},
"powershell.developer.bundledModulesPath": {
"type": "string",
"default": "../../PowerShellEditorServices/module",
"description": "Specifies an alternate path to the folder containing modules that are bundled with the PowerShell extension (i.e. PowerShell Editor Services, PSScriptAnalyzer, Plaster)"
},
"powershell.developer.editorServicesLogLevel": {
Expand Down
4 changes: 2 additions & 2 deletions src/features/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NotificationType, RequestType } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import { ICheckboxQuickPickItem, showCheckboxQuickPick } from "../controls/checkboxQuickPick";
import { Logger } from "../logging";
import Settings = require("../settings");
import { getSettings } from "../settings";
import { LanguageClientConsumer } from "../languageClientConsumer";

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

return;
Expand Down
4 changes: 2 additions & 2 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { LanguageClient } from "vscode-languageclient/node";
import { getPlatformDetails, OperatingSystem } from "../platform";
import { PowerShellProcess } from "../process";
import { IEditorServicesSessionDetails, SessionManager, SessionStatus } from "../session";
import Settings = require("../settings");
import { getSettings } from "../settings";
import { Logger } from "../logging";
import { LanguageClientConsumer } from "../languageClientConsumer";
import path = require("path");
Expand Down Expand Up @@ -169,7 +169,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
// setting. Otherwise, the launch config value overrides the setting.
//
// Also start the temporary process and console for this configuration.
const settings = Settings.load();
const settings = getSettings();
config.createTemporaryIntegratedConsole =
config.createTemporaryIntegratedConsole ??
settings.debugging.createTemporaryIntegratedConsole;
Expand Down
4 changes: 2 additions & 2 deletions src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import { Logger } from "../logging";
import Settings = require("../settings");
import { getSettings } from "../settings";
import { LanguageClientConsumer } from "../languageClientConsumer";

export interface IExtensionCommand {
Expand Down Expand Up @@ -260,7 +260,7 @@ export class ExtensionCommandsFeature extends LanguageClientConsumer {
() => {
// We check to see if they have TrueClear on. If not, no-op because the
// overriden Clear-Host already calls [System.Console]::Clear()
if (Settings.load().integratedConsole.forceClearScrollbackBuffer) {
if (getSettings().integratedConsole.forceClearScrollbackBuffer) {
void vscode.commands.executeCommand("workbench.action.terminal.clear");
}
})
Expand Down
4 changes: 1 addition & 3 deletions src/features/GenerateBugReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import os = require("os");
import vscode = require("vscode");
import child_process = require("child_process");
import { SessionManager } from "../session";
import Settings = require("../settings");

const queryStringPrefix = "?";

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

const extensions =
Expand Down
5 changes: 3 additions & 2 deletions src/features/GetCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RequestType0 } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import { Logger } from "../logging";
import { LanguageClientConsumer } from "../languageClientConsumer";
import { getSettings } from "../settings";

interface ICommand {
name: string;
Expand Down Expand Up @@ -68,8 +69,8 @@ export class GetCommandsFeature extends LanguageClientConsumer {
return;
}
await this.languageClient.sendRequest(GetCommandRequestType).then((result) => {
const SidebarConfig = vscode.workspace.getConfiguration("powershell.sideBar");
const excludeFilter = (SidebarConfig.CommandExplorerExcludeFilter).map((filter: string) => filter.toLowerCase());
const exclusions = getSettings().sideBar.CommandExplorerExcludeFilter;
const excludeFilter = exclusions.map((filter: string) => filter.toLowerCase());
result = result.filter((command) => (excludeFilter.indexOf(command.moduleName.toLowerCase()) === -1));
this.commandsExplorerProvider.powerShellCommands = result.map(toCommand);
this.commandsExplorerProvider.refresh();
Expand Down
14 changes: 7 additions & 7 deletions src/features/HelpCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from "vscode";
import { RequestType } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import Settings = require("../settings");
import { Settings, CommentType, getSettings } from "../settings";
import { LanguageClientConsumer } from "../languageClientConsumer";

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

constructor() {
super();
this.settings = Settings.load();
this.settings = getSettings();

if (this.settings.helpCompletion !== Settings.CommentType.Disabled) {
if (this.settings.helpCompletion !== CommentType.Disabled) {
this.helpCompletionProvider = new HelpCompletionProvider();
this.disposable = workspace.onDidChangeTextDocument(async (e) => { await this.onEvent(e); });
}
Expand Down Expand Up @@ -125,11 +125,11 @@ class HelpCompletionProvider {
private lastChangeRange: Range | undefined;
private lastDocument: TextDocument | undefined;
private langClient: LanguageClient | undefined;
private settings: Settings.ISettings;
private settings: Settings;

constructor() {
this.triggerFinderHelpComment = new TriggerFinder("##");
this.settings = Settings.load();
this.settings = getSettings();
}

public get triggerFound(): boolean {
Expand Down Expand Up @@ -161,7 +161,7 @@ class HelpCompletionProvider {
const result = await this.langClient.sendRequest(CommentHelpRequestType, {
documentUri: doc.uri.toString(),
triggerPosition: triggerStartPos,
blockComment: this.settings.helpCompletion === Settings.CommentType.BlockComment,
blockComment: this.settings.helpCompletion === CommentType.BlockComment,
});

if (result.content.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/features/ISECompatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as vscode from "vscode";
import * as Settings from "../settings";
import { getSettings } from "../settings";

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

if (!Settings.load().sideBar.CommandExplorerVisibility) {
if (!getSettings().sideBar.CommandExplorerVisibility) {
// Hide the explorer if the setting says so.
await vscode.commands.executeCommand("workbench.action.toggleSidebarVisibility");
}
Expand Down
4 changes: 2 additions & 2 deletions src/features/PesterTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as path from "path";
import vscode = require("vscode");
import { SessionManager } from "../session";
import Settings = require("../settings");
import { getSettings } from "../settings";
import utils = require("../utils");

enum LaunchType {
Expand Down Expand Up @@ -83,7 +83,7 @@ export class PesterTestsFeature implements vscode.Disposable {
lineNum?: number,
outputPath?: string): vscode.DebugConfiguration {

const settings = Settings.load();
const settings = getSettings();

// Since we pass the script path to PSES in single quotes to avoid issues with PowerShell
// special chars like & $ @ () [], we do have to double up the interior single quotes.
Expand Down
4 changes: 2 additions & 2 deletions src/features/RunCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import vscode = require("vscode");
import { SessionManager } from "../session";
import Settings = require("../settings");
import { getSettings } from "../settings";

enum LaunchType {
Debug,
Expand Down Expand Up @@ -46,7 +46,7 @@ export class RunCodeFeature implements vscode.Disposable {
}

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

const launchConfig = {
request: "launch",
Expand Down
4 changes: 2 additions & 2 deletions src/features/UpdatePowerShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MessageItem, ProgressLocation, window } from "vscode";
import { LanguageClient } from "vscode-languageclient/node";
import { Logger } from "../logging";
import { SessionManager } from "../session";
import * as Settings from "../settings";
import { changeSetting } from "../settings";
import { isMacOS, isWindows } from "../utils";
import { EvaluateRequestType } from "./Console";

Expand Down Expand Up @@ -195,7 +195,7 @@ export async function InvokePowerShellUpdateCheck(

// Never choice.
case 2:
await Settings.change("promptToUpdatePowerShell", false, true, logger);
await changeSetting("promptToUpdatePowerShell", false, true, logger);
break;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ShowHelpFeature } from "./features/ShowHelp";
import { SpecifyScriptArgsFeature } from "./features/DebugSession";
import { Logger } from "./logging";
import { SessionManager } from "./session";
import Settings = require("./settings");
import { LogLevel, getSettings, validateCwdSetting } from "./settings";
import { PowerShellLanguageId } from "./utils";
import { LanguageClientConsumer } from "./languageClientConsumer";

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

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

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

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

languageConfigurationDisposable = vscode.languages.setLanguageConfiguration(
Expand Down
6 changes: 3 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as os from "os";
import * as path from "path";
import * as process from "process";
import { integer } from "vscode-languageserver-protocol";
import { IPowerShellAdditionalExePathSettings } from "./settings";
import { PowerShellAdditionalExePathSettings } from "./settings";

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

// Additional configured PowerShells
private readonly additionalPSExeSettings: IPowerShellAdditionalExePathSettings;
private readonly additionalPSExeSettings: PowerShellAdditionalExePathSettings;

private winPS: IPossiblePowerShellExe | undefined;

Expand All @@ -92,7 +92,7 @@ export class PowerShellExeFinder {
*/
constructor(
platformDetails?: IPlatformDetails,
additionalPowerShellExes?: IPowerShellAdditionalExePathSettings) {
additionalPowerShellExes?: PowerShellAdditionalExePathSettings) {

this.platformDetails = platformDetails ?? getPlatformDetails();
this.additionalPSExeSettings = additionalPowerShellExes ?? {};
Expand Down
4 changes: 2 additions & 2 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PowerShellProcess {
private logger: Logger,
private startPsesArgs: string,
private sessionFilePath: vscode.Uri,
private sessionSettings: Settings.ISettings) {
private sessionSettings: Settings.Settings) {

this.onExited = this.onExitedEmitter.event;
}
Expand All @@ -46,7 +46,7 @@ export class PowerShellProcess {
"PowerShellEditorServices/PowerShellEditorServices.psd1");

const featureFlags =
this.sessionSettings.developer.featureFlags !== undefined
this.sessionSettings.developer.featureFlags.length > 0
? this.sessionSettings.developer.featureFlags.map((f) => `'${f}'`).join(", ")
: "";

Expand Down
Loading