提交 cd4c1b3a 编写于 作者: J Johannes Rieken

Also support MarkdownString in signature help, #11877

上级 e4ce4453
......@@ -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
......@@ -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.
*/
......
......@@ -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.$;
......@@ -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>;
......@@ -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);
......@@ -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);
......@@ -491,4 +507,4 @@ registerThemingParticipant((theme, collector) => {
if (background) {
collector.addRule(`.monaco-editor .parameter-hints-widget { background-color: ${background}; }`);
}
});
\ No newline at end of file
});
......@@ -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;
}
/**
......@@ -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.
*/
......
......@@ -2458,7 +2458,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;
/**
* Creates a new parameter information object.
......@@ -2466,7 +2466,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);
}
/**
......@@ -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.
......@@ -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);
}
/**
......
......@@ -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;
......@@ -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,
......
......@@ -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;
......@@ -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)
};
}
}
......
......@@ -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;
}
......@@ -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 = [];
......@@ -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;
......
......@@ -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
};
}
}, []));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册