diff --git a/lib/index.js b/lib/index.js index 84332c7..8ece8dc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -572,21 +572,58 @@ class RustLanguageClient extends AutoLanguageClient { return provide } - // Workaround #133 that affects stable rust 1.35.0 - async getCodeFormat(...args) { - const edits = await super.getCodeFormat(...args) - for (const edit of edits) { - const end = edit && edit.oldRange && edit.oldRange.end - if (end && end.column > 18e18) { - end.row += 1 - end.column = 0 - edit.newText += (process.platform === "win32" ? "\r\n" : "\n") + /** + * Extend base-class to workaround the limited markdown support. + * @param {TextEditor} editor + * @param {Point} point + * @returns {Promise} + */ + async getDatatip(editor, ...args) { + let datatip = await super.getDatatip(editor, ...args) + try { + if (datatip) { + datatip.markedStrings = datatip.markedStrings + .flatMap(m => { + if (!m.grammar && m.type === "markdown" && m.value) { + return convertMarkdownToSnippets(m.value) + } else { + return m + } + }) + .filter(m => m.value) } + } catch (e) { + console.error("Error processing datatip", e) } - return edits + return datatip } } +/** + * Convert "foo\n```rust\nHashSet\n```\nbar" + * to [{type: "markdown", value: "foo"}, {type:"snippet", value: "HashSet", ...}, ...] + * @param {string} value + * @returns {object[]} + */ +function convertMarkdownToSnippets(value) { + // even indices are text, odds are rust snippets + return value.split(/\s*```rust\s*((?:.|\s)+?)\s*```/) + .map((bit, index) => { + if (index % 2 == 0) { + return { + type: "markdown", + value: bit, + } + } else { + return { + type: "snippet", + grammar: atom.grammars.grammarForScopeName("source.rust"), + value: bit, + } + } + }) +} + // override windows specific implementations if (process.platform === "win32") { // handle different slashes