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

mdoc langserver integration #207

Open
jackcviers opened this issue Jun 4, 2021 · 3 comments
Open

mdoc langserver integration #207

jackcviers opened this issue Jun 4, 2021 · 3 comments

Comments

@jackcviers
Copy link

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
Copy link
Contributor

tgodzik commented Jun 4, 2021

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:

  • make Metals a markdown language server
  • check the document for snippets marked with scala and split them to multiple *.worksheet.sc virtual files
  • use worksheet support for those snippets and translate the positions to the original document to enable evaluation

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

@olafurpg
Copy link
Member

olafurpg commented Jun 4, 2021

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
Copy link

kubukoz commented May 4, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants