feat(py) Add support for file type (#31)
This commit is contained in:
@@ -179,7 +179,7 @@ There is a list of supported languages and fields, with their annotation style
|
|||||||
| lua | | | `func`, `class`, `type` |
|
| lua | | | `func`, `class`, `type` |
|
||||||
| | [Emmylua](https://emmylua.github.io/) (`"emmylua"`) | `@param`, `@varargs`, `@return`, `@class`, `@type` |
|
| | [Emmylua](https://emmylua.github.io/) (`"emmylua"`) | `@param`, `@varargs`, `@return`, `@class`, `@type` |
|
||||||
| | [Ldoc](https://stevedonovan.github.io/ldoc/manual/doc.md.html) (`"ldoc"`) | `@param`, `@varargs`, `@return`, `@class`, `@type` |
|
| | [Ldoc](https://stevedonovan.github.io/ldoc/manual/doc.md.html) (`"ldoc"`) | `@param`, `@varargs`, `@return`, `@class`, `@type` |
|
||||||
| python | | | `func`, `class` |
|
| python | | | `func`, `class`, `file` |
|
||||||
| | [Google docstrings](https://google.github.io/styleguide/pyguide.html) (`"google_docstrings"`) | `Args`, `Attributes`, `Returns` |
|
| | [Google docstrings](https://google.github.io/styleguide/pyguide.html) (`"google_docstrings"`) | `Args`, `Attributes`, `Returns` |
|
||||||
| | [Numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) (`"numpydoc"`)| `Arguments`, `Attributes`, `Returns`|
|
| | [Numpydoc](https://numpydoc.readthedocs.io/en/latest/format.html) (`"numpydoc"`)| `Arguments`, `Attributes`, `Returns`|
|
||||||
| javascript | | | `func`, `class` |
|
| javascript | | | `func`, `class` |
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ local ts_utils = require("nvim-treesitter.ts_utils")
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
-- Search for these nodes
|
-- Search for these nodes
|
||||||
parent = { func = { "function_definition" }, class = { "class_definition" } },
|
parent = { func = { "function_definition" }, class = { "class_definition" }, file = { "module" } },
|
||||||
|
|
||||||
-- Traverse down these nodes and extract the information as necessary
|
-- Traverse down these nodes and extract the information as necessary
|
||||||
data = {
|
data = {
|
||||||
@@ -101,6 +101,15 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
file = {
|
||||||
|
["module"] = {
|
||||||
|
["0"] = {
|
||||||
|
extract = function()
|
||||||
|
return {}
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Use default granulator and generator
|
-- Use default granulator and generator
|
||||||
@@ -113,16 +122,28 @@ return {
|
|||||||
append = { position = "after", child_name = "block" }, -- optional: where to append the text (default_generator)
|
append = { position = "after", child_name = "block" }, -- optional: where to append the text (default_generator)
|
||||||
use_default_comment = false, -- If you want to prefix the template with the default comment for the language, e.g for python: # (default_generator)
|
use_default_comment = false, -- If you want to prefix the template with the default comment for the language, e.g for python: # (default_generator)
|
||||||
google_docstrings = {
|
google_docstrings = {
|
||||||
|
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "$1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, '"""', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
{ nil, '"""$1' },
|
{ nil, '"""$1' },
|
||||||
{ nil, '""" $1 """', { no_results = true } },
|
|
||||||
{ "parameters", "\t%s: $1", { before_first_item = { "", "Args:" } } },
|
{ "parameters", "\t%s: $1", { before_first_item = { "", "Args:" } } },
|
||||||
{ "attributes", "\t%s: $1", { before_first_item = { "", "Attributes: " } } },
|
{ "attributes", "\t%s: $1", { before_first_item = { "", "Attributes: " } } },
|
||||||
{ "return_statement", "\t$1", { before_first_item = { "", "Returns: " } } },
|
{ "return_statement", "\t$1", { before_first_item = { "", "Returns: " } } },
|
||||||
{ nil, '"""' },
|
{ nil, '"""' },
|
||||||
},
|
},
|
||||||
numpydoc = {
|
numpydoc = {
|
||||||
|
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "$1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, '"""', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
{ nil, '"""$1' },
|
{ nil, '"""$1' },
|
||||||
{ nil, '""" $1 """', { no_results = true } },
|
|
||||||
{ "parameters", "%s: $1", { before_first_item = { "", "Parameters", "----------" } } },
|
{ "parameters", "%s: $1", { before_first_item = { "", "Parameters", "----------" } } },
|
||||||
{ "attributes", "%s: $1", { before_first_item = { "", "Attributes", "----------" } } },
|
{ "attributes", "%s: $1", { before_first_item = { "", "Attributes", "----------" } } },
|
||||||
{ "return_statement", "$1", { before_first_item = { "", "Returns", "-------" } } },
|
{ "return_statement", "$1", { before_first_item = { "", "Returns", "-------" } } },
|
||||||
|
|||||||
Reference in New Issue
Block a user