emacs-vs / ts-docstr

A document string minor mode using tree-sitter
https://emacs-vs.github.io/ts-docstr/
GNU General Public License v3.0
39 stars 6 forks source link

Language is either not supported or WIP... c++mode #2

Open marlinstrub opened 1 year ago

marlinstrub commented 1 year ago

This package looks very promising. When I try ts-docstr-at-point I get the error Language is either not supported or WIP... c++mode.

I load tree-sitter and ts-docstr as follows:

(use-package tree-sitter
  :straight (tree-sitter :host github :repo "emacs-tree-sitter/elisp-tree-sitter"))

(use-package tree-sitter-langs
  :straight (tree-sitter-langs :host github :repo "emacs-tree-sitter/tree-sitter-langs"))

(use-package msgu
  :straight (msgu :host github :repo "jcs-elpa/msgu"))

(use-package ts-docstr 
  :straight (ts-docstr :host github :repo "emacs-vs/ts-docstr"))

I then visit a cpp file and call M-x ts-docstr-at-point on a function.

Am I doing this wrong?

jcs090218 commented 1 year ago

Make sure you have tree-sitter-mode enabled in your buffer!

marlinstrub commented 1 year ago

Ah my bad, I had indeed misconfigured tree-sitter. I think it's setup correctly now, at least syntax highlighting works with it.

I'm not sure if I'm using this package correctly though. Let me try to explain what I'm doing. I created a test file with the following content:

ss1

If I insert a new line above line 1 and type M-x ts-docstr-at-point I get the following:

ss2

If I then place the cursor on line 7 (above auto baz ...) and type M-x ts-docstr-at-point again, nothing happens.

I noticed that the syntax highlighting is wrong after the first invocation of ts-docstr-at-point. I can fix it by temporarily removing the second star of the opening comment identifier (/**). If I do that and then place the cursor on line 7 and type M-x ts-docstr-at-point again, another comment is inserted:

ss3

Notice how the syntax highlighting of that second comment is wrong again.

I observe the same behaviour when I try with emacs -Q and load only the relevant packages. I'm on emacs version 29.0.50 (commit 8a5678906f).

Any pointers on how to fix this behaviour are much appreciated!

jcs090218 commented 1 year ago

Yeah, I have the same experience and I suspect the issue is from the upstream tree-sitter-langs. I think if you edit buffer with or without this package you will experience something like that (any packages/operations that modified the buffer directly). Can you try and confirm the behavior?

Emacs devel is working on built-in tree-sitter, so I'm not quite sure the route of all tree-sitter packages (ts-docstr, ts-fold, tree-sitter-langs, etc). I think we will eventually replace all Elisp API with the built-in one. Then I guess this issue will then be resolved?

marlinstrub commented 1 year ago

Mhh. I don't use many packages that directly edit the buffer, but yasnippet works, for example. Did you have a particular package in mind that you wanted me to test?

I agree that it could well be a problem with upstream tree-sitter.

nicodebo commented 1 year ago

I think I have the same issue on python. After M-x ts-docstr-at-point the syntax highlighting seems to be broken in the whole buffer. After saving, the syntax highlighting is back to normal.

jcs090218 commented 1 year ago

We might need to refresh the AST or font-lock highlighting after the insertion.

ratnesh1729 commented 11 months ago

Thanks for the library. I face the same issue for python mode