Skip to content

Commit

Permalink
Update linter and formatter warning notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Oct 23, 2023
1 parent 9e07503 commit c19652b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 11 deletions.
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
90 changes: 81 additions & 9 deletions src/client/logging/settingLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { getConfiguration, getWorkspaceFolders } from '../common/vscodeApis/work
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 +22,93 @@ 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 suported extensions like "ruff" which include several linter rules`,
);
traceError(
`Please install extension: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff`,
);
}
}
});
});

return usesLegacyLinter;
}

let _isShown = false;
async function notifyLegacySettings(): Promise<void> {
if (_isShown) {
return;
}
_isShown = true;
const response = await showErrorMessage(
l10n.t(
'Formatting and Linting features have been moved to separate extensions. Please see the logs for more information.',
),
Common.showLogs,
);
if (response === Common.showLogs) {
executeCommand(Commands.ViewOutput);
}
}

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

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

0 comments on commit c19652b

Please sign in to comment.