From e38e663dc124d9fa388fbb55277b1cf6612c53fd Mon Sep 17 00:00:00 2001 From: danymat Date: Tue, 8 Feb 2022 15:12:08 +0100 Subject: [PATCH] feat: Add support for `bash` (google shellguide) --- README.md | 1 + lua/neogen/configurations/sh.lua | 62 ++++++++++++++++++++++++++++ lua/neogen/templates/google_bash.lua | 18 ++++++++ 3 files changed, 81 insertions(+) create mode 100644 lua/neogen/configurations/sh.lua create mode 100644 lua/neogen/templates/google_bash.lua diff --git a/README.md b/README.md index b0451b7..c7ceef6 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ There is a list of supported languages and fields, with their annotation style | Languages | Annotation Conventions | Supported annotation types | | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- | +| sh | [Google Style Guide](https://google.github.io/styleguide/shellguide.html) (`"google_bash"`) | `func`, `file` | | c | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `func`, `file` | | csharp | [Xmldoc](https://docs.microsoft.com/fr-fr/dotnet/csharp/language-reference/xmldoc/) (`"xmldoc"`)
[Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `func`, `file`, `class` | | cpp | [Doxygen](https://www.doxygen.nl/manual/commands.html) (`"doxygen"`) | `func`, `file`, `class` | diff --git a/lua/neogen/configurations/sh.lua b/lua/neogen/configurations/sh.lua new file mode 100644 index 0000000..cfd424b --- /dev/null +++ b/lua/neogen/configurations/sh.lua @@ -0,0 +1,62 @@ +local _template = require("neogen.utilities.template") +local i = require("neogen.types.template").item +local nodes_utils = require("neogen.utilities.nodes") +local extractors = require("neogen.utilities.extractors") + +---@type neogen.Configuration +local template = {} + +template.parent = { + func = { "function_definition" }, + file = { "program" }, +} + +template.data = { + func = { + ["function_definition"] = { + ["0"] = { + extract = function(node) + local tree = { + { + node_type = "compound_statement", + retrieve = "first", + subtree = { + { + node_type = "simple_expansion", + retrieve = "all", + recursive = true, + as = i.Parameter, + extract = true, + }, + { + node_type = "expansion", + recursive = true, + retrieve = "all", + subtree = { + { node_type = "variable_name", retrieve = "all", extract = true }, + }, + }, + }, + }, + } + local nodes = nodes_utils:matching_nodes_from(node, tree) + local res = extractors:extract_from_matched(nodes) + return res + end, + }, + }, + }, + file = { + ["program"] = { + ["0"] = { + extract = function() + return {} + end, + }, + }, + }, +} + +template.template = _template:add_default_annotation("google_bash") + +return template diff --git a/lua/neogen/templates/google_bash.lua b/lua/neogen/templates/google_bash.lua new file mode 100644 index 0000000..7d8715c --- /dev/null +++ b/lua/neogen/templates/google_bash.lua @@ -0,0 +1,18 @@ +local i = require("neogen.types.template").item + +return { + { nil, "#######################################", { no_results = true, type = { "func" } } }, + { nil, "# $1", { no_results = true, type = { "func" } } }, + { nil, "#######################################", { no_results = true, type = { "func" } } }, + + { nil, "#!/bin/bash$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, "#######################################" }, + { nil, "# $1" }, + { "variable_name", "# %s", { before_first_item = { "# Globals:" } } }, + { i.Parameter, "# $1", { before_first_item = { "# Arguments:" } } }, + { nil, "#######################################" }, +}