Skip to content

Commit c3afea5

Browse files
karthiknadigluabud
andauthored
Update linter and formatter warning notifications (microsoft#22292)
closes microsoft#22272 --------- Co-authored-by: Luciana Abud <[email protected]>
1 parent 3c88f27 commit c3afea5

File tree

2 files changed

+76
-13
lines changed

2 files changed

+76
-13
lines changed

src/client/extensionActivation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { IInterpreterQuickPick } from './interpreter/configuration/types';
5151
import { registerAllCreateEnvironmentFeatures } from './pythonEnvironments/creation/registrations';
5252
import { registerCreateEnvironmentTriggers } from './pythonEnvironments/creation/createEnvironmentTrigger';
5353
import { initializePersistentStateForTriggers } from './common/persistentState';
54-
import { logAndNotifyOnFormatterSetting } from './logging/settingLogs';
54+
import { logAndNotifyOnLegacySettings } from './logging/settingLogs';
5555

5656
export async function activateComponents(
5757
// `ext` is passed to any extra activation funcs.
@@ -183,7 +183,7 @@ async function activateLegacy(ext: ExtensionState): Promise<ActivationResult> {
183183
),
184184
);
185185

186-
logAndNotifyOnFormatterSetting();
186+
logAndNotifyOnLegacySettings();
187187
registerCreateEnvironmentTriggers(disposables);
188188
initializePersistentStateForTriggers(ext.context);
189189
}

src/client/logging/settingLogs.ts

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import { traceError, traceInfo } from '.';
66
import { Commands, PVSC_EXTENSION_ID } from '../common/constants';
77
import { showErrorMessage } from '../common/vscodeApis/windowApis';
88
import { getConfiguration, getWorkspaceFolders } from '../common/vscodeApis/workspaceApis';
9-
import { Common } from '../common/utils/localize';
10-
import { executeCommand } from '../common/vscodeApis/commandApis';
119

12-
export function logAndNotifyOnFormatterSetting(): void {
10+
function logOnLegacyFormatterSetting(): boolean {
11+
let usesLegacyFormatter = false;
1312
getWorkspaceFolders()?.forEach(async (workspace) => {
1413
let config = getConfiguration('editor', { uri: workspace.uri, languageId: 'python' });
1514
if (!config) {
@@ -21,22 +20,86 @@ export function logAndNotifyOnFormatterSetting(): void {
2120
const formatter = config.get<string>('defaultFormatter', '');
2221
traceInfo(`Default formatter is set to ${formatter} for workspace ${workspace.uri.fsPath}`);
2322
if (formatter === PVSC_EXTENSION_ID) {
23+
usesLegacyFormatter = true;
2424
traceError('Formatting features have been moved to separate formatter extensions.');
25+
traceError('See here for more information: https://code.visualstudio.com/docs/python/formatting');
2526
traceError('Please install the formatter extension you prefer and set it as the default formatter.');
2627
traceError('For `autopep8` use: https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8');
2728
traceError(
2829
'For `black` use: https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter',
2930
);
3031
traceError('For `yapf` use: https://marketplace.visualstudio.com/items?itemName=eeyore.yapf');
31-
const response = await showErrorMessage(
32-
l10n.t(
33-
'Formatting features have been moved to separate formatter extensions. Please install the formatter extension you prefer and set it as the default formatter.',
34-
),
35-
Common.showLogs,
36-
);
37-
if (response === Common.showLogs) {
38-
executeCommand(Commands.ViewOutput);
32+
}
33+
});
34+
return usesLegacyFormatter;
35+
}
36+
37+
function logOnLegacyLinterSetting(): boolean {
38+
let usesLegacyLinter = false;
39+
getWorkspaceFolders()?.forEach(async (workspace) => {
40+
let config = getConfiguration('python', { uri: workspace.uri, languageId: 'python' });
41+
if (!config) {
42+
config = getConfiguration('python', workspace.uri);
43+
if (!config) {
44+
traceError('Unable to get editor configuration');
3945
}
4046
}
47+
48+
const linters: string[] = [
49+
'pylint',
50+
'flake8',
51+
'mypy',
52+
'pydocstyle',
53+
'pylama',
54+
'pycodestyle',
55+
'bandit',
56+
'prospector',
57+
];
58+
59+
linters.forEach((linter) => {
60+
const linterEnabled = config.get<boolean>(`linting.${linter}Enabled`, false);
61+
if (linterEnabled) {
62+
usesLegacyLinter = true;
63+
traceError('Linting features have been moved to separate linter extensions.');
64+
traceError('See here for more information: https://code.visualstudio.com/docs/python/linting');
65+
if (linter === 'pylint' || linter === 'flake8') {
66+
traceError(
67+
`Please install "${linter}" extension: https://marketplace.visualstudio.com/items?itemName=ms-python.${linter}`,
68+
);
69+
} else if (linter === 'mypy') {
70+
traceError(
71+
`Please install "${linter}" extension: https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker`,
72+
);
73+
} else if (['pydocstyle', 'pylama', 'pycodestyle', 'bandit'].includes(linter)) {
74+
traceError(
75+
`selected linter "${linter}" may be supported by extensions like "Ruff", which include several linter rules: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff`,
76+
);
77+
}
78+
}
79+
});
4180
});
81+
82+
return usesLegacyLinter;
83+
}
84+
85+
let _isShown = false;
86+
async function notifyLegacySettings(): Promise<void> {
87+
if (_isShown) {
88+
return;
89+
}
90+
_isShown = true;
91+
showErrorMessage(
92+
l10n.t(
93+
`Formatting and linting features have been deprecated from the Python extension. Please install a linter or a formatter extension. [Open logs](command:${Commands.ViewOutput}) for more information.`,
94+
),
95+
);
96+
}
97+
98+
export function logAndNotifyOnLegacySettings(): void {
99+
const usesLegacyFormatter = logOnLegacyFormatterSetting();
100+
const usesLegacyLinter = logOnLegacyLinterSetting();
101+
102+
if (usesLegacyFormatter || usesLegacyLinter) {
103+
setImmediate(() => notifyLegacySettings().ignoreErrors());
104+
}
42105
}

0 commit comments

Comments
 (0)