@@ -115,6 +115,20 @@ def Exit( self ):
115115 'See the YCM docs for details on how to use a custom Clangd.' )
116116
117117
118+ def FindLatestMSVC ():
119+ import winreg
120+ aReg = winreg .ConnectRegistry (None , winreg .HKEY_LOCAL_MACHINE )
121+ msvc = None
122+ for i in [17 , 16 , 15 ]:
123+ try :
124+ aKey = winreg .OpenKey (aReg , rf'SOFTWARE\Microsoft\VisualStudio\{ i } .0' )
125+ print (f"Found { i } " )
126+ msvc = i
127+ break
128+ except FileNotFoundError :
129+ pass
130+ return msvc
131+
118132def RemoveDirectory ( directory ):
119133 try_number = 0
120134 max_tries = 10
@@ -409,9 +423,16 @@ def ParseArguments():
409423 parser .add_argument ( '--system-libclang' , action = 'store_true' ,
410424 help = 'Use system libclang instead of downloading one '
411425 '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).' )
426+ if OnWindows ():
427+ latest_msvc = FindLatestMSVC ()
428+ if latest_msvc is None :
429+ # TODO: raise?
430+ # raise FileNotFoundError("Could not find a valid MSVC version")
431+ latest_msvc = 16
432+ parser .add_argument ( '--msvc' , type = int , choices = [ 15 , 16 , 17 ],
433+ default = latest_msvc ,
434+ help = 'Choose the Microsoft Visual Studio version '
435+ '(default: %(default)s).' )
415436 parser .add_argument ( '--ninja' , action = 'store_true' ,
416437 help = 'Use Ninja build system.' )
417438 parser .add_argument ( '--all' ,
0 commit comments