haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Syntax highlighting in doctest comments?

Open konn opened this issue 5 years ago • 5 comments

I've been using the Eval Plugin of HLS, which provides us with a pleasant alternative for REPL. That plugin provides a way to evaluate (or execute some simple ghci-like commands such as type) codes in doctest style comment: -- >>>. The result is appended as line comments right after the doctest comments.

In some situation, both of the inputs and outputs of doctest comments can be relatively long. I think it might be useful if VSCode also highlights the contents inside the doctest comments and comments that immediately follow.

In short: currently, we have the following:

スクリーンショット 2020-09-20 0 15 20

And it might be good if this becomes (with a less bright colour than in the standard code block):

スクリーンショット 2020-09-20 0 15 20-high

If I understand correctly, there is a VSCode API to change text-decorations dynamically. Or, perhaps this should be resolved upstream, i.e. might be reported to JustusAdam/language-haskell?

konn avatar Sep 19 '20 15:09 konn

It seems that the upcoming LSP 3.16 specification includes semantic highlighting. If this is once released and implemented in lsp-types, we will be able to implement this feature upstream; i.e. in HLS, in an editor-agnostic manner (provided that the editor being used supports that spec, of course)!

So, it might be preferrable to close this issue or transfer to HLS once the situation get ready.

konn avatar Dec 04 '20 14:12 konn

this is blocked upstream on semantic highlighting support in lsp (lsp 3.16 spec was released)

jneira avatar Mar 09 '21 07:03 jneira

We have semantic highlighting now. However, I suspect a major problem would be figuring out what the elements in the comment actually are!

michaelpj avatar Jan 11 '24 09:01 michaelpj

Haddock has inline code markup, so maybe we can wrap the output in that and let LSP (or even treesitter) do the highlighting. It also should be morally correct since lawful Show should produce correct Haskell expressions.

Anrock avatar Jan 11 '24 10:01 Anrock

Semantic tokens currently picks identifier(mostly names) from hieAst.
The cheapest way is to figure out how to get the identifiers in the doctest comment into hieast, then highlight would be automatically supported. The same way as the semantic highlights in the code section of doc is automatically supportted now.

image

Any know where the token of code section of doc is inserted into the hieast ? maybe we can do the same thing

soulomoon avatar Jan 16 '24 08:01 soulomoon