ref(py) Better handling of class methods (#51)
This commit is contained in:
@@ -1,15 +1,18 @@
|
|||||||
local ts_utils = require("nvim-treesitter.ts_utils")
|
local ts_utils = require("nvim-treesitter.ts_utils")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
|
local locator = require("neogen.locators.default")
|
||||||
|
|
||||||
return {
|
local parent = {
|
||||||
-- Search for these nodes
|
|
||||||
parent = {
|
|
||||||
func = { "function_definition" },
|
func = { "function_definition" },
|
||||||
class = { "class_definition" },
|
class = { "class_definition" },
|
||||||
file = { "module" },
|
file = { "module" },
|
||||||
type = { "expression_statement" },
|
type = { "expression_statement" },
|
||||||
},
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
-- Search for these nodes
|
||||||
|
parent = parent,
|
||||||
|
|
||||||
-- Traverse down these nodes and extract the information as necessary
|
-- Traverse down these nodes and extract the information as necessary
|
||||||
data = {
|
data = {
|
||||||
@@ -106,11 +109,10 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Remove reference to "self" if any
|
-- Check if the function is inside a class
|
||||||
if res.identifier then
|
-- If so, remove reference to the first parameter (that can be `self`, `cls`, or a custom name)
|
||||||
res.identifier = vim.tbl_filter(function(v)
|
if res.identifier and locator({ current = node }, parent.class) then
|
||||||
return v ~= "self"
|
table.remove(res.identifier, 1)
|
||||||
end, res.identifier)
|
|
||||||
if vim.tbl_isempty(res.identifier) then
|
if vim.tbl_isempty(res.identifier) then
|
||||||
res.identifier = nil
|
res.identifier = nil
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user