@@ -201,8 +201,8 @@ function M.inline_func(_, config)
201201 local definitions = unpack (results [1 ]) --- @type refactor.QfItem[]
202202 local references = unpack (results [2 ]) --- @type refactor.QfItem[]
203203
204- local match_info = get_processed_match_info (definitions , references , lang )
205- if not match_info then return end
204+ local match_info_by_buf = get_processed_match_info (definitions , references , lang )
205+ if not match_info_by_buf then return end
206206
207207 --- @class refactor.inline_func.DefinitionWithFunctionInfo
208208 --- @field definition refactor.QfItem
@@ -215,7 +215,7 @@ function M.inline_func(_, config)
215215 function (d )
216216 local buf = vim .fn .bufadd (d .filename )
217217
218- local match_info = match_info [buf ]
218+ local match_info = match_info_by_buf [buf ]
219219 -- TODO: add range.vimscript
220220 local d_range = range (d .lnum - 1 , d .col - 1 , d .end_lnum - 1 , d .end_col - 1 , { buf = buf })
221221 local function_info = iter (match_info .functions ):find (
@@ -266,14 +266,18 @@ function M.inline_func(_, config)
266266 --- @field reference refactor.QfItem
267267 --- @field function_call_info refactor.FunctionCallInfo
268268
269+ -- TODO: some LSPs (like lua_ls) may give a reference to a symbol that is
270+ -- not a function_call (i.e. the variable declaration on `require`). Maybe
271+ -- give a warning and do nothing if there are no
272+ -- `references_with_function_call_info` (?
269273 --- @type refactor.inline_func.ReferenceWithFunctionCallInfo[]
270274 local references_with_function_call_info = iter (references )
271275 :map (
272276 --- @param r refactor.QfItem
273277 function (r )
274278 local buf = vim .fn .bufadd (r .filename )
275279
276- local match_info = match_info [buf ]
280+ local match_info = match_info_by_buf [buf ]
277281 -- TODO: add range.vimscript
278282 local r_range = range (r .lnum - 1 , r .col - 1 , r .end_lnum - 1 , r .end_col - 1 , { buf = buf })
279283 local function_call_info = iter (match_info .function_calls ):find (
@@ -303,9 +307,12 @@ function M.inline_func(_, config)
303307 else
304308 body_end_row , body_end_col = function_info .returns_info [1 ][" return" ]:start ()
305309 end
310+ local body_range = range (body_start_row , body_start_col , body_end_row , body_end_col , { buf = in_buf })
311+ local b_srow , b_scol , b_erow , b_ecol = body_range :to_extmark ()
306312
307- local body_lines_without_return =
308- api .nvim_buf_get_text (in_buf , body_start_row , body_start_col , body_end_row , body_end_col , {})
313+ local body_lines_without_return = api .nvim_buf_get_text (in_buf , b_srow , b_scol , b_erow , b_ecol , {})
314+ -- NOTE: can't use `indent()` because first line may not have any indent because of treesitter
315+ -- TODO: use `indent()` without the first line and then add the first line
309316 local body_without_return = iter (body_lines_without_return )
310317 :map (
311318 --- @param line string
0 commit comments