Skip to content

Commit 88173a2

Browse files
author
Andreas Gerlach
committed
fix: multiple items of same type in datatip; preamble in snippets
1 parent a0ff0f4 commit 88173a2

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

lib/datatip-manager.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ module.exports = class DatatipManager {
313313
}
314314
else if (datatip.markedStrings.length > 0) {
315315
const grammar = editor.getGrammar().name.toLowerCase();
316-
const snippetHtml = await this.getSnippetHtml(datatip.markedStrings.filter(t => t.type === 'snippet').map(t => t.value).shift(), grammar);
317-
const documentationHtml = await this.getDocumentationHtml(datatip.markedStrings.filter(t => t.type === 'markdown').map(t => t.value).shift(), grammar);
316+
const snippetHtml = await this.getSnippetHtml(datatip.markedStrings.filter(t => t.type === 'snippet').map(t => t.value), grammar);
317+
const documentationHtml = await this.getDocumentationHtml(datatip.markedStrings.filter(t => t.type === 'markdown').map(t => t.value), grammar);
318318
const dataTipView = new DataTipView({ snippet: snippetHtml, html: documentationHtml });
319319
this.dataTipMarkerDisposables = this.mountDataTipWithMarker(editor, datatip.range, position, dataTipView);
320320
}
@@ -327,33 +327,37 @@ module.exports = class DatatipManager {
327327

328328
/**
329329
* converts a given code snippet into syntax formatted HTML
330-
* @param {String} snippet the code snippet to be converted
330+
* @param {Array<String>} snippets the code snippet to be converted
331331
* @param {String} grammarName the name of the grammar to be used for syntax highlighting
332332
* @return {Promise<string>} a promise object to track the asynchronous operation
333333
*/
334-
async getSnippetHtml(snippet, grammarName) {
335-
if ((snippet !== undefined) && (snippet.length > 0)) {
334+
async getSnippetHtml(snippets, grammarName) {
335+
if ((snippets !== undefined) && (snippets.length > 0)) {
336336
const regExpLSPPrefix = /^\((method|property|parameter|alias)\)\W/;
337-
const preElem = document.createElement('pre');
338-
const codeElem = document.createElement('code');
339-
340-
codeElem.classList.add(grammarName);
341-
codeElem.innerText = snippet.replace(regExpLSPPrefix, '');
342-
preElem.appendChild(codeElem);
343-
344-
return this.renderer.render(preElem.outerHTML, grammarName);
337+
const divElem = document.createElement('div');
338+
snippets.forEach((snippet) => {
339+
const preElem = document.createElement('pre');
340+
const codeElem = document.createElement('code');
341+
snippet = snippet.replace(/^\s*<!([a-zA-Z]+)?\s*/i, ''); // remove any preamble from the line
342+
codeElem.classList.add(grammarName);
343+
codeElem.innerText = snippet.replace(regExpLSPPrefix, '');
344+
preElem.appendChild(codeElem);
345+
divElem.appendChild(preElem);
346+
});
347+
return this.renderer.render(divElem.outerHTML, grammarName);
345348
}
346349
return null;
347350
}
348351

349352
/**
350353
* convert the markdown documentation to HTML
351-
* @param {String} markdownText the documentation text in markdown format to be converted
354+
* @param {Array<String>} markdownTexts the documentation text in markdown format to be converted
352355
* @param {String} grammarName the default grammar used for embedded code samples
353356
* @return {Promise<string>} a promise object to track the asynchronous operation
354357
*/
355-
async getDocumentationHtml(markdownText, grammarName) {
356-
if ((markdownText !== undefined) && (markdownText.length > 0)) {
358+
async getDocumentationHtml(markdownTexts, grammarName) {
359+
if ((markdownTexts !== undefined) && (markdownTexts.length > 0)) {
360+
const markdownText = markdownTexts.join("\r\n");
357361
return this.renderer.render(markdownText, grammarName);
358362
}
359363
return null;

0 commit comments

Comments
 (0)