@@ -6,6 +6,7 @@ import { inject, injectable } from 'inversify';
6
6
import { DiagnosticSeverity } from 'vscode' ;
7
7
import '../../../common/extensions' ;
8
8
import * as nls from 'vscode-nls' ;
9
+ import * as path from 'path' ;
9
10
import { IDisposableRegistry , Resource } from '../../../common/types' ;
10
11
import { IInterpreterService } from '../../../interpreter/contracts' ;
11
12
import { IServiceContainer } from '../../../ioc/types' ;
@@ -16,6 +17,7 @@ import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '.
16
17
import { DiagnosticScope , IDiagnostic , IDiagnosticCommand , IDiagnosticHandlerService } from '../types' ;
17
18
import { Common } from '../../../common/utils/localize' ;
18
19
import { Commands } from '../../../common/constants' ;
20
+ import { IWorkspaceService } from '../../../common/application/types' ;
19
21
20
22
const localize : nls . LocalizeFunc = nls . loadMessageBundle ( ) ;
21
23
@@ -26,16 +28,31 @@ const messages = {
26
28
) ,
27
29
[ DiagnosticCodes . InvalidPythonInterpreterDiagnostic ] : localize (
28
30
'DiagnosticCodes.NoCurrentlySelectedPythonInterpreterDiagnostic' ,
29
- 'An Invalid Python interpreter is selected, please try changing it to enable features such as IntelliSense, linting, and debugging.' ,
31
+ 'An Invalid Python interpreter is selected{0} , please try changing it to enable features such as IntelliSense, linting, and debugging.' ,
30
32
) ,
31
33
} ;
32
34
33
35
export class InvalidPythonInterpreterDiagnostic extends BaseDiagnostic {
34
36
constructor (
35
37
code : DiagnosticCodes . NoPythonInterpretersDiagnostic | DiagnosticCodes . InvalidPythonInterpreterDiagnostic ,
36
38
resource : Resource ,
39
+ workspaceService : IWorkspaceService ,
37
40
) {
38
- super ( code , messages [ code ] , DiagnosticSeverity . Error , DiagnosticScope . WorkspaceFolder , resource ) ;
41
+ let formatArg = '' ;
42
+ if ( workspaceService . workspaceFile ) {
43
+ // Specify folder name in case of multiroot scenarios
44
+ const folder = workspaceService . getWorkspaceFolder ( resource ) ;
45
+ if ( folder ) {
46
+ formatArg = ` for ${ path . basename ( folder . uri . fsPath ) } ` ;
47
+ }
48
+ }
49
+ super (
50
+ code ,
51
+ messages [ code ] . format ( formatArg ) ,
52
+ DiagnosticSeverity . Error ,
53
+ DiagnosticScope . WorkspaceFolder ,
54
+ resource ,
55
+ ) ;
39
56
}
40
57
}
41
58
@@ -56,17 +73,28 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService {
56
73
}
57
74
58
75
public async diagnose ( resource : Resource ) : Promise < IDiagnostic [ ] > {
76
+ const workspaceService = this . serviceContainer . get < IWorkspaceService > ( IWorkspaceService ) ;
59
77
const interpreterService = this . serviceContainer . get < IInterpreterService > ( IInterpreterService ) ;
60
78
const hasInterpreters = await interpreterService . hasInterpreters ( ) ;
61
79
62
80
if ( ! hasInterpreters ) {
63
- return [ new InvalidPythonInterpreterDiagnostic ( DiagnosticCodes . NoPythonInterpretersDiagnostic , resource ) ] ;
81
+ return [
82
+ new InvalidPythonInterpreterDiagnostic (
83
+ DiagnosticCodes . NoPythonInterpretersDiagnostic ,
84
+ resource ,
85
+ workspaceService ,
86
+ ) ,
87
+ ] ;
64
88
}
65
89
66
90
const currentInterpreter = await interpreterService . getActiveInterpreter ( resource ) ;
67
91
if ( ! currentInterpreter ) {
68
92
return [
69
- new InvalidPythonInterpreterDiagnostic ( DiagnosticCodes . InvalidPythonInterpreterDiagnostic , resource ) ,
93
+ new InvalidPythonInterpreterDiagnostic (
94
+ DiagnosticCodes . InvalidPythonInterpreterDiagnostic ,
95
+ resource ,
96
+ workspaceService ,
97
+ ) ,
70
98
] ;
71
99
}
72
100
return [ ] ;
0 commit comments