dustinblackman / languagetool-code-comments

languagetool-code-comments integrates the LanguageTool API to parse, spell check, and correct the grammar of your code comments!
MIT License
31 stars 4 forks source link

Adds Elixir comments #4

Closed georgeguimaraes closed 11 months ago

georgeguimaraes commented 11 months ago

Hi,

Thanks for the project. I was trying to add Elixir to it, but besides comments, Elixir also has documentation in the source code. (see test file for an example).

The query for highlighting documentation is in https://github.com/elixir-lang/tree-sitter-elixir/blob/a2861e88a730287a60c11ea9299c033c7d076e30/queries/highlights.scm#L7-L21

I added "quoted_content" to https://github.com/dustinblackman/languagetool-code-comments/blob/42b9c90e7d942063e6b58e7e7491d84fdaae979d/src/parse.rs#L337 , but unfortunately, that also matches the String "Hello, #{name}" in the test.

And that's where my knowledge of tree-sitter hits a wall.

Do you see a way to add those into languagetool-code-comments?

georgeguimaraes commented 11 months ago

Since these docs in Elixir are created with heredocs, which are just multiline strings, I think we can only support @moduledoc and @doc using the Query API from treesitter, but that would mean changing a lot of code in languagetool-code-comments.

Thoughts?

dustinblackman commented 11 months ago

Hey there @georgeguimaraes

This is a tricky one, I've struggled doing something similar with Python's inline docs and haven't found a solid solution for it myself. Currently the tool just handles the most basic extractions from TreeSitter. My lazy attempt at something more advanced with Astro's syntax just ended up being ugly. A decent refactor is gonna be needed, and Elixer is a good example to set expectations.

Otherwise unfortunately I don't have a decent recommendation to move forward. I myself need some time to think what the next evolution of parsing TreeSitter looks like.

georgeguimaraes commented 11 months ago

Hi,

I see.

I found out https://github.com/jmbuhr/otter.nvim, which means I can use LSPs from Markdown in these @moduledoc and @doc, but since otter uses Treesitter's injected language feature, it can't work with simple comments like language-tool-code-comments.

Well, if you're up to it, we can make this PR only work with code comments (#) in Elixir, and forget code documentation (@moduledoc and @doc) for now.

georgeguimaraes commented 11 months ago

Anyway, feel free to close this PR, of course! :)

dustinblackman commented 11 months ago

Nice! Otter looks cool. I'm going to dig in to that tomorrow.

And sure I'd be happy to accept just the first step to get Elixer on board. :)

georgeguimaraes commented 11 months ago

Done!

I've removed @moduledoc and @doc from the test, so that it makes it clear that we don't expect it to be parsed.

Btw, in Elixir, people call that code documentation, instead of code comments. So we can say that we are indeed parsing all Elixir code comments :)

dustinblackman commented 11 months ago

Amazing, great stuff. Thank you very much!