mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Python: inject rst in docstrings (#917)
Since hasn't been much discussion around https://github.com/nvim-treesitter/nvim-treesitter/issues/806. I'm just porting the injection queries. I've been using this for a while now. Things I've noticed: - Due that rst uses indentation for its syntax, everything is treated as an block quote (but it looks good). This can be solved by having a predicate like `#dedent!`. - Looks like there is a bug in how the injected content is extracted ``` def foo(): """Foo bar""" ``` That would be parsed as a section title for some reason, but it's a paragraph. In rst it would be a title if the content was: ``` """ Foo bar """ ``` If the content is ``` """Foo bar""" ``` That's just a paragraph. I'll try to debug that from the neovim side next week or so.
This commit is contained in:
parent
9385413597
commit
af36d31cb7
1 changed files with 18 additions and 0 deletions
|
|
@ -4,3 +4,21 @@
|
|||
arguments: (argument_list (string) @regex))
|
||||
(#eq? @_re "re")
|
||||
(#match? @regex "^r.*"))
|
||||
|
||||
; Module docstring
|
||||
((module . (expression_statement (string) @rst))
|
||||
(#offset! @rst 0 3 0 -3))
|
||||
|
||||
; Class docstring
|
||||
((class_definition
|
||||
body: (block . (expression_statement (string) @rst)))
|
||||
(#offset! @rst 0 3 0 -3))
|
||||
|
||||
; Function/method docstring
|
||||
((function_definition
|
||||
body: (block . (expression_statement (string) @rst)))
|
||||
(#offset! @rst 0 3 0 -3))
|
||||
|
||||
; Attribute docstring
|
||||
(((expression_statement (assignment)) . (expression_statement (string) @rst))
|
||||
(#offset! @rst 0 3 0 -3))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue