Skip to content
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

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

Open
2 tasks done
davenforce opened this issue Mar 30, 2023 · 8 comments
Open
2 tasks done
Labels
help wanted Extra attention is needed

Comments

@davenforce
Copy link

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

  • Restart your editor (which will restart ElixirLS) sometimes fixes issues
  • 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
Copy link
Author

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.

@lukaszsamson
Copy link
Collaborator

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

lukaszsamson added a commit that referenced this issue Jun 4, 2023
make markdown an embedded language
Addresses #315
@lukaszsamson
Copy link
Collaborator

With the changes from 9b7f43d 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
Copy link
Collaborator

I had to partially revert 9b7f43d in 3e5c623.
This introduced problems with end of heredoc matching #344 (comment), elixir-lsp/elixir-ls#911, #344 (comment).

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 lukaszsamson reopened this Jun 22, 2023
@lukaszsamson lukaszsamson added the help wanted Extra attention is needed label Jun 22, 2023
@florius0
Copy link

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

@SteffenDE
Copy link

@lukaszsamson this should be fixable by using a while pattern:

diff --git a/syntaxes/elixir.json b/syntaxes/elixir.json
index 0e246ba..775118e 100644
--- a/syntaxes/elixir.json
+++ b/syntaxes/elixir.json
@@ -41,7 +41,11 @@
           "include": "#escaped_char"
         },
         {
-          "include": "text.html.markdown"
+          "begin": ".*",
+          "while": "(^|\\G)(?!\\s*\"\"\"\\s*$)",
+          "patterns": [
+            { "include": "text.html.markdown" }
+          ]
         }
       ]
     },
@@ -58,7 +62,11 @@
           "include": "#escaped_char"
         },
         {
-          "include": "text.html.markdown"
+          "begin": ".*",
+          "while": "(^|\\G)(?!\\s*'''\\s*$)",
+          "patterns": [
+            { "include": "text.html.markdown" }
+          ]
         }
       ]
     },
@@ -72,7 +80,11 @@
           "include": "#escaped_char"
         },
         {
-          "include": "text.html.markdown"
+          "begin": ".*",
+          "while": "(^|\\G)(?!\\s*\"\"\"\\s*$)",
+          "patterns": [
+            { "include": "text.html.markdown" }
+          ]
         }
       ]
     },
@@ -86,7 +98,11 @@
           "include": "#escaped_char"
         },
         {
-          "include": "text.html.markdown"
+          "begin": ".*",
+          "while": "(^|\\G)(?!\\s*'''\\s*$)",
+          "patterns": [
+            { "include": "text.html.markdown" }
+          ]
         }
       ]
     },

@SteffenDE
Copy link

Before:
image

After:
image

@lukaszsamson
Copy link
Collaborator

Nice. I'll give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants