mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
product icons definition files: show icon in hover
This commit is contained in:
parent
1897f26c21
commit
951164ae96
|
@ -13,12 +13,12 @@ const localize = nls.loadMessageBundle();
|
|||
import {
|
||||
workspace, window, languages, commands, ExtensionContext, extensions, Uri, LanguageConfiguration,
|
||||
Diagnostic, StatusBarAlignment, TextEditor, TextDocument, FormattingOptions, CancellationToken,
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext
|
||||
ProviderResult, TextEdit, Range, Position, Disposable, CompletionItem, CompletionList, CompletionContext, Hover, MarkdownString, MarkedString
|
||||
} from 'vscode';
|
||||
import {
|
||||
LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType,
|
||||
DidChangeConfigurationNotification, HandleDiagnosticsSignature, ResponseError, DocumentRangeFormattingParams,
|
||||
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature
|
||||
DocumentRangeFormattingRequest, ProvideCompletionItemsSignature, ProvideHoverSignature
|
||||
} from 'vscode-languageclient';
|
||||
import TelemetryReporter from 'vscode-extension-telemetry';
|
||||
|
||||
|
@ -153,25 +153,41 @@ export function activate(context: ExtensionContext) {
|
|||
},
|
||||
// testing the replace / insert mode
|
||||
provideCompletionItem(document: TextDocument, position: Position, context: CompletionContext, token: CancellationToken, next: ProvideCompletionItemsSignature): ProviderResult<CompletionItem[] | CompletionList> {
|
||||
function updateRanges(item: CompletionItem) {
|
||||
function update(item: CompletionItem) {
|
||||
const range = item.range;
|
||||
if (range instanceof Range && range.end.isAfter(position) && range.start.isBeforeOrEqual(position)) {
|
||||
item.range = { inserting: new Range(range.start, position), replacing: range };
|
||||
}
|
||||
if (item.documentation instanceof MarkdownString) {
|
||||
item.documentation = updateMarkdownString(item.documentation);
|
||||
}
|
||||
|
||||
}
|
||||
function updateProposals(r: CompletionItem[] | CompletionList | null | undefined): CompletionItem[] | CompletionList | null | undefined {
|
||||
if (r) {
|
||||
(Array.isArray(r) ? r : r.items).forEach(updateRanges);
|
||||
(Array.isArray(r) ? r : r.items).forEach(update);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
const isThenable = <T>(obj: ProviderResult<T>): obj is Thenable<T> => obj && (<any>obj)['then'];
|
||||
|
||||
const r = next(document, position, context, token);
|
||||
if (isThenable<CompletionItem[] | CompletionList | null | undefined>(r)) {
|
||||
return r.then(updateProposals);
|
||||
}
|
||||
return updateProposals(r);
|
||||
},
|
||||
provideHover(document: TextDocument, position: Position, token: CancellationToken, next: ProvideHoverSignature) {
|
||||
function updateHover(r: Hover | null | undefined): Hover | null | undefined {
|
||||
if (r && Array.isArray(r.contents)) {
|
||||
r.contents = r.contents.map(h => h instanceof MarkdownString ? updateMarkdownString(h) : h);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
const r = next(document, position, token);
|
||||
if (isThenable<Hover | null | undefined>(r)) {
|
||||
return r.then(updateHover);
|
||||
}
|
||||
return updateHover(r);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -492,3 +508,13 @@ function readJSONFile(location: string) {
|
|||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
function isThenable<T>(obj: ProviderResult<T>): obj is Thenable<T> {
|
||||
return obj && (<any>obj)['then'];
|
||||
}
|
||||
|
||||
function updateMarkdownString(h: MarkdownString): MarkdownString {
|
||||
const n = new MarkdownString(h.value, true);
|
||||
n.isTrusted = h.isTrusted;
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ class IconRegistry implements IIconRegistry {
|
|||
if (deprecationMessage) {
|
||||
propertySchema.deprecationMessage = deprecationMessage;
|
||||
}
|
||||
propertySchema.markdownDescription = localize('iconPreview', "Current icon: {0}", `$(${id})`);
|
||||
this.iconSchema.properties[id] = propertySchema;
|
||||
this.iconReferenceSchema.enum.push(id);
|
||||
this.iconReferenceSchema.enumDescriptions.push(description);
|
||||
|
|
Loading…
Reference in a new issue