fix(py) better handling of static methods

This commit is contained in:
danymat
2022-01-30 16:18:49 +01:00
parent 33fc37b6b7
commit cda1f0a372

View File

@@ -111,11 +111,22 @@ return {
-- Check if the function is inside a class -- Check if the function is inside a class
-- If so, remove reference to the first parameter (that can be `self`, `cls`, or a custom name) -- If so, remove reference to the first parameter (that can be `self`, `cls`, or a custom name)
if res.identifier and locator({ current = node }, parent.class) then if res.identifier and locator({ current = node }, parent.class) then
local remove_identifier = true
-- Check if function is a static method. If so, will not remove the first parameter
if node:parent():type() == "decorated_definition" then
local decorator = nodes_utils:matching_child_nodes(node:parent(), "decorator")
decorator = ts_utils.get_node_text(decorator[1])[1]
if decorator == "@staticmethod" then
remove_identifier = false
end
end
if remove_identifier then
table.remove(res.identifier, 1) table.remove(res.identifier, 1)
if vim.tbl_isempty(res.identifier) then if vim.tbl_isempty(res.identifier) then
res.identifier = nil res.identifier = nil
end end
end end
end
results.has_identifier = (res.typed_parameter or res.identifier) and { true } or nil results.has_identifier = (res.typed_parameter or res.identifier) and { true } or nil
results.type = res.type results.type = res.type