From eaad79c8eae30cb217f2edb77ead3f858f79ce1a Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 21 Apr 2018 23:01:42 -0600 Subject: [PATCH 1/2] Add poweshell.helpCompletion setting to control/disable feature Changing this setting does require a reload window. Trigger sequence changed to just "##". Fix #1228 --- package.json | 10 ++++++++++ src/features/HelpCompletion.ts | 33 +++++++++++++++++++++------------ src/settings.ts | 9 +++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 61100d285a..7b3e051560 100644 --- a/package.json +++ b/package.json @@ -447,6 +447,16 @@ "default": "https://github.com/PowerShell/vscode-powershell", "description": "Specifies the url of the GitHub project in which to generate bug reports." }, + "powershell.helpCompletion": { + "type": "string", + "enum": [ + "Disabled", + "BlockComment", + "LineComment" + ], + "default": "BlockComment", + "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'." + }, "powershell.scriptAnalysis.enable": { "type": "boolean", "default": true, diff --git a/src/features/HelpCompletion.ts b/src/features/HelpCompletion.ts index f056e10fe0..b5ef097ce1 100644 --- a/src/features/HelpCompletion.ts +++ b/src/features/HelpCompletion.ts @@ -7,6 +7,7 @@ import { Disposable, EndOfLine, Position, Range, SnippetString, import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; import { Logger } from "../logging"; +import Settings = require("../settings"); export const CommentHelpRequestType = new RequestType("powerShell/getCommentHelp"); @@ -27,21 +28,30 @@ export class HelpCompletionFeature implements IFeature { private helpCompletionProvider: HelpCompletionProvider; private languageClient: LanguageClient; private disposable: Disposable; + private settings: Settings.ISettings; constructor(private log: Logger) { - this.helpCompletionProvider = new HelpCompletionProvider(); - const subscriptions = []; - workspace.onDidChangeTextDocument(this.onEvent, this, subscriptions); - this.disposable = Disposable.from(...subscriptions); + this.settings = Settings.load(); + + if (this.settings.helpCompletion !== Settings.HelpCompletion.Disabled) { + this.helpCompletionProvider = new HelpCompletionProvider(); + const subscriptions = []; + workspace.onDidChangeTextDocument(this.onEvent, this, subscriptions); + this.disposable = Disposable.from(...subscriptions); + } } public dispose() { - this.disposable.dispose(); + if (this.disposable) { + this.disposable.dispose(); + } } public setLanguageClient(languageClient: LanguageClient) { this.languageClient = languageClient; - this.helpCompletionProvider.languageClient = languageClient; + if (this.helpCompletionProvider) { + this.helpCompletionProvider.languageClient = languageClient; + } } public onEvent(changeEvent: TextDocumentChangeEvent): void { @@ -68,6 +78,7 @@ class TriggerFinder { private state: SearchState; private document: TextDocument; private count: number; + constructor(private triggerCharacters: string) { this.state = SearchState.Searching; this.count = 0; @@ -113,20 +124,20 @@ class TriggerFinder { } class HelpCompletionProvider { - private triggerFinderBlockComment: TriggerFinder; private triggerFinderLineComment: TriggerFinder; private lastChangeText: string; private lastChangeRange: Range; private lastDocument: TextDocument; private langClient: LanguageClient; + private settings: Settings.ISettings; constructor() { - this.triggerFinderBlockComment = new TriggerFinder("<#"); this.triggerFinderLineComment = new TriggerFinder("##"); + this.settings = Settings.load(); } public get triggerFound(): boolean { - return this.triggerFinderBlockComment.found || this.triggerFinderLineComment.found; + return this.triggerFinderLineComment.found; } public set languageClient(value: LanguageClient) { @@ -137,12 +148,10 @@ class HelpCompletionProvider { this.lastDocument = document; this.lastChangeText = changeText; this.lastChangeRange = changeRange; - this.triggerFinderBlockComment.updateState(document, changeText); this.triggerFinderLineComment.updateState(document, changeText); } public reset(): void { - this.triggerFinderBlockComment.reset(); this.triggerFinderLineComment.reset(); } @@ -161,7 +170,7 @@ class HelpCompletionProvider { { documentUri: doc.uri.toString(), triggerPosition: triggerStartPos, - blockComment: this.triggerFinderBlockComment.found, + blockComment: this.settings.helpCompletion === Settings.HelpCompletion.BlockComment, }).then((result) => { if (result == null || result.content == null) { return; diff --git a/src/settings.ts b/src/settings.ts index ba42119c24..4c77d2f60b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -14,6 +14,12 @@ enum CodeFormattingPreset { Stroustrup, } +export class HelpCompletion { + public static readonly Disabled: string = "Disabled"; + public static readonly BlockComment: string = "BlockComment"; + public static readonly LineComment: string = "LineComment"; +} + export interface IPowerShellAdditionalExePathSettings { versionName: string; exePath: string; @@ -61,6 +67,7 @@ export interface ISettings { startAutomatically?: boolean; useX86Host?: boolean; enableProfileLoading?: boolean; + helpCompletion: string; scriptAnalysis?: IScriptAnalysisSettings; debugging?: IDebuggingSettings; developer?: IDeveloperSettings; @@ -132,6 +139,8 @@ export function load(): ISettings { configuration.get("useX86Host", false), enableProfileLoading: configuration.get("enableProfileLoading", false), + helpCompletion: + configuration.get("helpCompletion", HelpCompletion.BlockComment), scriptAnalysis: configuration.get("scriptAnalysis", defaultScriptAnalysisSettings), debugging: From 89d67efd47f4aec684776bb7e28801f77b706efb Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 22 Apr 2018 13:12:10 -0600 Subject: [PATCH 2/2] Rename triggerFinderLineComment field per PR review --- src/features/HelpCompletion.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/features/HelpCompletion.ts b/src/features/HelpCompletion.ts index b5ef097ce1..0dad935e71 100644 --- a/src/features/HelpCompletion.ts +++ b/src/features/HelpCompletion.ts @@ -124,7 +124,7 @@ class TriggerFinder { } class HelpCompletionProvider { - private triggerFinderLineComment: TriggerFinder; + private triggerFinderHelpComment: TriggerFinder; private lastChangeText: string; private lastChangeRange: Range; private lastDocument: TextDocument; @@ -132,12 +132,12 @@ class HelpCompletionProvider { private settings: Settings.ISettings; constructor() { - this.triggerFinderLineComment = new TriggerFinder("##"); + this.triggerFinderHelpComment = new TriggerFinder("##"); this.settings = Settings.load(); } public get triggerFound(): boolean { - return this.triggerFinderLineComment.found; + return this.triggerFinderHelpComment.found; } public set languageClient(value: LanguageClient) { @@ -148,11 +148,11 @@ class HelpCompletionProvider { this.lastDocument = document; this.lastChangeText = changeText; this.lastChangeRange = changeRange; - this.triggerFinderLineComment.updateState(document, changeText); + this.triggerFinderHelpComment.updateState(document, changeText); } public reset(): void { - this.triggerFinderLineComment.reset(); + this.triggerFinderHelpComment.reset(); } public complete(): Thenable {