Skip to content

Commit

Permalink
Also support MarkdownString in signature help, #11877
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Sep 8, 2017
1 parent e4ce445 commit cd4c1b3
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export interface ParameterInformation {
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*/
documentation?: string;
documentation?: string | IMarkdownString;
}
/**
* Represents the signature of something callable. A signature
Expand All @@ -302,7 +302,7 @@ export interface SignatureInformation {
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*/
documentation?: string;
documentation?: string | IMarkdownString;
/**
* The parameters of this signature.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOption
import { ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { registerThemingParticipant, HIGH_CONTRAST } from 'vs/platform/theme/common/themeService';
import { editorHoverBackground, editorHoverBorder } from 'vs/platform/theme/common/colorRegistry';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IModeService } from 'vs/editor/common/services/modeService';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/browser/markdownRenderer';

const $ = dom.$;

Expand Down Expand Up @@ -170,6 +173,7 @@ export class ParameterHintsWidget implements IContentWidget, IDisposable {

private static ID = 'editor.widget.parameterHintsWidget';

private markdownRenderer: MarkdownRenderer;
private model: ParameterHintsModel;
private keyVisible: IContextKey<boolean>;
private keyMultipleSignatures: IContextKey<boolean>;
Expand All @@ -187,7 +191,13 @@ export class ParameterHintsWidget implements IContentWidget, IDisposable {
// Editor.IContentWidget.allowEditorOverflow
allowEditorOverflow = true;

constructor(private editor: ICodeEditor, @IContextKeyService contextKeyService: IContextKeyService) {
constructor(
private editor: ICodeEditor,
@IContextKeyService contextKeyService: IContextKeyService,
@IOpenerService openerService: IOpenerService,
@IModeService modeService: IModeService,
) {
this.markdownRenderer = new MarkdownRenderer(editor, modeService, openerService);
this.model = new ParameterHintsModel(editor);
this.keyVisible = Context.Visible.bindTo(contextKeyService);
this.keyMultipleSignatures = Context.MultipleSignatures.bindTo(contextKeyService);
Expand Down Expand Up @@ -325,14 +335,20 @@ export class ParameterHintsWidget implements IContentWidget, IDisposable {

if (activeParameter && activeParameter.documentation) {
const documentation = $('span.documentation');
documentation.textContent = activeParameter.documentation;
if (typeof activeParameter.documentation === 'string') {
documentation.textContent = activeParameter.documentation;
} else {
documentation.appendChild(this.markdownRenderer.render(activeParameter.documentation));
}
dom.append(this.docs, $('p', null, documentation));
}

dom.toggleClass(this.signature, 'has-docs', !!signature.documentation);

if (signature.documentation) {
if (typeof signature.documentation === 'string') {
dom.append(this.docs, $('p', null, signature.documentation));
} else {
dom.append(this.docs, this.markdownRenderer.render(signature.documentation));
}

let currentOverload = String(this.currentSignature + 1);
Expand Down Expand Up @@ -491,4 +507,4 @@ registerThemingParticipant((theme, collector) => {
if (background) {
collector.addRule(`.monaco-editor .parameter-hints-widget { background-color: ${background}; }`);
}
});
});
4 changes: 2 additions & 2 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4459,7 +4459,7 @@ declare module monaco.languages {
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*/
documentation?: string;
documentation?: string | IMarkdownString;
}

/**
Expand All @@ -4477,7 +4477,7 @@ declare module monaco.languages {
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*/
documentation?: string;
documentation?: string | IMarkdownString;
/**
* The parameters of this signature.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2458,15 +2458,15 @@ declare module 'vscode' {
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*/
documentation?: string;
documentation?: string | MarkdownString;

/**
* Creates a new parameter information object.
*
* @param label A label string.
* @param documentation A doc string.
*/
constructor(label: string, documentation?: string);
constructor(label: string, documentation?: string | MarkdownString);
}

/**
Expand All @@ -2486,7 +2486,7 @@ declare module 'vscode' {
* The human-readable doc-comment of this signature. Will be shown
* in the UI but can be omitted.
*/
documentation?: string;
documentation?: string | MarkdownString;

/**
* The parameters of this signature.
Expand All @@ -2499,7 +2499,7 @@ declare module 'vscode' {
* @param label A label string.
* @param documentation A doc string.
*/
constructor(label: string, documentation?: string);
constructor(label: string, documentation?: string | MarkdownString);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/api/node/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { TextEditorCursorStyle } from 'vs/editor/common/config/editorOptions';
import { ExtHostThreadService } from 'vs/workbench/services/thread/node/extHostThreadService';
import { ProxyIdentifier } from 'vs/workbench/services/thread/common/threadService';
import { ExtHostDialogs } from 'vs/workbench/api/node/extHostDialogs';
import { MarkdownString } from 'vs/base/common/htmlContent';

