Skip to content

Commit ac2d6ad

Browse files
committed
Fix up ISettings
* Stop exporting things unused elsewhere * Remove unnecessary getWorkspaceSettingsWithDefaults * Make `settings.ts` and `package.json` defaults consistent
1 parent b640e71 commit ac2d6ad

File tree

4 files changed

+71
-69
lines changed

4 files changed

+71
-69
lines changed

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -573,18 +573,20 @@
573573
},
574574
"powershell.powerShellAdditionalExePaths": {
575575
"type": "object",
576+
"default": null,
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": null,
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": {
586588
"type": "string",
587-
"default": "",
589+
"default": null,
588590
"scope": "machine",
589591
"description": "REMOVED: Please use the \"powershell.powerShellAdditionalExePaths\" setting instead.",
590592
"deprecationMessage": "Please use the \"powershell.powerShellAdditionalExePaths\" setting instead."
@@ -811,6 +813,7 @@
811813
},
812814
"powershell.integratedConsole.forceClearScrollbackBuffer": {
813815
"type": "boolean",
816+
"default": false,
814817
"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."
815818
},
816819
"powershell.integratedConsole.suppressStartupBanner": {
@@ -825,6 +828,7 @@
825828
},
826829
"powershell.developer.bundledModulesPath": {
827830
"type": "string",
831+
"default": "../../PowerShellEditorServices/module",
828832
"description": "Specifies an alternate path to the folder containing modules that are bundled with the PowerShell extension (i.e. PowerShell Editor Services, PSScriptAnalyzer, Plaster)"
829833
},
830834
"powershell.developer.editorServicesLogLevel": {

src/logging.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import utils = require("./utils");
55
import os = require("os");
66
import vscode = require("vscode");
77

8+
// NOTE: This is not a string enum because the order is used for comparison.
89
export enum LogLevel {
910
Diagnostic,
1011
Verbose,

src/session.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,7 @@ Type 'help' to get help.
575575
editorServicesArgs += "-WaitForDebugger ";
576576
}
577577

578-
if (this.sessionSettings.developer.editorServicesLogLevel) {
579-
editorServicesArgs += `-LogLevel '${this.sessionSettings.developer.editorServicesLogLevel}' `;
580-
}
578+
editorServicesArgs += `-LogLevel '${this.sessionSettings.developer.editorServicesLogLevel}' `;
581579

582580
return editorServicesArgs;
583581
}

src/settings.ts

+64-65
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,53 @@ import utils = require("./utils");
66
import os = require("os");
77
import { Logger } from "./logging";
88

9+
export interface ISettings {
10+
powerShellAdditionalExePaths: IPowerShellAdditionalExePathSettings | undefined;
11+
powerShellDefaultVersion: string | undefined;
12+
// This setting is no longer used but is here to assist in cleaning up the users settings.
13+
powerShellExePath: string | undefined;
14+
promptToUpdatePowerShell: boolean;
15+
bundledModulesPath: string;
16+
startAsLoginShell: IStartAsLoginShellSettings;
17+
startAutomatically: boolean;
18+
enableProfileLoading: boolean;
19+
helpCompletion: string;
20+
scriptAnalysis: IScriptAnalysisSettings;
21+
debugging: IDebuggingSettings;
22+
developer: IDeveloperSettings;
23+
codeFolding: ICodeFoldingSettings;
24+
codeFormatting: ICodeFormattingSettings;
25+
integratedConsole: IIntegratedConsoleSettings;
26+
bugReporting: IBugReportingSettings;
27+
sideBar: ISideBarSettings;
28+
pester: IPesterSettings;
29+
buttons: IButtonSettings;
30+
cwd: string | undefined;
31+
enableReferencesCodeLens: boolean;
32+
analyzeOpenDocumentsOnly: boolean;
33+
}
34+
935
enum CodeFormattingPreset {
10-
Custom,
11-
Allman,
12-
OTBS,
13-
Stroustrup,
36+
Custom = "Custom",
37+
Allman = "Allman",
38+
OTBS = "OTBS",
39+
Stroustrup = "Stroustrup",
1440
}
1541

