Skip to content

Commit 99dee72

Browse files
committed
Clean up settings.ts and its use
1 parent e431f79 commit 99dee72

13 files changed

+98
-92
lines changed

src/features/Console.ts

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ 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");
8+
import { getSettings } from "../settings";
99

1010
const queryStringPrefix = "?";
1111

12-
const settings = Settings.load();
13-
const project = settings.bugReporting.project;
12+
const project = getSettings().bugReporting.project;
1413
const issuesUrl = `${project}/issues/new`;
1514

1615
const extensions =

src/features/HelpCompletion.ts

Lines changed: 7 additions & 7 deletions
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 { ISettings, 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: ISettings;
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: ISettings;
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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(

0 commit comments

Comments
 (0)