Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Workaround missing markdown syntax highlighting #171

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<atomIde.Datatip | null>}
*/
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<u32, String>\n```\nbar"
* to [{type: "markdown", value: "foo"}, {type:"snippet", value: "HashSet<u32, String>", ...}, ...]
* @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
Expand Down