export interface IExtensionApiFactory {
(extension: IExtensionDescription): typeof vscode;
Expand Down Expand Up @@ -567,7 +566,7 @@ export function createApiFactory(
Hover: extHostTypes.Hover,
IndentAction: languageConfiguration.IndentAction,
Location: extHostTypes.Location,
MarkdownString: MarkdownString,
MarkdownString: extHostTypes.MarkdownString,
OverviewRulerLane: EditorCommon.OverviewRulerLane,
ParameterInformation: extHostTypes.ParameterInformation,
Position: extHostTypes.Position,
Expand Down
52 changes: 47 additions & 5 deletions src/vs/workbench/api/node/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export namespace Suggest {
result.insertText = suggestion.insertText;
result.kind = CompletionItemKind.to(suggestion.type);
result.detail = suggestion.detail;
result.documentation = typeof suggestion.documentation === 'string' ? suggestion.documentation : MarkdownString.to(suggestion.documentation);
result.documentation = htmlContent.isMarkdownString(suggestion.documentation) ? MarkdownString.to(suggestion.documentation) : suggestion.documentation;
result.sortText = suggestion.sortText;
result.filterText = suggestion.filterText;

Expand All @@ -381,14 +381,56 @@ export namespace Suggest {
}
};

export namespace ParameterInformation {
export function from(info: types.ParameterInformation): modes.ParameterInformation {
return {
label: info.label,
documentation: info.documentation && MarkdownString.from(info.documentation)
};
}
export function to(info: modes.ParameterInformation): types.ParameterInformation {
return {
label: info.label,
documentation: htmlContent.isMarkdownString(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation
};
}
}

export namespace SignatureInformation {

export function from(info: types.SignatureInformation): modes.SignatureInformation {
return {
label: info.label,
documentation: info.documentation && MarkdownString.from(info.documentation),
parameters: info.parameters && info.parameters.map(ParameterInformation.from)
};
}

export function to(info: modes.SignatureInformation): types.SignatureInformation {
return {
label: info.label,
documentation: htmlContent.isMarkdownString(info.documentation) ? MarkdownString.to(info.documentation) : info.documentation,
parameters: info.parameters && info.parameters.map(ParameterInformation.to)
};
}
}

export namespace SignatureHelp {

export function from(signatureHelp: types.SignatureHelp): modes.SignatureHelp {
return signatureHelp;
export function from(help: types.SignatureHelp): modes.SignatureHelp {
return {
activeSignature: help.activeSignature,
activeParameter: help.activeParameter,
signatures: help.signatures && help.signatures.map(SignatureInformation.from)
};
}

export function to(hints: modes.SignatureHelp): types.SignatureHelp {
return hints;
export function to(help: modes.SignatureHelp): types.SignatureHelp {
return {
activeSignature: help.activeSignature,
activeParameter: help.activeParameter,
signatures: help.signatures && help.signatures.map(SignatureInformation.to)
};
}
}

Expand Down
31 changes: 26 additions & 5 deletions src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,33 @@ export class CodeLens {
}
}

export class MarkdownString {

value: string;
isTrusted?: boolean;

constructor(value?: string) {
this.value = value || '';
}

appendText(value: string): MarkdownString {
// escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
this.value += value.replace(/[\\`*_{}[\]()#+\-.!]/g, '\\$&');
return this;
}

appendMarkdown(value: string): MarkdownString {
this.value += value;
return this;
}
}

export class ParameterInformation {

label: string;
documentation?: string;
documentation?: string | MarkdownString;

constructor(label: string, documentation?: string) {
constructor(label: string, documentation?: string | MarkdownString) {
this.label = label;
this.documentation = documentation;
}
Expand All @@ -838,10 +859,10 @@ export class ParameterInformation {
export class SignatureInformation {

label: string;
documentation?: string;
documentation?: string | MarkdownString;
parameters: ParameterInformation[];

constructor(label: string, documentation?: string) {
constructor(label: string, documentation?: string | MarkdownString) {
this.label = label;
this.documentation = documentation;
this.parameters = [];
Expand Down Expand Up @@ -892,7 +913,7 @@ export class CompletionItem {
label: string;
kind: CompletionItemKind;
detail: string;
documentation: string | vscode.MarkdownString;
documentation: string | MarkdownString;
sortText: string;
filterText: string;
insertText: string | SnippetString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,11 @@ suite('ExtHostLanguageFeatures', function () {

disposables.push(extHost.registerSignatureHelpProvider(defaultSelector, <vscode.SignatureHelpProvider>{
provideSignatureHelp(): vscode.SignatureHelp {
return new types.SignatureHelp();
return {
signatures: [],
activeParameter: 0,
activeSignature: 0
};
}
}, []));

Expand Down

0 comments on commit cd4c1b3

Please sign in to comment.