Skip to content

Commit 6a99426

Browse files
committed
(PowerShellGH-1336) Add Code Folding settings and enable by default
Previously the syntax folding was available for all users. However it was able to be configured or turned off. This commit adds a new `codeFolding` settings section, with the syntax folding feature enabled by default.
1 parent 1e15180 commit 6a99426

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@
467467
"default": "",
468468
"description": "Specifies the path to a PowerShell Script Analyzer settings file. To override the default settings for all projects, enter an absolute path, or enter a path relative to your workspace."
469469
},
470+
"powershell.codeFolding.enable": {
471+
"type": "boolean",
472+
"default": true,
473+
"description": "Enables syntax based code folding. When disabled, the default indentation based code folding is used."
474+
},
470475
"powershell.codeFormatting.preset": {
471476
"type": "string",
472477
"enum": [

src/features/Folding.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "vscode-languageclient";
77
import { IFeature } from "../feature";
88
import { Logger } from "../logging";
9+
import * as Settings from "../settings";
910

1011
/**
1112
* Defines a grammar file that is in a VS Code Extension
@@ -495,6 +496,9 @@ export class FoldingFeature implements IFeature {
495496
constructor(private logger: Logger, documentSelector: DocumentSelector) {
496497
const grammar: IGrammar = this.grammar(logger);
497498

499+
const settings = Settings.load();
500+
if (!(settings.codeFolding && settings.codeFolding.enable)) { return; }
501+
498502
// If the PowerShell grammar is not available for some reason, don't register a folding provider,
499503
// which reverts VSCode to the default indentation style folding
500504
if (grammar == null) {

src/settings.ts

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export interface IBugReportingSettings {
2929
project: string;
3030
}
3131

32+
export interface ICodeFoldingSettings {
33+
enable?: boolean;
34+
}
35+
3236
export interface ICodeFormattingSettings {
3337
preset: CodeFormattingPreset;
3438
openBraceOnSameLine: boolean;
@@ -72,6 +76,7 @@ export interface ISettings {
7276
scriptAnalysis?: IScriptAnalysisSettings;
7377
debugging?: IDebuggingSettings;
7478
developer?: IDeveloperSettings;
79+
codeFolding?: ICodeFoldingSettings;
7580
codeFormatting?: ICodeFormattingSettings;
7681
integratedConsole?: IIntegratedConsoleSettings;
7782
bugReporting?: IBugReportingSettings;
@@ -109,6 +114,10 @@ export function load(): ISettings {
109114
powerShellExeIsWindowsDevBuild: false,
110115
};
111116

117+
const defaultCodeFoldingSettings: ICodeFoldingSettings = {
118+
enable: true,
119+
};
120+
112121
const defaultCodeFormattingSettings: ICodeFormattingSettings = {
113122
preset: CodeFormattingPreset.Custom,
114123
openBraceOnSameLine: true,
@@ -150,6 +159,8 @@ export function load(): ISettings {
150159
configuration.get<IDebuggingSettings>("debugging", defaultDebuggingSettings),
151160
developer:
152161
getWorkspaceSettingsWithDefaults<IDeveloperSettings>(configuration, "developer", defaultDeveloperSettings),
162+
codeFolding:
163+
configuration.get<ICodeFoldingSettings>("codeFolding", defaultCodeFoldingSettings),
153164
codeFormatting:
154165
configuration.get<ICodeFormattingSettings>("codeFormatting", defaultCodeFormattingSettings),
155166
integratedConsole:

0 commit comments

Comments
 (0)