@@ -822,12 +822,23 @@ fn recurse_call(
822
822
}
823
823
824
824
fn handle_package_attach_call ( node : Node , context : & mut DiagnosticContext ) -> anyhow:: Result < ( ) > {
825
- // Find the first argument (package name). Positionally for now.
826
- let Some ( value) = node. arguments_values ( ) . nth ( 0 ) else {
825
+ // Find the first argument (package name). Positionally for now, no attempt
826
+ // at argument matching whatsoever.
827
+ let Some ( package_node) = node. arguments_values ( ) . nth ( 0 ) else {
827
828
return Err ( anyhow:: anyhow!( "Can't unpack attached package argument" ) ) ;
828
829
} ;
829
830
830
- let package_name = value. get_identifier_or_string_text ( context. contents ) ?;
831
+ // Just bail if `character.only` is passed, even if it's actually `FALSE`.
832
+ // We'll do better when we have a more capable argument inspection
833
+ // infrastructure.
834
+ if let Some ( _) = node
835
+ . arguments_names_as_string ( context. contents )
836
+ . find ( |n| n == "character.only" )
837
+ {
838
+ return Ok ( ( ) ) ;
839
+ }
840
+
841
+ let package_name = package_node. get_identifier_or_string_text ( context. contents ) ?;
831
842
let attach_pos = node. end_position ( ) ;
832
843
833
844
let package = match insert_package_exports ( & package_name, attach_pos, context) {
@@ -1666,8 +1677,26 @@ foo
1666
1677
bar
1667
1678
" ;
1668
1679
let document = Document :: new ( code, None ) ;
1669
- let diagnostics = generate_diagnostics ( document, state) ;
1680
+ let diagnostics = generate_diagnostics ( document, state. clone ( ) ) ;
1670
1681
assert_eq ! ( diagnostics. len( ) , 0 ) ;
1682
+
1683
+ // If the library call includes the `character.only` argument, we bail
1684
+ let code = r#"
1685
+ library(mockpkg, character.only = TRUE)
1686
+ foo()
1687
+ "# ;
1688
+ let document = Document :: new ( code, None ) ;
1689
+ let diagnostics = generate_diagnostics ( document, state. clone ( ) ) ;
1690
+ assert_eq ! ( diagnostics. len( ) , 1 ) ;
1691
+
1692
+ // Same if passed `FALSE`, we're not trying to be smart (yet)
1693
+ let code = r#"
1694
+ library(mockpkg, character.only = FALSE)
1695
+ foo()
1696
+ "# ;
1697
+ let document = Document :: new ( code, None ) ;
1698
+ let diagnostics = generate_diagnostics ( document, state) ;
1699
+ assert_eq ! ( diagnostics. len( ) , 1 ) ;
1671
1700
} ) ;
1672
1701
}
1673
1702
0 commit comments