@@ -19,49 +19,64 @@ import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
1919import { IDiagnosticsCommandFactory } from '../commands/types' ;
2020import { DiagnosticCodes } from '../constants' ;
2121import { DiagnosticCommandPromptHandlerServiceId , MessageCommandPrompt } from '../promptHandler' ;
22- import { DiagnosticScope , IDiagnostic , IDiagnosticCommand , IDiagnosticHandlerService , IInvalidPythonPathInDebuggerService } from '../types' ;
22+ import {
23+ DiagnosticScope ,
24+ IDiagnostic ,
25+ IDiagnosticCommand ,
26+ IDiagnosticHandlerService ,
27+ IInvalidPythonPathInDebuggerService
28+ } from '../types' ;
2329
2430export class InvalidPythonPathInDebuggerSettingsDiagnostic extends BaseDiagnostic {
2531 constructor ( resource : Resource ) {
26- super ( DiagnosticCodes . InvalidPythonPathInDebuggerSettingsDiagnostic ,
27- Diagnostics . invalidPythonPathInDebuggerSettings ( ) , DiagnosticSeverity . Error , DiagnosticScope . WorkspaceFolder ,
28- resource ) ;
32+ super (
33+ DiagnosticCodes . InvalidPythonPathInDebuggerSettingsDiagnostic ,
34+ Diagnostics . invalidPythonPathInDebuggerSettings ( ) ,
35+ DiagnosticSeverity . Error ,
36+ DiagnosticScope . WorkspaceFolder ,
37+ resource
38+ ) ;
2939 }
3040}
3141
3242export class InvalidPythonPathInDebuggerLaunchDiagnostic extends BaseDiagnostic {
3343 constructor ( resource : Resource ) {
34- super ( DiagnosticCodes . InvalidPythonPathInDebuggerLaunchDiagnostic ,
35- Diagnostics . invalidPythonPathInDebuggerLaunch ( ) , DiagnosticSeverity . Error , DiagnosticScope . WorkspaceFolder ,
36- resource ) ;
44+ super (
45+ DiagnosticCodes . InvalidPythonPathInDebuggerLaunchDiagnostic ,
46+ Diagnostics . invalidPythonPathInDebuggerLaunch ( ) ,
47+ DiagnosticSeverity . Error ,
48+ DiagnosticScope . WorkspaceFolder ,
49+ resource
50+ ) ;
3751 }
3852}
3953
4054export const InvalidPythonPathInDebuggerServiceId = 'InvalidPythonPathInDebuggerServiceId' ;
4155
4256@injectable ( )
43- export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService implements IInvalidPythonPathInDebuggerService {
44- constructor ( @inject ( IServiceContainer ) serviceContainer : IServiceContainer ,
57+ export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService
58+ implements IInvalidPythonPathInDebuggerService {
59+ constructor (
60+ @inject ( IServiceContainer ) serviceContainer : IServiceContainer ,
4561 @inject ( IWorkspaceService ) private readonly workspace : IWorkspaceService ,
4662 @inject ( IDiagnosticsCommandFactory ) private readonly commandFactory : IDiagnosticsCommandFactory ,
4763 @inject ( IInterpreterHelper ) private readonly interpreterHelper : IInterpreterHelper ,
4864 @inject ( IConfigurationService ) private readonly configService : IConfigurationService ,
49- @inject ( IDiagnosticHandlerService ) @named ( DiagnosticCommandPromptHandlerServiceId ) protected readonly messageService : IDiagnosticHandlerService < MessageCommandPrompt > ) {
50- super ( [ DiagnosticCodes . InvalidPythonPathInDebuggerSettingsDiagnostic , DiagnosticCodes . InvalidPythonPathInDebuggerLaunchDiagnostic ] , serviceContainer ) ;
65+ @inject ( IDiagnosticHandlerService )
66+ @named ( DiagnosticCommandPromptHandlerServiceId )
67+ protected readonly messageService : IDiagnosticHandlerService < MessageCommandPrompt >
68+ ) {
69+ super (
70+ [
71+ DiagnosticCodes . InvalidPythonPathInDebuggerSettingsDiagnostic ,
72+ DiagnosticCodes . InvalidPythonPathInDebuggerLaunchDiagnostic
73+ ] ,
74+ serviceContainer
75+ ) ;
5176 }
5277 public async diagnose ( _resource : Resource ) : Promise < IDiagnostic [ ] > {
5378 return [ ] ;
5479 }
55- public async handle ( diagnostics : IDiagnostic [ ] ) : Promise < void > {
56- // This class can only handle one type of diagnostic, hence just use first item in list.
57- if ( diagnostics . length === 0 || ! this . canHandle ( diagnostics [ 0 ] ) ) {
58- return ;
59- }
60- const diagnostic = diagnostics [ 0 ] ;
61- const commandPrompts = this . getCommandPrompts ( diagnostic ) ;
62-
63- await this . messageService . handle ( diagnostic , { commandPrompts } ) ;
64- }
6580 public async validatePythonPath ( pythonPath ?: string , resource ?: Uri ) {
6681 pythonPath = pythonPath ? this . resolveVariables ( pythonPath , resource ) : undefined ;
6782 let pathInLaunchJson = true ;
@@ -85,6 +100,16 @@ export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService i
85100 }
86101 return false ;
87102 }
103+ protected async onHandle ( diagnostics : IDiagnostic [ ] ) : Promise < void > {
104+ // This class can only handle one type of diagnostic, hence just use first item in list.
105+ if ( diagnostics . length === 0 || ! this . canHandle ( diagnostics [ 0 ] ) ) {
106+ return ;
107+ }
108+ const diagnostic = diagnostics [ 0 ] ;
109+ const commandPrompts = this . getCommandPrompts ( diagnostic ) ;
110+
111+ await this . messageService . handle ( diagnostic , { commandPrompts } ) ;
112+ }
88113 protected resolveVariables ( pythonPath : string , resource : Uri | undefined ) : string {
89114 const workspaceFolder = resource ? this . workspace . getWorkspaceFolder ( resource ) : undefined ;
90115 const systemVariables = new SystemVariables ( workspaceFolder ? workspaceFolder . uri . fsPath : undefined ) ;
@@ -93,22 +118,30 @@ export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService i
93118 private getCommandPrompts ( diagnostic : IDiagnostic ) : { prompt : string ; command ?: IDiagnosticCommand } [ ] {
94119 switch ( diagnostic . code ) {
95120 case DiagnosticCodes . InvalidPythonPathInDebuggerSettingsDiagnostic : {
96- return [ {
97- prompt : 'Select Python Interpreter' ,
98- command : this . commandFactory . createCommand ( diagnostic , { type : 'executeVSCCommand' , options : 'python.setInterpreter' } )
99- } ] ;
121+ return [
122+ {
123+ prompt : 'Select Python Interpreter' ,
124+ command : this . commandFactory . createCommand ( diagnostic , {
125+ type : 'executeVSCCommand' ,
126+ options : 'python.setInterpreter'
127+ } )
128+ }
129+ ] ;
100130 }
101131 case DiagnosticCodes . InvalidPythonPathInDebuggerLaunchDiagnostic : {
102- return [ {
103- prompt : 'Open launch.json' ,
104- // tslint:disable-next-line:no-object-literal-type-assertion
105- command : {
106- diagnostic, invoke : async ( ) : Promise < void > => {
107- const launchJson = this . getLaunchJsonFile ( workspc . workspaceFolders ! [ 0 ] ) ;
108- await openFile ( launchJson ) ;
132+ return [
133+ {
134+ prompt : 'Open launch.json' ,
135+ // tslint:disable-next-line:no-object-literal-type-assertion
136+ command : {
137+ diagnostic,
138+ invoke : async ( ) : Promise < void > => {
139+ const launchJson = this . getLaunchJsonFile ( workspc . workspaceFolders ! [ 0 ] ) ;
140+ await openFile ( launchJson ) ;
141+ }
109142 }
110143 }
111- } ] ;
144+ ] ;
112145 }
113146 default : {
114147 throw new Error ( 'Invalid diagnostic for \'InvalidPythonPathInDebuggerService\'' ) ;
0 commit comments