1642
enum PipelineIndentationStyle {
17-
IncreaseIndentationForFirstPipeline,
18-
IncreaseIndentationAfterEveryPipeline,
19-
NoIndentation,
20-
None,
43+
IncreaseIndentationForFirstPipeline = "IncreaseIndentationForFirstPipeline",
44+
IncreaseIndentationAfterEveryPipeline = "IncreaseIndentationAfterEveryPipeline",
45+
NoIndentation = "NoIndentation",
46+
None = "None",
47+
}
48+
49+
enum LogLevel {
50+
Diagnostic = "Diagnostic",
51+
Verbose = "Verbose",
52+
Normal = "Normal",
53+
Warning = "Warning",
54+
Error = "Error",
55+
None = "None",
2156
}
2257

2358
export enum CommentType {
@@ -28,16 +63,16 @@ export enum CommentType {
2863

2964
export type IPowerShellAdditionalExePathSettings = Record<string, string>;
3065

31-
export interface IBugReportingSettings {
66+
interface IBugReportingSettings {
3267
project: string;
3368
}
3469

35-
export interface ICodeFoldingSettings {
70+
interface ICodeFoldingSettings {
3671
enable: boolean;
3772
showLastLine: boolean;
3873
}
3974

40-
export interface ICodeFormattingSettings {
75+
interface ICodeFormattingSettings {
4176
autoCorrectAliases: boolean;
4277
avoidSemicolonsAsLineTerminators: boolean;
4378
preset: CodeFormattingPreset;
@@ -59,55 +94,29 @@ export interface ICodeFormattingSettings {
5994
useCorrectCasing: boolean;
6095
}
6196

62-
export interface IScriptAnalysisSettings {
97+
interface IScriptAnalysisSettings {
6398
enable: boolean;
6499
settingsPath: string;
65100
}
66101

67-
export interface IDebuggingSettings {
102+
interface IDebuggingSettings {
68103
createTemporaryIntegratedConsole: boolean;
69104
}
70105

71-
export interface IDeveloperSettings {
106+
interface IDeveloperSettings {
72107
featureFlags: string[];
73108
bundledModulesPath: string;
74-
editorServicesLogLevel: string;
109+
editorServicesLogLevel: LogLevel;
75110
editorServicesWaitForDebugger: boolean;
76111
waitForSessionFileTimeoutSeconds: number;
77112
}
78113

79-
export interface ISettings {
80-
powerShellAdditionalExePaths: IPowerShellAdditionalExePathSettings | undefined;
81-
powerShellDefaultVersion: string | undefined;
82-
// This setting is no longer used but is here to assist in cleaning up the users settings.
83-
powerShellExePath: string | undefined;
84-
promptToUpdatePowerShell: boolean;
85-
bundledModulesPath: string;
86-
startAsLoginShell: IStartAsLoginShellSettings;
87-
startAutomatically: boolean;
88-
enableProfileLoading: boolean;
89-
helpCompletion: string;
90-
scriptAnalysis: IScriptAnalysisSettings;
91-
debugging: IDebuggingSettings;
92-
developer: IDeveloperSettings;
93-
codeFolding: ICodeFoldingSettings;
94-
codeFormatting: ICodeFormattingSettings;
95-
integratedConsole: IIntegratedConsoleSettings;
96-
bugReporting: IBugReportingSettings;
97-
sideBar: ISideBarSettings;
98-
pester: IPesterSettings;
99-
buttons: IButtonSettings;
100-
cwd: string | undefined;
101-
enableReferencesCodeLens: boolean;
102-
analyzeOpenDocumentsOnly: boolean;
103-
}
104-
105-
export interface IStartAsLoginShellSettings {
114+
interface IStartAsLoginShellSettings {
106115
osx: boolean;
107116
linux: boolean;
108117
}
109118

110-
export interface IIntegratedConsoleSettings {
119+
interface IIntegratedConsoleSettings {
111120
showOnStartup: boolean;
112121
startInBackground: boolean;
113122
focusConsoleOnExecute: boolean;
@@ -116,17 +125,17 @@ export interface IIntegratedConsoleSettings {
116125
suppressStartupBanner: boolean;
117126
}
118127

119-
export interface ISideBarSettings {
128+
interface ISideBarSettings {
120129
CommandExplorerVisibility: boolean;
121130
}
122131

123-
export interface IPesterSettings {
132+
interface IPesterSettings {
124133
useLegacyCodeLens: boolean;
125134
outputVerbosity: string;
126135
debugOutputVerbosity: string;
127136
}
128137

129-
export interface IButtonSettings {
138+
interface IButtonSettings {
130139
showRunButtons: boolean;
131140
showPanelMovementButtons: boolean;
132141
}
@@ -154,14 +163,14 @@ export function load(): ISettings {
154163
// From `<root>/out/main.js` we go to the directory before <root> and
155164
// then into the other repo.
156165
bundledModulesPath: "../../PowerShellEditorServices/module",
157-
editorServicesLogLevel: "Normal",
166+
editorServicesLogLevel: LogLevel.Normal,
158167
editorServicesWaitForDebugger: false,
159168
waitForSessionFileTimeoutSeconds: 240,
160169
};
161170

162171
const defaultCodeFoldingSettings: ICodeFoldingSettings = {
163172
enable: true,
164-
showLastLine: false,
173+
showLastLine: true,
165174
};
166175

167176
const defaultCodeFormattingSettings: ICodeFormattingSettings = {
@@ -215,7 +224,10 @@ export function load(): ISettings {
215224
debugOutputVerbosity: "Diagnostic",
216225
};
217226

218-
// TODO: I believe all the defaults can be removed, as the `package.json` should supply them (and be the source of truth).
227+
// TODO: I believe all the defaults can be removed, as the `package.json`
228+
// should supply them (and be the source of truth). However, this proves
229+
// fairly messy to do as it requires casting the configuration to unknown
230+
// and then to `ISettings`. It could work but will take more testing.
219231
return {
220232
startAutomatically:
221233
configuration.get<boolean>("startAutomatically", true),
@@ -230,15 +242,15 @@ export function load(): ISettings {
230242
bundledModulesPath:
231243
"../modules", // Because the extension is always at `<root>/out/main.js`
232244
enableProfileLoading:
233-
configuration.get<boolean>("enableProfileLoading", false),
245+
configuration.get<boolean>("enableProfileLoading", true),
234246
helpCompletion:
235247
configuration.get<string>("helpCompletion", CommentType.BlockComment),
236248
scriptAnalysis:
237249
configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
238250
debugging:
239251
configuration.get<IDebuggingSettings>("debugging", defaultDebuggingSettings),
240252
developer:
241-
getWorkspaceSettingsWithDefaults<IDeveloperSettings>(configuration, "developer", defaultDeveloperSettings),
253+
configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings),
242254
codeFolding:
243255
configuration.get<ICodeFoldingSettings>("codeFolding", defaultCodeFoldingSettings),
244256
codeFormatting:
@@ -264,7 +276,7 @@ export function load(): ISettings {
264276
enableReferencesCodeLens:
265277
configuration.get<boolean>("enableReferencesCodeLens", true),
266278
analyzeOpenDocumentsOnly:
267-
configuration.get<boolean>("analyzeOpenDocumentsOnly", true),
279+
configuration.get<boolean>("analyzeOpenDocumentsOnly", false),
268280
};
269281
}
270282

@@ -303,19 +315,6 @@ export async function change(
303315
}
304316
}
305317

306-
function getWorkspaceSettingsWithDefaults<TSettings>(
307-
workspaceConfiguration: vscode.WorkspaceConfiguration,
308-
settingName: string,
309-
defaultSettings: TSettings): TSettings {
310-
311-
const importedSettings: TSettings = workspaceConfiguration.get<TSettings>(settingName, defaultSettings);
312-
313-
for (const setting in importedSettings) {
314-
defaultSettings[setting] = importedSettings[setting];
315-
}
316-
return defaultSettings;
317-
}
318-
319318
// We don't want to query the user more than once, so this is idempotent.
320319
let hasPrompted = false;
321320

0 commit comments

Comments
 (0)