Skip to content

Commit a76f230

Browse files
author
Kartik Raj
committed
Specify folder name in case of multiroot scenarios
1 parent 1201499 commit a76f230

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/client/application/diagnostics/checks/pythonInterpreter.ts

+32-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { inject, injectable } from 'inversify';
66
import { DiagnosticSeverity } from 'vscode';
77
import '../../../common/extensions';
88
import * as nls from 'vscode-nls';
9+
import * as path from 'path';
910
import { IDisposableRegistry, Resource } from '../../../common/types';
1011
import { IInterpreterService } from '../../../interpreter/contracts';
1112
import { IServiceContainer } from '../../../ioc/types';
@@ -16,6 +17,7 @@ import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '.
1617
import { DiagnosticScope, IDiagnostic, IDiagnosticCommand, IDiagnosticHandlerService } from '../types';
1718
import { Common } from '../../../common/utils/localize';
1819
import { Commands } from '../../../common/constants';
20+
import { IWorkspaceService } from '../../../common/application/types';
1921

2022
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
2123

@@ -26,16 +28,31 @@ const messages = {
2628
),
2729
[DiagnosticCodes.InvalidPythonInterpreterDiagnostic]: localize(
2830
'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.',
3032
),
3133
};
3234

3335
export class InvalidPythonInterpreterDiagnostic extends BaseDiagnostic {
3436
constructor(
3537
code: DiagnosticCodes.NoPythonInterpretersDiagnostic | DiagnosticCodes.InvalidPythonInterpreterDiagnostic,
3638
resource: Resource,
39+
workspaceService: IWorkspaceService,
3740
) {
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+
);
3956
}
4057
}
4158

@@ -56,17 +73,28 @@ export class InvalidPythonInterpreterService extends BaseDiagnosticsService {
5673
}
5774

5875
public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
76+
const workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
5977
const interpreterService = this.serviceContainer.get<IInterpreterService>(IInterpreterService);
6078
const hasInterpreters = await interpreterService.hasInterpreters();
6179

6280
if (!hasInterpreters) {
63-
return [new InvalidPythonInterpreterDiagnostic(DiagnosticCodes.NoPythonInterpretersDiagnostic, resource)];
81+
return [
82+
new InvalidPythonInterpreterDiagnostic(
83+
DiagnosticCodes.NoPythonInterpretersDiagnostic,
84+
resource,
85+
workspaceService,
86+
),
87+
];
6488
}
6589

6690
const currentInterpreter = await interpreterService.getActiveInterpreter(resource);
6791
if (!currentInterpreter) {
6892
return [
69-
new InvalidPythonInterpreterDiagnostic(DiagnosticCodes.InvalidPythonInterpreterDiagnostic, resource),
93+
new InvalidPythonInterpreterDiagnostic(
94+
DiagnosticCodes.InvalidPythonInterpreterDiagnostic,
95+
resource,
96+
workspaceService,
97+
),
7098
];
7199
}
72100
return [];

0 commit comments

Comments
 (0)