@@ -95,7 +95,7 @@ def Exit( self ):
9595 '2363d8c01d5a8260a3d55f8fa008828d26a7b0acf9b173fafca4471ee81a701f'
9696)
9797
98- RUST_TOOLCHAIN = 'nightly-2022-08-17 '
98+ DEFAULT_RUST_TOOLCHAIN = 'nightly-2023-05-11 '
9999RUST_ANALYZER_DIR = p .join ( DIR_OF_THIRD_PARTY , 'rust-analyzer' )
100100
101101BUILD_ERROR_MESSAGE = (
@@ -455,6 +455,14 @@ def ParseArguments():
455455 help = 'Enable Go semantic completion engine.' )
456456 parser .add_argument ( '--rust-completer' , action = 'store_true' ,
457457 help = 'Enable Rust semantic completion engine.' )
458+ parser .add_argument ( '--rust-toolchain-version' ,
459+ action = 'store' ,
460+ default = DEFAULT_RUST_TOOLCHAIN ,
461+ help = 'For advanced users ***NO SUPPORT***, specify '
462+ 'the rust toolchain version to install from '
463+ 'rustup. Only the default vaule "' +
464+ DEFAULT_RUST_TOOLCHAIN + '" is tested/'
465+ 'supported by the maintainers of YCM/ycmd' )
458466 parser .add_argument ( '--java-completer' , action = 'store_true' ,
459467 help = 'Enable Java semantic completion engine.' ),
460468 parser .add_argument ( '--ts-completer' , action = 'store_true' ,
@@ -958,13 +966,23 @@ def ReadToolchainVersion():
958966 return None
959967
960968
969+ def RustToolchainNeedsRefresh ( cur , req ):
970+ if cur == 'stable' and req == 'stable' :
971+ return True
972+
973+ return cur != req
974+
975+
961976def EnableRustCompleter ( switches ):
977+ cur_toolchain_version = ReadToolchainVersion ()
978+ req_toolchain_version = switches .rust_toolchain_version
979+
962980 if switches .quiet :
963- sys .stdout .write ( 'Installing rust-analyzer for Rust support...' )
981+ sys .stdout .write ( f'Installing rust-analyzer "{ req_toolchain_version } " '
982+ 'for Rust support...' )
964983 sys .stdout .flush ()
965984
966- toolchain_version = ReadToolchainVersion ()
967- if toolchain_version != RUST_TOOLCHAIN :
985+ if RustToolchainNeedsRefresh ( cur_toolchain_version , req_toolchain_version ):
968986 install_dir = mkdtemp ( prefix = 'rust_install_' )
969987
970988 new_env = os .environ .copy ()
@@ -992,7 +1010,7 @@ def EnableRustCompleter( switches ):
9921010 rustup = p .join ( install_dir , 'bin' , 'rustup' )
9931011
9941012 try :
995- CheckCall ( [ rustup , 'toolchain' , 'install' , RUST_TOOLCHAIN ],
1013+ CheckCall ( [ rustup , 'toolchain' , 'install' , req_toolchain_version ],
9961014 env = new_env ,
9971015 quiet = switches .quiet )
9981016
@@ -1001,12 +1019,12 @@ def EnableRustCompleter( switches ):
10011019 'rustfmt' ,
10021020 'clippy' ]:
10031021 CheckCall ( [ rustup , 'component' , 'add' , component ,
1004- '--toolchain' , RUST_TOOLCHAIN ],
1022+ '--toolchain' , req_toolchain_version ],
10051023 env = new_env ,
10061024 quiet = switches .quiet )
10071025
10081026 toolchain_dir = subprocess .check_output (
1009- [ rustup , 'run' , RUST_TOOLCHAIN , 'rustc' , '--print' , 'sysroot' ],
1027+ [ rustup , 'run' , req_toolchain_version , 'rustc' , '--print' , 'sysroot' ],
10101028 env = new_env
10111029 ).rstrip ().decode ( 'utf8' )
10121030
@@ -1017,7 +1035,7 @@ def EnableRustCompleter( switches ):
10171035 for folder in os .listdir ( toolchain_dir ):
10181036 shutil .move ( p .join ( toolchain_dir , folder ), RUST_ANALYZER_DIR )
10191037
1020- WriteToolchainVersion ( RUST_TOOLCHAIN )
1038+ WriteToolchainVersion ( req_toolchain_version )
10211039 finally :
10221040 RemoveDirectory ( install_dir )
10231041
0 commit comments