Skip to content

Add poweshell.helpCompletion setting to control/disable feature #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
33 changes: 21 additions & 12 deletions src/features/HelpCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any, void, void>("powerShell/getCommentHelp");
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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("##");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be set to the settings value rather than "##"? One less string to manage. If it's less performant we don't have to do this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of the settings value (BlockComment or LineComment), the trigger sequence is always ##. Perhaps I'm not following the ask here??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I see now, you're right. Somehow I was thinking you could set the trigger to Block or Line. <# or ##. Ignore me :)

this.settings = Settings.load();
}

public get triggerFound(): boolean {
return this.triggerFinderBlockComment.found || this.triggerFinderLineComment.found;
return this.triggerFinderLineComment.found;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only have the one variable now, could this be renamed to triggerFinderHelpComment so that it's more apparent this applies to both block and line?

}

public set languageClient(value: LanguageClient) {
Expand All @@ -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();
}

Expand All @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +67,7 @@ export interface ISettings {
startAutomatically?: boolean;
useX86Host?: boolean;
enableProfileLoading?: boolean;
helpCompletion: string;
scriptAnalysis?: IScriptAnalysisSettings;
debugging?: IDebuggingSettings;
developer?: IDeveloperSettings;
Expand Down Expand Up @@ -132,6 +139,8 @@ export function load(): ISettings {
configuration.get<boolean>("useX86Host", false),
enableProfileLoading:
configuration.get<boolean>("enableProfileLoading", false),
helpCompletion:
configuration.get<string>("helpCompletion", HelpCompletion.BlockComment),
scriptAnalysis:
configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
debugging:
Expand Down