@@ -12,28 +12,26 @@ import { DebuggerPrerequisiteWarning, DebuggerPrerequisiteFailure, DebuggerNotIn
1212import { EventStream } from '../EventStream' ;
1313import CSharpExtensionExports from '../CSharpExtensionExports' ;
1414import { getRuntimeDependencyPackageWithId } from '../tools/RuntimeDependencyPackageUtils' ;
15- import { getDotnetInfo , DotnetInfo } from '../utils/getDotnetInfo' ;
15+ import { getDotnetInfo } from '../utils/getDotnetInfo' ;
1616import { DotnetDebugConfigurationProvider } from './debugConfigurationProvider' ;
1717import { Options } from '../omnisharp/options' ;
1818
19- let _debugUtil : CoreClrDebugUtil = null ;
20-
2119export async function activate ( thisExtension : vscode . Extension < CSharpExtensionExports > , context : vscode . ExtensionContext , platformInformation : PlatformInformation , eventStream : EventStream , options : Options ) {
22- _debugUtil = new CoreClrDebugUtil ( context . extensionPath ) ;
20+ const debugUtil = new CoreClrDebugUtil ( context . extensionPath ) ;
2321
24- if ( ! CoreClrDebugUtil . existsSync ( _debugUtil . debugAdapterDir ( ) ) ) {
22+ if ( ! CoreClrDebugUtil . existsSync ( debugUtil . debugAdapterDir ( ) ) ) {
2523 let isValidArchitecture : boolean = await checkIsValidArchitecture ( platformInformation , eventStream ) ;
2624 // If this is a valid architecture, we should have had a debugger, so warn if we didn't, otherwise
2725 // a warning was already issued, so do nothing.
2826 if ( isValidArchitecture ) {
2927 eventStream . post ( new DebuggerPrerequisiteFailure ( "[ERROR]: C# Extension failed to install the debugger package." ) ) ;
3028 showInstallErrorMessage ( eventStream ) ;
3129 }
32- } else if ( ! CoreClrDebugUtil . existsSync ( _debugUtil . installCompleteFilePath ( ) ) ) {
33- completeDebuggerInstall ( platformInformation , eventStream , options ) ;
30+ } else if ( ! CoreClrDebugUtil . existsSync ( debugUtil . installCompleteFilePath ( ) ) ) {
31+ completeDebuggerInstall ( debugUtil , platformInformation , eventStream , options ) ;
3432 }
3533
36- const factory = new DebugAdapterExecutableFactory ( platformInformation , eventStream , thisExtension . packageJSON , thisExtension . extensionPath , options ) ;
34+ const factory = new DebugAdapterExecutableFactory ( debugUtil , platformInformation , eventStream , thisExtension . packageJSON , thisExtension . extensionPath , options ) ;
3735 context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( 'coreclr' , new DotnetDebugConfigurationProvider ( platformInformation ) ) ) ;
3836 context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( 'clr' , new DotnetDebugConfigurationProvider ( platformInformation ) ) ) ;
3937 context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( 'coreclr' , factory ) ) ;
@@ -74,30 +72,29 @@ async function checkIsValidArchitecture(platformInformation: PlatformInformation
7472 return false ;
7573}
7674
77- async function completeDebuggerInstall ( platformInformation : PlatformInformation , eventStream : EventStream , options : Options ) : Promise < boolean > {
78- return _debugUtil . checkDotNetCli ( options . dotNetCliPaths )
79- . then ( async ( dotnetInfo : DotnetInfo ) => {
75+ async function completeDebuggerInstall ( debugUtil : CoreClrDebugUtil , platformInformation : PlatformInformation , eventStream : EventStream , options : Options ) : Promise < boolean > {
76+ try {
77+ await debugUtil . checkDotNetCli ( options . dotNetCliPaths ) ;
78+ const isValidArchitecture = await checkIsValidArchitecture ( platformInformation , eventStream ) ;
79+ if ( ! isValidArchitecture ) {
80+ eventStream . post ( new DebuggerNotInstalledFailure ( ) ) ;
81+ vscode . window . showErrorMessage ( 'Failed to complete the installation of the C# extension. Please see the error in the output window below.' ) ;
82+ return false ;
83+ }
8084
81- let isValidArchitecture : boolean = await checkIsValidArchitecture ( platformInformation , eventStream ) ;
85+ // Write install.complete
86+ CoreClrDebugUtil . writeEmptyFile ( debugUtil . installCompleteFilePath ( ) ) ;
8287
83- if ( ! isValidArchitecture ) {
84- eventStream . post ( new DebuggerNotInstalledFailure ( ) ) ;
85- vscode . window . showErrorMessage ( 'Failed to complete the installation of the C# extension. Please see the error in the output window below.' ) ;
86- return false ;
87- }
88-
89- // Write install.complete
90- CoreClrDebugUtil . writeEmptyFile ( _debugUtil . installCompleteFilePath ( ) ) ;
88+ return true ;
89+ } catch ( err ) {
90+ const error = err as Error ;
9191
92- return true ;
93- } , ( err ) => {
94- // Check for dotnet tools failed. pop the UI
95- // err is a DotNetCliError but use defaults in the unexpected case that it's not
96- showDotnetToolsWarning ( err . ErrorMessage || _debugUtil . defaultDotNetCliErrorMessage ( ) ) ;
97- eventStream . post ( new DebuggerPrerequisiteWarning ( err . ErrorString || err ) ) ;
98- // TODO: log telemetry?
99- return false ;
100- } ) ;
92+ // Check for dotnet tools failed. pop the UI
93+ showDotnetToolsWarning ( error . message ) ;
94+ eventStream . post ( new DebuggerPrerequisiteWarning ( error . message ) ) ;
95+ // TODO: log telemetry?
96+ return false ;
97+ }
10198}
10299
103100function showInstallErrorMessage ( eventStream : EventStream ) {
@@ -133,7 +130,7 @@ function showDotnetToolsWarning(message: string): void {
133130// Else it will launch the debug adapter
134131export class DebugAdapterExecutableFactory implements vscode . DebugAdapterDescriptorFactory {
135132
136- constructor ( private readonly platformInfo : PlatformInformation , private readonly eventStream : EventStream , private readonly packageJSON : any , private readonly extensionPath : string , private readonly options : Options ) {
133+ constructor ( private readonly debugUtil : CoreClrDebugUtil , private readonly platformInfo : PlatformInformation , private readonly eventStream : EventStream , private readonly packageJSON : any , private readonly extensionPath : string , private readonly options : Options ) {
137134 }
138135
139136 async createDebugAdapterDescriptor ( _session : vscode . DebugSession , executable : vscode . DebugAdapterExecutable | undefined ) : Promise < vscode . DebugAdapterDescriptor > {
@@ -161,8 +158,7 @@ export class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescrip
161158 }
162159 // install.complete does not exist, check dotnetCLI to see if we can complete.
163160 else if ( ! CoreClrDebugUtil . existsSync ( util . installCompleteFilePath ( ) ) ) {
164- let success : boolean = await completeDebuggerInstall ( this . platformInfo , this . eventStream , this . options ) ;
165-
161+ let success = await completeDebuggerInstall ( this . debugUtil , this . platformInfo , this . eventStream , this . options ) ;
166162 if ( ! success ) {
167163 this . eventStream . post ( new DebuggerNotInstalledFailure ( ) ) ;
168164 throw new Error ( 'Failed to complete the installation of the C# extension. Please see the error in the output window below.' ) ;
@@ -172,14 +168,16 @@ export class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescrip
172168
173169 // debugger has finished installation, kick off our debugger process
174170
175- // Check for targetArchitecture
176- let dotNetInfo = await getDotnetInfo ( this . options . dotNetCliPaths ) ;
177- const targetArchitecture : string = getTargetArchitecture ( this . platformInfo , _session . configuration . targetArchitecture , dotNetInfo ) ;
178-
179171 // use the executable specified in the package.json if it exists or determine it based on some other information (e.g. the session)
180172 if ( ! executable ) {
173+ const dotNetInfo = await getDotnetInfo ( this . options . dotNetCliPaths ) ;
174+ const targetArchitecture = getTargetArchitecture ( this . platformInfo , _session . configuration . targetArchitecture , dotNetInfo ) ;
181175 const command = path . join ( common . getExtensionPath ( ) , ".debugger" , targetArchitecture , "vsdbg-ui" + CoreClrDebugUtil . getPlatformExeExtension ( ) ) ;
182- executable = new vscode . DebugAdapterExecutable ( command , [ ] , { env : { 'DOTNET_ROOT' : dotNetInfo . CliPath ? path . dirname ( dotNetInfo . CliPath ) : '' } } ) ;
176+ executable = new vscode . DebugAdapterExecutable ( command , [ ] , {
177+ env : {
178+ DOTNET_ROOT : dotNetInfo . CliPath ? path . dirname ( dotNetInfo . CliPath ) : '' ,
179+ }
180+ } ) ;
183181 }
184182
185183 // make VS Code launch the DA executable
0 commit comments