Merge pull request #114 from remcohaszing/remove-hover-content-checks

Remove checks for hover content
This commit is contained in:
Remco Haszing 2021-10-02 16:16:00 +02:00 committed by GitHub
commit 0f2e5536bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,7 +1,6 @@
import {
editor,
IDisposable,
IMarkdownString,
languages,
MarkerSeverity,
Position,
@ -253,42 +252,6 @@ export function createCompletionItemProvider(
};
}
function isMarkupContent(thing: unknown): thing is ls.MarkupContent {
return thing && typeof thing === 'object' && typeof (thing as ls.MarkupContent).kind === 'string';
}
function toMarkdownString(entry: ls.MarkedString | ls.MarkupContent): IMarkdownString {
if (typeof entry === 'string') {
return {
value: entry,
};
}
if (isMarkupContent(entry)) {
if (entry.kind === 'plaintext') {
return {
value: entry.value.replace(/[!#()*+.[\\\]_`{}-]/g, '\\$&'),
};
}
return {
value: entry.value,
};
}
return { value: `\`\`\`${entry.language}\n${entry.value}\n\`\`\`\n` };
}
function toMarkedStringArray(
contents: ls.MarkedString | ls.MarkedString[] | ls.MarkupContent,
): IMarkdownString[] {
if (!contents) {
return;
}
if (Array.isArray(contents)) {
return contents.map(toMarkdownString);
}
return [toMarkdownString(contents)];
}
// --- hover ------
export function createHoverProvider(getWorker: WorkerAccessor): languages.HoverProvider {
@ -303,7 +266,7 @@ export function createHoverProvider(getWorker: WorkerAccessor): languages.HoverP
}
return {
range: toRange(info.range),
contents: toMarkedStringArray(info.contents),
contents: [{ value: (info.contents as ls.MarkupContent).value }],
};
},
};