3
3
//! Of particular interest is the `feature_flags` hash map: while other fields
4
4
//! configure the server itself, feature flags are passed into analysis, and
5
5
//! tweak things like automatic insertion of `()` in completions.
6
- use std:: { fmt, iter, ops:: Not , sync:: OnceLock } ;
6
+ use std:: {
7
+ env, fmt, iter,
8
+ ops:: Not ,
9
+ sync:: { LazyLock , OnceLock } ,
10
+ } ;
7
11
8
12
use cfg:: { CfgAtom , CfgDiff } ;
9
- use dirs:: config_dir;
10
13
use hir:: Symbol ;
11
14
use ide:: {
12
15
AssistConfig , CallableSnippets , CompletionConfig , DiagnosticsConfig , ExprFillDefaultMode ,
@@ -735,7 +738,6 @@ pub enum RatomlFileKind {
735
738
}
736
739
737
740
#[ derive( Debug , Clone ) ]
738
- // FIXME @alibektas : Seems like a clippy warning of this sort should tell that combining different ConfigInputs into one enum was not a good idea.
739
741
#[ allow( clippy:: large_enum_variant) ]
740
742
enum RatomlFile {
741
743
Workspace ( GlobalLocalConfigInput ) ,
@@ -757,16 +759,6 @@ pub struct Config {
757
759
/// by receiving a `lsp_types::notification::DidChangeConfiguration`.
758
760
client_config : ( FullConfigInput , ConfigErrors ) ,
759
761
760
- /// Path to the root configuration file. This can be seen as a generic way to define what would be `$XDG_CONFIG_HOME/rust-analyzer/rust-analyzer.toml` in Linux.
761
- /// If not specified by init of a `Config` object this value defaults to :
762
- ///
763
- /// |Platform | Value | Example |
764
- /// | ------- | ------------------------------------- | ---------------------------------------- |
765
- /// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config |
766
- /// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support |
767
- /// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming |
768
- user_config_path : VfsPath ,
769
-
770
762
/// Config node whose values apply to **every** Rust project.
771
763
user_config : Option < ( GlobalLocalConfigInput , ConfigErrors ) > ,
772
764
@@ -794,8 +786,25 @@ impl std::ops::Deref for Config {
794
786
}
795
787
796
788
impl Config {
797
- pub fn user_config_path ( & self ) -> & VfsPath {
798
- & self . user_config_path
789
+ /// Path to the root configuration file. This can be seen as a generic way to define what would be `$XDG_CONFIG_HOME/rust-analyzer/rust-analyzer.toml` in Linux.
790
+ /// This path is equal to:
791
+ ///
792
+ /// |Platform | Value | Example |
793
+ /// | ------- | ------------------------------------- | ---------------------------------------- |
794
+ /// | Linux | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config |
795
+ /// | macOS | `$HOME`/Library/Application Support | /Users/Alice/Library/Application Support |
796
+ /// | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming |
797
+ pub fn user_config_path ( ) -> Option < & ' static AbsPath > {
798
+ static USER_CONFIG_PATH : LazyLock < Option < AbsPathBuf > > = LazyLock :: new ( || {
799
+ let user_config_path = if let Some ( path) = env:: var_os ( "__TEST_RA_USER_CONFIG_DIR" ) {
800
+ std:: path:: PathBuf :: from ( path)
801
+ } else {
802
+ dirs:: config_dir ( ) ?. join ( "rust-analyzer" )
803
+ }
804
+ . join ( "rust-analyzer.toml" ) ;
805
+ Some ( AbsPathBuf :: assert_utf8 ( user_config_path) )
806
+ } ) ;
807
+ USER_CONFIG_PATH . as_deref ( )
799
808
}
800
809
801
810
pub fn same_source_root_parent_map (
@@ -1315,24 +1324,8 @@ impl Config {
1315
1324
caps : lsp_types:: ClientCapabilities ,
1316
1325
workspace_roots : Vec < AbsPathBuf > ,
1317
1326
visual_studio_code_version : Option < Version > ,
1318
- user_config_path : Option < Utf8PathBuf > ,
1319
1327
) -> Self {
1320
1328
static DEFAULT_CONFIG_DATA : OnceLock < & ' static DefaultConfigData > = OnceLock :: new ( ) ;
1321
- let user_config_path = if let Some ( user_config_path) = user_config_path {
1322
- user_config_path. join ( "rust-analyzer" ) . join ( "rust-analyzer.toml" )
1323
- } else {
1324
- let p = config_dir ( )
1325
- . expect ( "A config dir is expected to existed on all platforms ra supports." )
1326
- . join ( "rust-analyzer" )
1327
- . join ( "rust-analyzer.toml" ) ;
1328
- Utf8PathBuf :: from_path_buf ( p) . expect ( "Config dir expected to be abs." )
1329
- } ;
1330
-
1331
- // A user config cannot be a virtual path as rust-analyzer cannot support watching changes in virtual paths.
1332
- // See `GlobalState::process_changes` to get more info.
1333
- // FIXME @alibektas : Temporary solution. I don't think this is right as at some point we may allow users to specify
1334
- // custom USER_CONFIG_PATHs which may also be relative.
1335
- let user_config_path = VfsPath :: from ( AbsPathBuf :: assert ( user_config_path) ) ;
1336
1329
1337
1330
Config {
1338
1331
caps : ClientCapabilities :: new ( caps) ,
@@ -1345,7 +1338,6 @@ impl Config {
1345
1338
default_config : DEFAULT_CONFIG_DATA . get_or_init ( || Box :: leak ( Box :: default ( ) ) ) ,
1346
1339
source_root_parent_map : Arc :: new ( FxHashMap :: default ( ) ) ,
1347
1340
user_config : None ,
1348
- user_config_path,
1349
1341
detached_files : Default :: default ( ) ,
1350
1342
validation_errors : Default :: default ( ) ,
1351
1343
ratoml_file : Default :: default ( ) ,
@@ -3417,7 +3409,7 @@ mod tests {
3417
3409
#[ test]
3418
3410
fn proc_macro_srv_null ( ) {
3419
3411
let mut config =
3420
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3412
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3421
3413
3422
3414
let mut change = ConfigChange :: default ( ) ;
3423
3415
change. change_client_config ( serde_json:: json!( {
@@ -3432,7 +3424,7 @@ mod tests {
3432
3424
#[ test]
3433
3425
fn proc_macro_srv_abs ( ) {
3434
3426
let mut config =
3435
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3427
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3436
3428
let mut change = ConfigChange :: default ( ) ;
3437
3429
change. change_client_config ( serde_json:: json!( {
3438
3430
"procMacro" : {
@@ -3446,7 +3438,7 @@ mod tests {
3446
3438
#[ test]
3447
3439
fn proc_macro_srv_rel ( ) {
3448
3440
let mut config =
3449
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3441
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3450
3442
3451
3443
let mut change = ConfigChange :: default ( ) ;
3452
3444
@@ -3466,7 +3458,7 @@ mod tests {
3466
3458
#[ test]
3467
3459
fn cargo_target_dir_unset ( ) {
3468
3460
let mut config =
3469
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3461
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3470
3462
3471
3463
let mut change = ConfigChange :: default ( ) ;
3472
3464
@@ -3484,7 +3476,7 @@ mod tests {
3484
3476
#[ test]
3485
3477
fn cargo_target_dir_subdir ( ) {
3486
3478
let mut config =
3487
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3479
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3488
3480
3489
3481
let mut change = ConfigChange :: default ( ) ;
3490
3482
change. change_client_config ( serde_json:: json!( {
@@ -3502,7 +3494,7 @@ mod tests {
3502
3494
#[ test]
3503
3495
fn cargo_target_dir_relative_dir ( ) {
3504
3496
let mut config =
3505
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3497
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3506
3498
3507
3499
let mut change = ConfigChange :: default ( ) ;
3508
3500
change. change_client_config ( serde_json:: json!( {
@@ -3523,7 +3515,7 @@ mod tests {
3523
3515
#[ test]
3524
3516
fn toml_unknown_key ( ) {
3525
3517
let config =
3526
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3518
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3527
3519
3528
3520
let mut change = ConfigChange :: default ( ) ;
3529
3521
0 commit comments