Improve hover tool tips and function docs (#5538)

* Improve hover tool tips and function docs

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)

* A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores)

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Nick Cameron
2025-02-27 22:03:37 +13:00
committed by GitHub
parent 2efea3ec06
commit 1104d908c0
71 changed files with 390 additions and 88 deletions

View File

@ -28,6 +28,7 @@ export default function lspHoverExt(
'.cm-tooltip': {
fontSize: '12px',
maxWidth: '400px',
padding: '2px',
},
}),
]

View File

@ -1,5 +1,5 @@
import { Text } from '@codemirror/state'
import { Marked } from '@ts-stack/markdown'
import { Marked, MarkedOptions } from '@ts-stack/markdown'
import type * as LSP from 'vscode-languageserver-protocol'
import { isArray } from '../lib/utils'
@ -43,14 +43,18 @@ export function offsetToPos(doc: Text, offset: number) {
}
}
const markedOptions: MarkedOptions = {
gfm: true,
}
export function formatMarkdownContents(
contents: LSP.MarkupContent | LSP.MarkedString | LSP.MarkedString[]
): string {
if (isArray(contents)) {
return contents.map((c) => formatMarkdownContents(c) + '\n\n').join('')
} else if (typeof contents === 'string') {
return Marked.parse(contents)
return Marked.parse(contents, markedOptions)
} else {
return Marked.parse(contents.value)
return Marked.parse(contents.value, markedOptions)
}
}