Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update linter and formatter warning notifications #22292

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client/extensionActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { IInterpreterQuickPick } from './interpreter/configuration/types';
import { registerAllCreateEnvironmentFeatures } from './pythonEnvironments/creation/registrations';
import { registerCreateEnvironmentTriggers } from './pythonEnvironments/creation/createEnvironmentTrigger';
import { initializePersistentStateForTriggers } from './common/persistentState';
import { logAndNotifyOnFormatterSetting } from './logging/settingLogs';
import { logAndNotifyOnLegacySettings } from './logging/settingLogs';

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

logAndNotifyOnFormatterSetting();
logAndNotifyOnLegacySettings();
registerCreateEnvironmentTriggers(disposables);
initializePersistentStateForTriggers(ext.context);
}
Expand Down
85 changes: 74 additions & 11 deletions src/client/logging/settingLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { traceError, traceInfo } from '.';
import { Commands, PVSC_EXTENSION_ID } from '../common/constants';
import { showErrorMessage } from '../common/vscodeApis/windowApis';
import { getConfiguration, getWorkspaceFolders } from '../common/vscodeApis/workspaceApis';
import { Common } from '../common/utils/localize';
import { executeCommand } from '../common/vscodeApis/commandApis';

export function logAndNotifyOnFormatterSetting(): void {
function logOnLegacyFormatterSetting(): boolean {
let usesLegacyFormatter = false;
getWorkspaceFolders()?.forEach(async (workspace) => {
let config = getConfiguration('editor', { uri: workspace.uri, languageId: 'python' });
if (!config) {
Expand All @@ -21,22 +20,86 @@ export function logAndNotifyOnFormatterSetting(): void {
const formatter = config.get<string>('defaultFormatter', '');
traceInfo(`Default formatter is set to ${formatter} for workspace ${workspace.uri.fsPath}`);
if (formatter === PVSC_EXTENSION_ID) {
usesLegacyFormatter = true;
traceError('Formatting features have been moved to separate formatter extensions.');
traceError('See here for more information: https://code.visualstudio.com/docs/python/formatting');
traceError('Please install the formatter extension you prefer and set it as the default formatter.');
traceError('For `autopep8` use: https://marketplace.visualstudio.com/items?itemName=ms-python.autopep8');
traceError(
'For `black` use: https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter',
);
traceError('For `yapf` use: https://marketplace.visualstudio.com/items?itemName=eeyore.yapf');
const response = await showErrorMessage(
l10n.t(
'Formatting features have been moved to separate formatter extensions. Please install the formatter extension you prefer and set it as the default formatter.',
),
Common.showLogs,
);
if (response === Common.showLogs) {
executeCommand(Commands.ViewOutput);
}
});
return usesLegacyFormatter;
}

function logOnLegacyLinterSetting(): boolean {
let usesLegacyLinter = false;
getWorkspaceFolders()?.forEach(async (workspace) => {
let config = getConfiguration('python', { uri: workspace.uri, languageId: 'python' });
if (!config) {
config = getConfiguration('python', workspace.uri);
if (!config) {
traceError('Unable to get editor configuration');
}
}

const linters: string[] = [
'pylint',
'flake8',
'mypy',
'pydocstyle',
'pylama',
'pycodestyle',
'bandit',
'prospector',
];

linters.forEach((linter) => {
const linterEnabled = config.get<boolean>(`linting.${linter}Enabled`, false);
if (linterEnabled) {
usesLegacyLinter = true;
traceError('Linting features have been moved to separate linter extensions.');
traceError('See here for more information: https://code.visualstudio.com/docs/python/linting');
if (linter === 'pylint' || linter === 'flake8') {
traceError(
`Please install "${linter}" extension: https://marketplace.visualstudio.com/items?itemName=ms-python.${linter}`,
);
} else if (linter === 'mypy') {
traceError(
`Please install "${linter}" extension: https://marketplace.visualstudio.com/items?itemName=ms-python.mypy-type-checker`,
);
} else if (['pydocstyle', 'pylama', 'pycodestyle', 'bandit'].includes(linter)) {
traceError(
`selected linter "${linter}" may be supported by extensions like "Ruff", which include several linter rules: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff`,
);
}
}
});
});

return usesLegacyLinter;
}

let _isShown = false;
async function notifyLegacySettings(): Promise<void> {
if (_isShown) {
return;
}
_isShown = true;
showErrorMessage(
l10n.t(
`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.`,
),
);
}

export function logAndNotifyOnLegacySettings(): void {
const usesLegacyFormatter = logOnLegacyFormatterSetting();
const usesLegacyLinter = logOnLegacyLinterSetting();

if (usesLegacyFormatter || usesLegacyLinter) {
setImmediate(() => notifyLegacySettings().ignoreErrors());
}
}
Loading