vscode-elixir-ls icon indicating copy to clipboard operation
vscode-elixir-ls copied to clipboard

VSCode does not recognize heredocs as markdown, and highlight/lint appropriately

Open davenforce opened this issue 2 years ago • 8 comments

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_ls directory, 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.

davenforce avatar Mar 30 '23 18:03 davenforce

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.

davenforce avatar Mar 30 '23 20:03 davenforce

This can be achieved with an injection grammar Screenshot 2023-06-04 at 15 58 54

lukaszsamson avatar Jun 04 '23 14:06 lukaszsamson

With the changes from https://github.com/elixir-lsp/vscode-elixir-ls/commit/9b7f43d7d673a76fb3530e8e262c657529a8b88a docstrings are now recognized as markdown. Screenshot 2023-06-04 at 16 55 13 Markdown refactorings now work as well Screenshot 2023-06-04 at 16 55 55 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

lukaszsamson avatar Jun 04 '23 14:06 lukaszsamson

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

lukaszsamson avatar Jun 22 '23 06:06 lukaszsamson

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

florius0 avatar Jun 28 '23 08:06 florius0