@@ -180,25 +180,20 @@ arg_value_completion <- function(uri, workspace, document, point, token, funct,
180180 package_for_call <- workspace $ guess_namespace(funct , isf = TRUE )
181181 }
182182
183- if (is.null(package_for_call )) {
184- return (list ())
185- }
186-
187- # Get the formals
183+ # Try to get the formals - works with NULL package for user-defined functions
188184 formals_list <- workspace $ get_formals(funct , package_for_call ,
189185 exported_only = exported_only )
190186
191187 if (is.null(formals_list ) || ! is.list(formals_list ) || length(formals_list ) == 0 ) {
192188 return (list ())
193189 }
194190
195- # Get current line
196- lines <- strsplit(document $ content , " \n " , fixed = TRUE )[[1 ]]
197- if (point $ row > = length(lines )) {
191+ # Get current line - document$content is an array of lines (1-indexed)
192+ if (point $ row + 1 < 1 || point $ row + 1 > length(document $ content )) {
198193 return (list ())
199194 }
200195
201- current_line <- lines [point $ row + 1 ]
196+ current_line <- document $ content [point $ row + 1 ]
202197 if (point $ col == 0 || point $ col > nchar(current_line )) {
203198 return (list ())
204199 }
@@ -209,7 +204,7 @@ arg_value_completion <- function(uri, workspace, document, point, token, funct,
209204 # Simple approach: split by = and check if the part before it looks like a named argument
210205 parts <- strsplit(prefix , " =" , fixed = TRUE )[[1 ]]
211206 if (length(parts ) > = 2 ) {
212- # Get text before the = sign
207+ # Get text before the = sign
213208 before_equals <- parts [length(parts ) - 1 ]
214209
215210 # Extract potential argument name from end of before_equals
@@ -225,7 +220,9 @@ arg_value_completion <- function(uri, workspace, document, point, token, funct,
225220 param_names <- names(formals_list )
226221 if (potential_arg %in% param_names ) {
227222 # Get value completions for this argument
228- return (argument_value_completion(workspace , funct , package_for_call , potential_arg , token ))
223+ result <- argument_value_completion(workspace , funct , package_for_call , potential_arg , token )
224+ logger $ info(" arg_value_completion: returning" , length(result ), " items for" , funct , " arg" , potential_arg )
225+ return (result )
229226 }
230227 }
231228 }
0 commit comments