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 4 forks source link

Python: inserted docstring's indentation off #3

Closed d-miketa closed 1 year ago

d-miketa commented 1 year ago

Hi, thanks for making this package available. I've been looking for something that supports Google-style docstrings for Python and this seems like the most promising choice going forward. I especially like the use of Treesitter underneath. It shows a lot of potential.

Unfortunately I can't quite get the package to work out of the box. I have set it up with 'google style Python docstrings and to trigger on typing """. The result ends up indented twice as much as it should be.

Starting from

image

And after writing """:

image

PS: I noticed you use the word "triggeration" in the README to refer to the activation of a trigger. The usual word for this is simply "triggering". Hope you don't mind the correction.

jcs090218 commented 1 year ago

I am not able to reproduce this bug. Can you try it in emacs -q?

PS: I noticed you use the word "triggeration" in the README to refer to the activation of a trigger. The usual word for this is simply "triggering". Hope you don't mind the correction.

No, I don't mind. 👍 Thank you for the correction!

d-miketa commented 1 year ago

Sorry for the long delay in responding.

I had trouble setting up ts-docstr within emacs -q; I use Doom Emacs and feel a bit useless without all the nice extras!

However, you may be able to reproduce the bug (in Python) by first indenting a little bit (try 4 spaces) and then writing the three quotes. One of my minor modes seems to be indenting me automatically while writing a function. So, if | represents my cursor:

class MyClass:
    def my_method(a:int) -> int:|

then hitting enter drops me to

class MyClass:
    def my_method(a:int) -> int:|
        |

and writing """ causes the issue described above:

class MyClass:
    def my_method(a:int) -> int:|
            """[summary]
            ...

Disabling dtrt-indent-mode increases the indentation to 8 spaces.

jcs090218 commented 1 year ago

Sorry for the late reply. I was very busy with other things. 😓

I don't have a clear idea to reproduce this, and not sure the relation regarding the package dtrt-indent-mode. I will investigate more once I have better idea. And feel free to report anything you found might causes this bug! Thank you!

jcs090218 commented 1 year ago

I've opened a PR in #6. I hope this will fix the issue for you, can you try pull the latest version? Thanks!

d-miketa commented 1 year ago

My turn to apologise for taking so long to test and reply. The issue seems to be resolved on the current version of main, thank you!! :)