aboutsummaryrefslogtreecommitdiffstats
path: root/queries/python/injections.scm
diff options
context:
space:
mode:
authorSantos Gallegos <stsewd@protonmail.com>2021-02-05 10:01:50 -0500
committerGitHub <noreply@github.com>2021-02-05 15:01:50 +0000
commitaf36d31cb773e3ffe69b75a12ca39419de4dc801 (patch)
tree0756bf469228b7943f4cb1145e2525ee5c1658a9 /queries/python/injections.scm
parentUpdate lockfile.json and `amount` query for ledger (diff)
downloadnvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.tar
nvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.tar.gz
nvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.tar.bz2
nvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.tar.lz
nvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.tar.xz
nvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.tar.zst
nvim-treesitter-af36d31cb773e3ffe69b75a12ca39419de4dc801.zip
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.
Diffstat (limited to 'queries/python/injections.scm')
-rw-r--r--queries/python/injections.scm18
1 files changed, 18 insertions, 0 deletions
diff --git a/queries/python/injections.scm b/queries/python/injections.scm
index feec13f73..de108262d 100644
--- a/queries/python/injections.scm
+++ b/queries/python/injections.scm
@@ -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))