-
Notifications
You must be signed in to change notification settings - Fork 40
Support highlighting Markdown/RST in comments #665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Note: this is a rather large PR, see individual commits to get more digestible diffs. |
Sorry, but I do not agree with any changes to the AST, especially those that use regular expressions to match and modify the usage of regions. |
I can redo those without regexes, but might you tell me what exactly you disagree with and why?
|
...
|
You just want to highlight the documentation in comments, so you only need to parse the comments once during semantic token request and highlight them in the appropriate places, rather than modifying the entire structure of the syntax tree. |
Hm, I see your point. I can implement this. Although there will be complications if we want to support Go To Definition in comments. I see it like this:
Would you agree with this implementation? |
This is a multithreaded language server, and caching introduces data races |
Even if you re-parse everything, it will still be faster than using a cache. |
Comment markup cache doesn't need its own AST, it will only save highlighted ranges. |
I can make cache async/multi-threaded, that's not a big issue.
That's possible, I'll need to benchmark this. |
I'll start with re-parsing on every request, and see if caching is warranted later. Two more questions:
|
5cb40f6
to
13a4679
Compare
Reworked this PR to avoid changes to AST. Caching wasn't required, it's fast enough to re-parse docs on every relevant request. |
When the code block area uses Lua syntax, should we use luaLexer to parse it and highlight keywords, strings, and numbers? |
I got error:
---```lua
---
--- local t = 213
---```
---
--- .. code-block:: lua
---
--- local t = 123
--- yes = 1123
local t = 123
|
Fixed bugs, added more tests, implemented autocomplete for ref targets, improved go to definition to handle modules. |
Just for context, is that because highlighting in comments is distracting for some people, or are there other concerns?
I've disabled highlighting for any comment that doesn't start with three dashes. It should also detect comment blocks adorned with long dashed lines: --------------- <- not highlighted
--- Comment <- highlighted
--------------- <- highlighted
--- Comment <- highlighted
--------------- <- not highlighted
--------------- <- not highlighted
-- Comment <- not highlighted
--------------- <- not highlighted
-- Comment 2 <- not highlighted
--------------- <- not highlighted
Yes. Also, |
Yes, and I've also had someone say they want treesitter (which has more highlights and is faster) to handle this kind of highlighting, not the server. |
Then there should be a way to disable highlighting even if |
I ran parsing and completions on my codebase, fixed some minor things. I believe I've done all features I wanted for this PR, it's ready for merge. In next PR I'll add option to force-disable markdown parsing even if |
Please don't invent new off-spec options that only VS Code is set up to handle it. It's enough to make this opt-in via If you want to do anything, split the I would also (strongly) recommend to name and structure the options in a way to make clear that they relate to semantic tokens. You probably also want to document the (off-spec?) tokens you send for documentation. |
Do you think it's needed? I like this idea, but I don't have a strong opinion here.
It's not just semantic tokens, though, but also hovers, completion, text ranges, and go to definition. Plus, option names must reflect that they affect highlighting markup within descriptions, and don't affect highlighting So, this is what I propose then (ideas for better naming are welcome):
As for defaults, I want to avoid scenario where a user sets
With settings being more granular this is indeed not necessary. Bear in mind, though, that there's already lots of off-spec things happening in VSCode extension, mostly because (1) VSCode doesn't support overlapping semantic tokens, and (2) VSCode doesn't allow customizing LSP configuration call the same way neovim does. So some changes will have to be made regardless.
Actually, no off-spec tokens so far. Maybe I'll add some for italic/bold text, but that will be later). |
I don't think the "active" LSP features need to be opt-in, as they need to be actively triggered on a documentation location anyway. (It would be different if references also included documentation locations -- which I feel they shouldn't either way.) I still -- strongly -- recommend the option split, since the syntax format is a project choice while the highlighting is a user choice. This needs to be respected. If this requires making doc semantic tokens opt-out, so be it. And I understand that the extension needs special support for this; that is fine. I amjust concerned with the server configuration not being driven by that -- everything should be (also) configurable through standard interfaces (config file and ConfigurationChanged notifications). |
Right now, our LSP only requests settings when client is VSCode or Neovim. To make matters worse, it requests *different* settings for these clients: - for VSCode, it requests VSCode-specific about files and extensions, - for Neovim, it requests settings in scope `"Lua"`, and uses them as overrides for `.emmyrc`. This PR aims to unify this behavior and make it easier for users to override settings without having to create `.emmyrc.json`. This is especially handy when you want to override a setting for a single project, but don't want to change project's `.emmyrc.json`. For example, switching documentation highlighting on per-project basis will become easier (see EmmyLuaLs#665). # Changes - When client is VSCode, LSP will request settings under `"emmylua.rc"` scope, as well as VSCode-specific settings mentioned above. I'll add `"emmylua.rc"` category to the plugin settings page in a separate PR when this is merged; until then, these changes will not affect user experience. - When client is Neovim, LSP will request settings under `"emmylua.rc"` scope. If there's no settings under this scope, it will fall back to using the `"Lua"` scope. Currently, both LuaLs and EmmyLua use the same scope `"Lua"`. This is good for backwards compatibility and for users switching from one to another, but risks introducing forward incompatibilities in the long run. The new option will allow users to configure EmmyLua without affecting LuaLs. I'll send a PR to update nvim-lspconfig's documentation for EmmyLua when this is merged. - For any other client, LSP will request settings under `"emmylua.rc"` scope. Currently, there are no clients that provide this scope (EmmyLua2 for Intellij doesn't provide any config scopes), so it shouldn't break anything, but it will provide future client implementations with a better way to override LSP configuration.
Right now, our LSP only requests settings when client is VSCode or Neovim. To make matters worse, it requests *different* settings for these clients: - for VSCode, it requests VSCode-specific about files and extensions, - for Neovim, it requests settings in scope `"Lua"`, and uses them as overrides for `.emmyrc`. This PR aims to unify this behavior and make it easier for users to override settings without having to create `.emmyrc.json`. This is especially handy when you want to override a setting for a single project, but don't want to change project's `.emmyrc.json`. For example, switching documentation highlighting on per-project basis will become easier (see discussion in EmmyLuaLs#665). # Changes - When client is VSCode, LSP will request settings under `"emmylua"` scope, as well as VSCode-specific settings mentioned above. I'll add relevant settings to the plugin settings page in a separate PR when this is merged; until then, these changes will not affect user experience. - When client is Neovim, LSP will request settings under `"emmylua"` scope. If there's no such scope, it will fall back to using the `"Lua"` scope. Currently, both LuaLs and EmmyLua use the same scope `"Lua"`. This is good for backwards compatibility and for users switching from one to another, but risks introducing forward incompatibilities in the long run. The new option will allow users to configure EmmyLua without affecting LuaLs. I'll send a PR to update nvim-lspconfig's documentation for EmmyLua when this is merged. - For any other client, LSP will request settings under `"emmylua"` scope. Currently, there are no clients that provide this scope (EmmyLua2 for Intellij doesn't provide any config scopes), so it shouldn't break anything, but it will provide future client implementations with a better way to override LSP configuration.
Added The reason for this name is for consistency with possible future options. For example, currently we don't provide
I've created #680 to address this issue. When it's merged, VSCode and NeoVim (and other editors) will be able to configure things using the same mechanism. |
Right now, our LSP only requests settings when client is VSCode or NeoVim. To make matters worse, it requests *different* settings for these clients: - for VSCode, it requests VSCode-specific about files and extensions, - for NeoVim, it requests settings in scope `"Lua"`, and uses them as overrides for `.emmyrc`. This PR aims to unify this behavior and make it easier for users to override settings without having to create `.emmyrc.json`. This is especially handy when you want to override a setting for a single project, but don't want to change project's `.emmyrc.json`. For example, switching documentation highlighting on per-project basis will become easier (see discussion in EmmyLuaLs#665). # Changes - When client is VSCode, LSP will request settings under `"emmylua"` scope, as well as VSCode-specific settings mentioned above. I'll add relevant settings to the plugin settings page in a separate PR when this is merged; until then, these changes will not affect user experience. - When client is NeoVim, LSP will request settings under `"emmylua"` scope. If there's no such scope, it will fall back to using the `"Lua"` scope. Currently, both LuaLs and EmmyLua use the same scope `"Lua"`. It works in NeoVim because options for every LSP server are independent. In VSCode, however, they all share the same namespace, meaning that we can't reuse `"Lua"`. I'd like to keep things consistent, hence this rename. I'll send a PR to update nvim-lspconfig's documentation for EmmyLua when this is merged. - For any other client, LSP will request settings under `"emmylua"` scope. Currently, there are no clients that provide this scope (EmmyLua2 for Intellij doesn't provide any config scopes), so it shouldn't break anything, but it will provide future client implementations with a better way to override LSP configuration. # Tests Tested this with VSCode and NeoVim.
please resolve conflicts |
If everything works well, I will merge it before the release tomorrow, but please resolve the conflicts first. |
Simplify reader's implementation, rename methods to be more consistent, add 1-character lookbehind support, expose unconsumed (tail) range and text.
Fix lifetimes, fix `current_token_range` not being reset.
This will allow parsing code snippets in comments line-by-line.
See more info in PR or merge commit.
Rebased. Since you want to release tomorrow, I've also added support for bold/italic highlighting via emmy annotator, see also EmmyLua/VSCode-EmmyLua#248. |
This PR adds an optional feature that highlights Markdown, MySt (a Markdown extension used with Sphinx), and RST syntax in comments and provides Go To Definition implementation for cross-references. This feature is disabled by default; it can be enabled by specifying
doc.syntax
in.emmyrc.json
.Caveats