From ef5c7466e267b63ffa72bcc7c92371611d307e5c Mon Sep 17 00:00:00 2001 From: tris203 Date: Wed, 20 Dec 2023 10:50:26 +0000 Subject: [PATCH] refactor: reuse buildArgs function --- lua/hawtkeys/ts.lua | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/lua/hawtkeys/ts.lua b/lua/hawtkeys/ts.lua index 114897e..33e8417 100644 --- a/lua/hawtkeys/ts.lua +++ b/lua/hawtkeys/ts.lua @@ -64,6 +64,19 @@ local keyMapSet = { ---@type table local scannedFiles = {} +---@param params keyMapArgs[] +---@param method setMethods +---@return string +local function buildArgs(params, method) + local args = "" + for name, opts in pairs(params) do + if opts.method == method then + args = args .. ' "' .. name .. '"' + end + end + return args +end + ---@param mapDefs keyMapArgs[] ---@return string local function build_dot_index_expression_query(mapDefs) @@ -73,18 +86,7 @@ local function build_dot_index_expression_query(mapDefs) (arguments) @args) ]] - ---@param params keyMapArgs[] - ---@return string - local function buildArgs(params) - local args = "" - for name, opts in pairs(params) do - if opts.method == "dot_index_expression" then - args = args .. ' "' .. name .. '"' - end - end - return args - end - return string.format(query, buildArgs(mapDefs)) + return string.format(query, buildArgs(mapDefs, "dot_index_expression")) end ---@param mapDefs keyMapArgs[] @@ -95,18 +97,7 @@ local function build_function_call_query(mapDefs) name: (identifier) @exp (#any-of? @exp %s) (arguments) @args) ]] - ---@param params keyMapArgs[] - ---@return string - local function buildArgs(params) - local args = "" - for name, opts in pairs(params) do - if opts.method == "function_call" then - args = args .. ' "' .. name .. '"' - end - end - return args - end - return string.format(query, buildArgs(mapDefs)) + return string.format(query, buildArgs(mapDefs, "function_call")) end ---@param node TSNode