Skip to content

Commit a13bc67

Browse files
authored
Add poweshell.helpCompletion setting to control/disable feature (#1282)
* Add poweshell.helpCompletion setting to control/disable feature Changing this setting does require a reload window. Trigger sequence changed to just "##". Fix #1228 * Rename triggerFinderLineComment field per PR review
1 parent 83b91cc commit a13bc67

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

package.json

+10
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,16 @@
447447
"default": "https://github.com/PowerShell/vscode-powershell",
448448
"description": "Specifies the url of the GitHub project in which to generate bug reports."
449449
},
450+
"powershell.helpCompletion": {
451+
"type": "string",
452+
"enum": [
453+
"Disabled",
454+
"BlockComment",
455+
"LineComment"
456+
],
457+
"default": "BlockComment",
458+
"description": "Controls the comment-based help completion behavior triggered by typing '##'. Set the generated help style with 'BlockComment' or 'LineComment'. Disable the feature with 'Disabled'."
459+
},
450460
"powershell.scriptAnalysis.enable": {
451461
"type": "boolean",
452462
"default": true,

src/features/HelpCompletion.ts

+25-16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Disposable, EndOfLine, Position, Range, SnippetString,
77
import { LanguageClient, RequestType } from "vscode-languageclient";
88
import { IFeature } from "../feature";
99
import { Logger } from "../logging";
10+
import Settings = require("../settings");
1011

1112
export const CommentHelpRequestType =
1213
new RequestType<any, any, void, void>("powerShell/getCommentHelp");
@@ -27,21 +28,30 @@ export class HelpCompletionFeature implements IFeature {
2728
private helpCompletionProvider: HelpCompletionProvider;
2829
private languageClient: LanguageClient;
2930
private disposable: Disposable;
31+
private settings: Settings.ISettings;
3032

3133
constructor(private log: Logger) {
32-
this.helpCompletionProvider = new HelpCompletionProvider();
33-
const subscriptions = [];
34-
workspace.onDidChangeTextDocument(this.onEvent, this, subscriptions);
35-
this.disposable = Disposable.from(...subscriptions);
34+
this.settings = Settings.load();
35+
36+
if (this.settings.helpCompletion !== Settings.HelpCompletion.Disabled) {
37+
this.helpCompletionProvider = new HelpCompletionProvider();
38+
const subscriptions = [];
39+
workspace.onDidChangeTextDocument(this.onEvent, this, subscriptions);
40+
this.disposable = Disposable.from(...subscriptions);
41+
}
3642
}
3743

3844
public dispose() {
39-
this.disposable.dispose();
45+
if (this.disposable) {
46+
this.disposable.dispose();
47+
}
4048
}
4149

4250
public setLanguageClient(languageClient: LanguageClient) {
4351
this.languageClient = languageClient;
44-
this.helpCompletionProvider.languageClient = languageClient;
52+
if (this.helpCompletionProvider) {
53+
this.helpCompletionProvider.languageClient = languageClient;
54+
}
4555
}
4656

4757
public onEvent(changeEvent: TextDocumentChangeEvent): void {
@@ -68,6 +78,7 @@ class TriggerFinder {
6878
private state: SearchState;
6979
private document: TextDocument;
7080
private count: number;
81+
7182
constructor(private triggerCharacters: string) {
7283
this.state = SearchState.Searching;
7384
this.count = 0;
@@ -113,20 +124,20 @@ class TriggerFinder {
113124
}
114125

115126
class HelpCompletionProvider {
116-
private triggerFinderBlockComment: TriggerFinder;
117-
private triggerFinderLineComment: TriggerFinder;
127+
private triggerFinderHelpComment: TriggerFinder;
118128
private lastChangeText: string;
119129
private lastChangeRange: Range;
120130
private lastDocument: TextDocument;
121131
private langClient: LanguageClient;
132+
private settings: Settings.ISettings;
122133

123134
constructor() {
124-
this.triggerFinderBlockComment = new TriggerFinder("<#");
125-
this.triggerFinderLineComment = new TriggerFinder("##");
135+
this.triggerFinderHelpComment = new TriggerFinder("##");
136+
this.settings = Settings.load();
126137
}
127138

128139
public get triggerFound(): boolean {
129-
return this.triggerFinderBlockComment.found || this.triggerFinderLineComment.found;
140+
return this.triggerFinderHelpComment.found;
130141
}
131142

132143
public set languageClient(value: LanguageClient) {
@@ -137,13 +148,11 @@ class HelpCompletionProvider {
137148
this.lastDocument = document;
138149
this.lastChangeText = changeText;
139150
this.lastChangeRange = changeRange;
140-
this.triggerFinderBlockComment.updateState(document, changeText);
141-
this.triggerFinderLineComment.updateState(document, changeText);
151+
this.triggerFinderHelpComment.updateState(document, changeText);
142152
}
143153

144154
public reset(): void {
145-
this.triggerFinderBlockComment.reset();
146-
this.triggerFinderLineComment.reset();
155+
this.triggerFinderHelpComment.reset();
147156
}
148157

149158
public complete(): Thenable<void> {
@@ -161,7 +170,7 @@ class HelpCompletionProvider {
161170
{
162171
documentUri: doc.uri.toString(),
163172
triggerPosition: triggerStartPos,
164-
blockComment: this.triggerFinderBlockComment.found,
173+
blockComment: this.settings.helpCompletion === Settings.HelpCompletion.BlockComment,
165174
}).then((result) => {
166175
if (result == null || result.content == null) {
167176
return;

src/settings.ts

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ enum CodeFormattingPreset {
1414
Stroustrup,
1515
}
1616

17+
export class HelpCompletion {
18+
public static readonly Disabled: string = "Disabled";
19+
public static readonly BlockComment: string = "BlockComment";
20+
public static readonly LineComment: string = "LineComment";
21+
}
22+
1723
export interface IPowerShellAdditionalExePathSettings {
1824
versionName: string;
1925
exePath: string;
@@ -61,6 +67,7 @@ export interface ISettings {
6167
startAutomatically?: boolean;
6268
useX86Host?: boolean;
6369
enableProfileLoading?: boolean;
70+
helpCompletion: string;
6471
scriptAnalysis?: IScriptAnalysisSettings;
6572
debugging?: IDebuggingSettings;
6673
developer?: IDeveloperSettings;
@@ -132,6 +139,8 @@ export function load(): ISettings {
132139
configuration.get<boolean>("useX86Host", false),
133140
enableProfileLoading:
134141
configuration.get<boolean>("enableProfileLoading", false),
142+
helpCompletion:
143+
configuration.get<string>("helpCompletion", HelpCompletion.BlockComment),
135144
scriptAnalysis:
136145
configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
137146
debugging:

0 commit comments

Comments
 (0)