Skip to content

Commit 7de1b0c

Browse files
committed
feat(lsp): derive code-hint signature highlighting from the file language
The signature block in the completion doc popup was hard-wired to ```typescript. The LSP `detail` string carries no language tag, so derive the highlight language from the active editor instead. The JS family maps to ts/tsx because vtsls emits TypeScript-syntax signatures even in .js/.jsx (TS is a superset); every other language uses its own id, and _highlightCode no-ops gracefully for ids hljs doesn't know.
1 parent 7f17ce0 commit 7de1b0c

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/languageTools/DefaultProviders.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,27 @@ define(function (require, exports, module) {
153153
}
154154
}
155155

156+
// Highlight.js language for the signature block, derived from the file being edited so it isn't
157+
// hard-wired to one language. The LSP `detail` string carries no language tag, so we use the
158+
// editor's. vtsls emits TypeScript-syntax signatures even in .js/.jsx (TS is a superset), so map
159+
// the JS family to ts/tsx; every other language uses its own id - hljs resolves many aliases, and
160+
// _highlightCode no-ops gracefully when the id is unknown (the block just renders as monospace).
161+
var SIGNATURE_HLJS_LANG = {
162+
javascript: "typescript",
163+
jsx: "tsx",
164+
typescript: "typescript",
165+
tsx: "tsx"
166+
};
167+
168+
function _signatureLang() {
169+
var editor = EditorManager.getActiveEditor();
170+
var id = editor && editor.getLanguageForSelection && editor.getLanguageForSelection().getId();
171+
if (!id) {
172+
return "typescript";
173+
}
174+
return SIGNATURE_HLJS_LANG[id] || id;
175+
}
176+
156177
// Build the side doc popup's content, like VS Code/WebStorm's details panel: the item's
157178
// signature (token.detail) as a highlighted code block - the focal point - followed by the
158179
// prose documentation. The signature already carries the "Add import from <module>" line for
@@ -163,7 +184,7 @@ define(function (require, exports, module) {
163184

164185
if (token.detail) {
165186
try {
166-
parts.push(_highlightCode(marked.parse("```typescript\n" + token.detail + "\n```")));
187+
parts.push(_highlightCode(marked.parse("```" + _signatureLang() + "\n" + token.detail + "\n```")));
167188
} catch (e) {
168189
// skip the signature block on any parse/highlight error
169190
}

0 commit comments

Comments
 (0)