@@ -84,10 +84,12 @@ fn completions_from_namespace(
84
84
let package = context. document . contents . node_slice ( & package) ?. to_string ( ) ;
85
85
let package = package. as_str ( ) ;
86
86
87
- // Get the package namespace.
87
+ // Get the package namespace
88
88
let Ok ( namespace) = RFunction :: new ( "base" , "getNamespace" ) . add ( package) . call ( ) else {
89
- // There is no package of this name or it could not be loaded
90
- return Ok ( None ) ;
89
+ // There is no package of this name or it could not be loaded, but it did look
90
+ // like the user wanted namespace completions, so disallow anything else from
91
+ // running
92
+ return Ok ( Some ( completions) ) ;
91
93
} ;
92
94
93
95
let symbols = if package == "base" {
@@ -240,6 +242,7 @@ fn list_namespace_exports(namespace: SEXP) -> RObject {
240
242
mod tests {
241
243
use tree_sitter:: Point ;
242
244
245
+ use crate :: fixtures:: point_from_cursor;
243
246
use crate :: lsp:: completions:: parameter_hints:: ParameterHints ;
244
247
use crate :: lsp:: completions:: sources:: unique:: namespace:: completions_from_namespace;
245
248
use crate :: lsp:: document_context:: DocumentContext ;
@@ -344,4 +347,18 @@ mod tests {
344
347
assert ! ( completions. is_empty( ) ) ;
345
348
} )
346
349
}
350
+
351
+ #[ test]
352
+ fn test_empty_set_of_completions_when_using_unknown_package ( ) {
353
+ // https://github.com/posit-dev/ark/issues/833
354
+ r_task ( || {
355
+ let ( text, point) = point_from_cursor ( "foo::bar@" ) ;
356
+ let document = Document :: new ( & text, None ) ;
357
+ let context = DocumentContext :: new ( & document, point, None ) ;
358
+ let completions = completions_from_namespace ( & context, & ParameterHints :: Enabled )
359
+ . unwrap ( )
360
+ . unwrap ( ) ;
361
+ assert ! ( completions. is_empty( ) ) ;
362
+ } )
363
+ }
347
364
}
0 commit comments