Skip to content

Commit

Permalink
Allow CompletionItem#documention to be also a MarkdownString, #11877
Browse files Browse the repository at this point in the history
Update internal api, update rendering of suggestion details, tweak shared renderer
  • Loading branch information
jrieken committed Sep 8, 2017
1 parent 48bc6f1 commit 098f7fa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/common/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export interface ISuggestion {
insertText: string;
type: SuggestionType;
detail?: string;
documentation?: string;
documentation?: string | IMarkdownString;
filterText?: string;
sortText?: string;
noAutoAccept?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/vs/editor/contrib/markdown/browser/markdownRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ export class MarkdownRenderer {

return this._modeService.getOrCreateMode(modeId).then(_ => {
return tokenizeToString(value, modeId);
}).then(code => {
return `<span style="font-family: ${editor.getConfiguration().fontInfo.fontFamily}">${code}</span>`;
});
}
};
}

render(markdown: IMarkdownString, options?: RenderOptions): HTMLElement {
if (!markdown) {
return document.createElement('span');
}
if (options) {
return renderMarkdown(markdown, { ...options, ...this._options });
} else {
Expand Down
19 changes: 15 additions & 4 deletions src/vs/editor/contrib/suggest/browser/suggestWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import { attachListStyler } from 'vs/platform/theme/common/styler';
import { IThemeService, ITheme, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { registerColor, editorWidgetBackground, listFocusBackground, activeContrastBorder, listHighlightForeground, editorForeground, editorWidgetBorder, focusBorder } from 'vs/platform/theme/common/colorRegistry';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/browser/markdownRenderer';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IOpenerService } from 'vs/platform/opener/common/opener';

const sticky = false; // for development purposes
const expandSuggestionDocsByDefault = false;
Expand Down Expand Up @@ -142,7 +145,7 @@ class Renderer implements IRenderer<ICompletionItem, ISuggestionTemplateData> {
data.colorspan.style.backgroundColor = '';

if (suggestion.type === 'color') {
let color = matchesColor(suggestion.label) || matchesColor(suggestion.documentation);
let color = matchesColor(suggestion.label) || typeof suggestion.documentation === 'string' && matchesColor(suggestion.documentation);
if (color) {
data.icon.className = 'icon customcolor';
data.colorspan.style.backgroundColor = color;
Expand Down Expand Up @@ -203,6 +206,7 @@ class SuggestionDetails {
container: HTMLElement,
private widget: SuggestWidget,
private editor: ICodeEditor,
private markdownRenderer: MarkdownRenderer,
private triggerKeybindingLabel: string
) {
this.disposables = [];
Expand Down Expand Up @@ -244,7 +248,11 @@ class SuggestionDetails {
return;
}
removeClass(this.el, 'no-docs');
this.docs.textContent = item.suggestion.documentation;
if (typeof item.suggestion.documentation === 'string') {
this.docs.textContent = item.suggestion.documentation;
} else {
this.docs.innerHTML = this.markdownRenderer.render(item.suggestion.documentation).innerHTML;
}

if (item.suggestion.detail) {
this.type.innerText = item.suggestion.detail;
Expand Down Expand Up @@ -382,10 +390,13 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
@IContextKeyService contextKeyService: IContextKeyService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService,
@IKeybindingService keybindingService: IKeybindingService
@IKeybindingService keybindingService: IKeybindingService,
@IModeService modeService: IModeService,
@IOpenerService openerService: IOpenerService
) {
const kb = keybindingService.lookupKeybinding('editor.action.triggerSuggest');
const triggerKeybindingLabel = !kb ? '' : ` (${kb.getLabel()})`;
const markdownRenderer = new MarkdownRenderer(editor, modeService, openerService);

this.isAuto = false;
this.focusedItem = null;
Expand All @@ -405,7 +416,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>

this.messageElement = append(this.element, $('.message'));
this.listElement = append(this.element, $('.tree'));
this.details = new SuggestionDetails(this.element, this, this.editor, triggerKeybindingLabel);
this.details = new SuggestionDetails(this.element, this, this.editor, markdownRenderer, triggerKeybindingLabel);

let renderer = new Renderer(this, this.editor, triggerKeybindingLabel);

Expand Down
2 changes: 1 addition & 1 deletion src/vs/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,7 @@ declare module 'vscode' {
/**
* A human-readable string that represents a doc-comment.
*/
documentation?: string;
documentation?: string | MarkdownString;

/**
* A string that should be used when comparing this item
Expand Down
2 changes: 1 addition & 1 deletion 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 = suggestion.documentation;
result.documentation = typeof suggestion.documentation === 'string' ? suggestion.documentation : MarkdownString.to(suggestion.documentation);
result.sortText = suggestion.sortText;
result.filterText = suggestion.filterText;

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ export class CompletionItem {
label: string;
kind: CompletionItemKind;
detail: string;
documentation: string;
documentation: string | vscode.MarkdownString;
sortText: string;
filterText: string;
insertText: string | SnippetString;
Expand Down

0 comments on commit 098f7fa

Please sign in to comment.