vscode-elixir-ls
vscode-elixir-ls copied to clipboard
VSCode does not recognize heredocs as markdown, and highlight/lint appropriately
Is this the right repo?
I believe this is the right repo, as the issue, as the issue I'm observing is related to syntax highlighting in VSCode.
Environment
- Elixir & Erlang versions (elixir --version): Erlang/OTP 23 [erts-11.2.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1]
Elixir 1.12.0 (compiled with Erlang/OTP 23)
- VSCode ElixirLS version: 0.13.0
- Operating System Version: darwin 21.2.0
Troubleshooting
- [X] Restart your editor (which will restart ElixirLS) sometimes fixes issues
- [X] Stop your editor, remove the entire
.elixir_lsdirectory, then restart your editor
Crash report template
No Crash
Description
When working in elixir files with @moduledoc and @doc attributes, they are not recognized as markdown. VSCode doesn't lint them appropriately, and there's no obvious way to provide appropriate previews of the files.
I'm not sure if this is a new feature, or a bug.
I've reviewed some of the code that appears to define this. I suspect this is defined in:
https://github.com/elixir-lsp/vscode-elixir-ls/blob/master/elixir-language-configuration.json
and
https://github.com/elixir-lsp/vscode-elixir-ls/blob/master/syntaxes/elixir.json
However, I'm quite uninitiated here, so I don't know what I'm looking at. There appear to be some accomodations for @moduledoc and @doc attributes, but I'm not sure if they are correct.
I pulled down elixir-ls locally and built, and tried changing the name of some of the moduledoc patterns in elixir.json to comment.documentation.heredoc.elixir.markdown. It didn't do everything I wanted it to.
This can be achieved with an injection grammar
With the changes from https://github.com/elixir-lsp/vscode-elixir-ls/commit/9b7f43d7d673a76fb3530e8e262c657529a8b88a docstrings are now recognized as markdown.
Markdown refactorings now work as well
But I didn't find a way to enable preview and diagnostics. Probably the only way would be to extend the language server to handle those but I'm afraid it's out of scope
I had to partially revert https://github.com/elixir-lsp/vscode-elixir-ls/commit/9b7f43d7d673a76fb3530e8e262c657529a8b88a in https://github.com/elixir-lsp/vscode-elixir-ls/commit/3e5c623a16305d86658b396e03299b74531b2f58. This introduced problems with end of heredoc matching https://github.com/elixir-lsp/vscode-elixir-ls/issues/344#issuecomment-1598875663, https://github.com/elixir-lsp/elixir-ls/issues/911, https://github.com/elixir-lsp/vscode-elixir-ls/issues/344#issuecomment-1600701761.
I couldn't find a workaround. Probably to handle it correctly we need a dedicated grammar for markdown heredocs. A good starting point would be forking https://github.com/microsoft/vscode-markdown-tm-grammar
It seems that dedicated grammar is indeed needed as one could interpolate elixir code into docstrings, i.e.
defmodule A do
alias Smth.Smth
@moduledoc """
Module description....
Does smth with `#{inspect Smth}`
"""
end