@@ -95,7 +95,7 @@ def Exit( self ):
95
95
'09650af5c9dc39f0b40981bcdaa2170cbbc5bb003ac90cdb07fbb57381ac47b2'
96
96
)
97
97
98
- RUST_TOOLCHAIN = 'nightly-2021-10-26 '
98
+ RUST_TOOLCHAIN = 'nightly-2022-08-17 '
99
99
RUST_ANALYZER_DIR = p .join ( DIR_OF_THIRD_PARTY , 'rust-analyzer' )
100
100
101
101
BUILD_ERROR_MESSAGE = (
@@ -115,6 +115,64 @@ def Exit( self ):
115
115
'See the YCM docs for details on how to use a custom Clangd.' )
116
116
117
117
118
+ def FindLatestMSVC ( quiet ):
119
+ ACCEPTABLE_VERSIONS = [ 17 , 16 , 15 ]
120
+
121
+ VSWHERE_EXE = os .path .join ( os .environ [ 'ProgramFiles(x86)' ],
122
+ 'Microsoft Visual Studio' ,
123
+ 'Installer' , 'vswhere.exe' )
124
+
125
+ if os .path .exists ( VSWHERE_EXE ):
126
+ if not quiet :
127
+ print ( "Calling vswhere -latest -installationVersion" )
128
+ latest_full_v = subprocess .check_output (
129
+ [ VSWHERE_EXE , '-latest' , '-property' , 'installationVersion' ]
130
+ ).strip ().decode ()
131
+ if '.' in latest_full_v :
132
+ try :
133
+ latest_v = int ( latest_full_v .split ( '.' )[ 0 ] )
134
+ except ValueError :
135
+ raise ValueError ( f"{ latest_full_v } is not a version number." )
136
+
137
+ if not quiet :
138
+ print ( f'vswhere -latest returned version { latest_full_v } ' )
139
+
140
+ if latest_v not in ACCEPTABLE_VERSIONS :
141
+ if latest_v > 17 :
142
+ if not quiet :
143
+ print ( f'MSVC Version { latest_full_v } is newer than expected.' )
144
+ else :
145
+ raise ValueError (
146
+ f'vswhere returned { latest_full_v } which is unexpected.'
147
+ 'Pass --msvc <version> argument.' )
148
+ return latest_v
149
+ else :
150
+ if not quiet :
151
+ print ( f'vswhere returned nothing usable, { latest_full_v } ' )
152
+
153
+ # Fall back to registry parsing, which works at least until MSVC 2019 (16)
154
+ # but is likely failing on MSVC 2022 (17)
155
+ if not quiet :
156
+ print ( "vswhere method failed, falling back to searching the registry" )
157
+
158
+ import winreg
159
+ handle = winreg .ConnectRegistry ( None , winreg .HKEY_LOCAL_MACHINE )
160
+ msvc = None
161
+ for i in ACCEPTABLE_VERSIONS :
162
+ if not quiet :
163
+ print ( 'Trying to find '
164
+ rf'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\{ i } .0' )
165
+ try :
166
+ winreg .OpenKey ( handle , rf'SOFTWARE\Microsoft\VisualStudio\{ i } .0' )
167
+ if not quiet :
168
+ print ( f"Found MSVC version { i } " )
169
+ msvc = i
170
+ break
171
+ except FileNotFoundError :
172
+ pass
173
+ return msvc
174
+
175
+
118
176
def RemoveDirectory ( directory ):
119
177
try_number = 0
120
178
max_tries = 10
@@ -409,9 +467,11 @@ def ParseArguments():
409
467
parser .add_argument ( '--system-libclang' , action = 'store_true' ,
410
468
help = 'Use system libclang instead of downloading one '
411
469
'from llvm.org. NOT RECOMMENDED OR SUPPORTED!' )
412
- parser .add_argument ( '--msvc' , type = int , choices = [ 15 , 16 , 17 ],
413
- default = 16 , help = 'Choose the Microsoft Visual '
414
- 'Studio version (default: %(default)s).' )
470
+ if OnWindows ():
471
+ parser .add_argument ( '--msvc' , type = int , choices = [ 15 , 16 , 17 ],
472
+ default = None ,
473
+ help = 'Choose the Microsoft Visual Studio version '
474
+ '(default: %(default)s).' )
415
475
parser .add_argument ( '--ninja' , action = 'store_true' ,
416
476
help = 'Use Ninja build system.' )
417
477
parser .add_argument ( '--all' ,
@@ -490,6 +550,11 @@ def ParseArguments():
490
550
# We always want a debug build when running with coverage enabled
491
551
args .enable_debug = True
492
552
553
+ if OnWindows () and args .msvc is None :
554
+ args .msvc = FindLatestMSVC ( args .quiet )
555
+ if args .msvc is None :
556
+ raise FileNotFoundError ( "Could not find a valid MSVC version." )
557
+
493
558
if args .core_tests :
494
559
os .environ [ 'YCM_TESTRUN' ] = '1'
495
560
elif os .environ .get ( 'YCM_TESTRUN' ):
@@ -868,7 +933,7 @@ def EnableGoCompleter( args ):
868
933
new_env .pop ( 'GOROOT' , None )
869
934
new_env [ 'GOBIN' ] = p .join ( new_env [ 'GOPATH' ], 'bin' )
870
935
871
- gopls = 'golang.org/x/tools/gopls@v0.7.1 '
936
+ gopls = 'golang.org/x/tools/gopls@v0.9.4 '
872
937
CheckCall ( [ go , 'install' , gopls ],
873
938
env = new_env ,
874
939
quiet = args .quiet ,
0 commit comments