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,27 @@ 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 ( ) -> & ' static AbsPath {
798
+ static USER_CONFIG_PATH : LazyLock < 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 ( )
803
+ . expect ( "A config dir is expected to existed on all platforms ra supports." )
804
+ . join ( "rust-analyzer" )
805
+ }
806
+ . join ( "rust-analyzer.toml" ) ;
807
+ AbsPathBuf :: assert_utf8 ( user_config_path)
808
+ } ) ;
809
+ & USER_CONFIG_PATH
799
810
}
800
811
801
812
pub fn same_source_root_parent_map (
@@ -1315,24 +1326,8 @@ impl Config {
1315
1326
caps : lsp_types:: ClientCapabilities ,
1316
1327
workspace_roots : Vec < AbsPathBuf > ,
1317
1328
visual_studio_code_version : Option < Version > ,
1318
- user_config_path : Option < Utf8PathBuf > ,
1319
1329
) -> Self {
1320
1330
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
1331
1337
1332
Config {
1338
1333
caps : ClientCapabilities :: new ( caps) ,
@@ -1345,7 +1340,6 @@ impl Config {
1345
1340
default_config : DEFAULT_CONFIG_DATA . get_or_init ( || Box :: leak ( Box :: default ( ) ) ) ,
1346
1341
source_root_parent_map : Arc :: new ( FxHashMap :: default ( ) ) ,
1347
1342
user_config : None ,
1348
- user_config_path,
1349
1343
detached_files : Default :: default ( ) ,
1350
1344
validation_errors : Default :: default ( ) ,
1351
1345
ratoml_file : Default :: default ( ) ,
@@ -3417,7 +3411,7 @@ mod tests {
3417
3411
#[ test]
3418
3412
fn proc_macro_srv_null ( ) {
3419
3413
let mut config =
3420
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3414
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3421
3415
3422
3416
let mut change = ConfigChange :: default ( ) ;
3423
3417
change. change_client_config ( serde_json:: json!( {
@@ -3432,7 +3426,7 @@ mod tests {
3432
3426
#[ test]
3433
3427
fn proc_macro_srv_abs ( ) {
3434
3428
let mut config =
3435
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3429
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3436
3430
let mut change = ConfigChange :: default ( ) ;
3437
3431
change. change_client_config ( serde_json:: json!( {
3438
3432
"procMacro" : {
@@ -3446,7 +3440,7 @@ mod tests {
3446
3440
#[ test]
3447
3441
fn proc_macro_srv_rel ( ) {
3448
3442
let mut config =
3449
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3443
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3450
3444
3451
3445
let mut change = ConfigChange :: default ( ) ;
3452
3446
@@ -3466,7 +3460,7 @@ mod tests {
3466
3460
#[ test]
3467
3461
fn cargo_target_dir_unset ( ) {
3468
3462
let mut config =
3469
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3463
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3470
3464
3471
3465
let mut change = ConfigChange :: default ( ) ;
3472
3466
@@ -3484,7 +3478,7 @@ mod tests {
3484
3478
#[ test]
3485
3479
fn cargo_target_dir_subdir ( ) {
3486
3480
let mut config =
3487
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3481
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3488
3482
3489
3483
let mut change = ConfigChange :: default ( ) ;
3490
3484
change. change_client_config ( serde_json:: json!( {
@@ -3502,7 +3496,7 @@ mod tests {
3502
3496
#[ test]
3503
3497
fn cargo_target_dir_relative_dir ( ) {
3504
3498
let mut config =
3505
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3499
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3506
3500
3507
3501
let mut change = ConfigChange :: default ( ) ;
3508
3502
change. change_client_config ( serde_json:: json!( {
@@ -3523,7 +3517,7 @@ mod tests {
3523
3517
#[ test]
3524
3518
fn toml_unknown_key ( ) {
3525
3519
let config =
3526
- Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None , None ) ;
3520
+ Config :: new ( AbsPathBuf :: assert ( project_root ( ) ) , Default :: default ( ) , vec ! [ ] , None ) ;
3527
3521
3528
3522
let mut change = ConfigChange :: default ( ) ;
3529
3523
0 commit comments