scalameta / metals-feature-requests

Issue tracker for Metals feature requests
37 stars 4 forks source link

mdoc langserver integration #207

Open jackcviers opened 3 years ago

jackcviers commented 3 years ago

Is your feature request related to a problem? Please describe. When editing mdoc documentation, scala code in the mdoc is not interactive. No error diagnostic information, code completion, code navigation currently exists.

Describe the solution you'd like When editing mdoc documentation, I want my scala code to have the same interactive features present in a regular scala buffer. I'd like live preview of the documentation available as well (as an emacs user markdown-mode provides preview on-demand with markdown-preview, but when I pair in vscode it would be nice to have).

Describe alternatives you've considered Write the document wrapped in comments inside a .scala file, then automatically remove the scala package object wrapper from the file and uncomment the markdown lines and change the file extension on save inside of an sbt project. While this works, it's pretty hacky.

Additional context

Search terms: metals-mdoc mdoc metals mdoc-integration

tgodzik commented 3 years ago

Thanks for reporting! This might not be possible using LSP at this moment (or at least he solution might not be that elegant), since we would need to support the markdown files fully and I am not sure if that would not interfere with other possible markdown language server. It might be possible, but that would require some experimentation.

I think a more elegant solution would be to fix it on the editor side. Whenever a snippet with a language is picked up, the editor should ask the proper language server if that is available.

But that might never happen, so a possible solution, that I was thinking of, would be to:

Or something along these lines. We could also add support for modifiers, since worksheets support them now.

olafurpg commented 3 years ago

check the document for snippets marked with scala and split them to multiple *.worksheet.sc virtual files

Metals should only have to look for the “mdoc” modifier and pass the plain markdown file directly to mdoc to get 1) diagnostics, 2) the rendered markdown output and optionally 3) the evaluated expressions for decorations. It might even be able to provide the instrumented source code that Metals can use for completions (might be necessary for full compatibility with modifiers like mdoc:nest or mdoc:reset, which impact scoping rules).

kubukoz commented 1 year ago

if you ask me, just diagnostics would be a great start :)