refactor(_utils.ts): some renameing, moving requires lines

This commit is contained in:
Smirnov Oleksandr 2023-07-19 23:28:07 +03:00
parent 3e51e15dac
commit d20081f2b0
2 changed files with 14 additions and 16 deletions

View file

@ -1,7 +1,7 @@
---@diagnostic disable: param-type-mismatch ---@diagnostic disable: param-type-mismatch
local nodes = require "gopher._utils.ts.nodes" local nodes = require "gopher._utils.ts.nodes"
local u = require "gopher._utils" local u = require "gopher._utils"
local M = { local ts = {
querys = { querys = {
struct_block = [[((type_declaration (type_spec name:(type_identifier) @struct.name type: (struct_type)))@struct.declaration)]], struct_block = [[((type_declaration (type_spec name:(type_identifier) @struct.name type: (struct_type)))@struct.declaration)]],
em_struct_block = [[(field_declaration name:(field_identifier)@struct.name type: (struct_type)) @struct.declaration]], em_struct_block = [[(field_declaration name:(field_identifier)@struct.name type: (struct_type)) @struct.declaration]],
@ -27,9 +27,9 @@ end
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil ---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_struct_node_at_pos(row, col, bufnr, do_notify) function ts.get_struct_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true local notify = do_notify or true
local query = M.querys.struct_block .. " " .. M.querys.em_struct_block local query = ts.querys.struct_block .. " " .. ts.querys.em_struct_block
local bufn = bufnr or vim.api.nvim_get_current_buf() local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
@ -46,9 +46,9 @@ end
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil ---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_func_method_node_at_pos(row, col, bufnr, do_notify) function ts.get_func_method_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true local notify = do_notify or true
local query = M.querys.func .. " " .. M.querys.method_name local query = ts.querys.func .. " " .. ts.querys.method_name
local bufn = bufnr or vim.api.nvim_get_current_buf() local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
@ -65,11 +65,11 @@ end
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil ---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_package_node_at_pos(row, col, bufnr, do_notify) function ts.get_package_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true local notify = do_notify or true
-- stylua: ignore -- stylua: ignore
if row > 10 then return end if row > 10 then return end
local query = M.querys.package local query = ts.querys.package
local bufn = bufnr or vim.api.nvim_get_current_buf() local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
@ -87,9 +87,9 @@ end
---@param bufnr string|nil ---@param bufnr string|nil
---@param do_notify boolean|nil ---@param do_notify boolean|nil
---@return table|nil ---@return table|nil
function M.get_interface_node_at_pos(row, col, bufnr, do_notify) function ts.get_interface_node_at_pos(row, col, bufnr, do_notify)
local notify = do_notify or true local notify = do_notify or true
local query = M.querys.interface local query = ts.querys.interface
local bufn = bufnr or vim.api.nvim_get_current_buf() local bufn = bufnr or vim.api.nvim_get_current_buf()
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
@ -101,4 +101,4 @@ function M.get_interface_node_at_pos(row, col, bufnr, do_notify)
end end
end end
return M return ts

View file

@ -1,3 +1,7 @@
local ts_query = require "nvim-treesitter.query"
local parsers = require "nvim-treesitter.parsers"
local locals = require "nvim-treesitter.locals"
local u = require "gopher._utils"
local M = {} local M = {}
local function intersects(row, col, sRow, sCol, eRow, eCol) local function intersects(row, col, sRow, sCol, eRow, eCol)
@ -53,10 +57,6 @@ end
---@param pos_row string ---@param pos_row string
---@return string ---@return string
function M.get_all_nodes(query, lang, _, bufnr, pos_row, _) function M.get_all_nodes(query, lang, _, bufnr, pos_row, _)
local ts_query = require "nvim-treesitter.query"
local parsers = require "nvim-treesitter.parsers"
local locals = require "nvim-treesitter.locals"
bufnr = bufnr or 0 bufnr = bufnr or 0
pos_row = pos_row or 30000 pos_row = pos_row or 30000
@ -113,8 +113,6 @@ end
---@param col string ---@param col string
---@return table ---@return table
function M.nodes_at_cursor(query, default, bufnr, row, col) function M.nodes_at_cursor(query, default, bufnr, row, col)
local u = require "gopher._utils"
bufnr = bufnr or vim.api.nvim_get_current_buf() bufnr = bufnr or vim.api.nvim_get_current_buf()
local ft = vim.api.nvim_buf_get_option(bufnr, "ft") local ft = vim.api.nvim_buf_get_option(bufnr, "ft")
if row == nil or col == nil then if row == nil or col == nil then