Skip to content

Commit b19ba19

Browse files
authored
Drop legacy settings support (#339)
1 parent 60ec6df commit b19ba19

File tree

2 files changed

+38
-32
lines changed

2 files changed

+38
-32
lines changed

src/common/settings.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,6 @@ function resolveVariables(value: string[], workspace?: WorkspaceFolder): string[
4343
});
4444
}
4545

46-
function getArgs(namespace: string, workspace: WorkspaceFolder): string[] {
47-
const config = getConfiguration(namespace, workspace.uri);
48-
const args = config.get<string[]>('args', []);
49-
50-
if (args.length > 0) {
51-
return args;
52-
}
53-
54-
const legacyConfig = getConfiguration('python', workspace.uri);
55-
return legacyConfig.get<string[]>('formatting.blackArgs', []);
56-
}
57-
58-
function getPath(namespace: string, workspace: WorkspaceFolder): string[] {
59-
const config = getConfiguration(namespace, workspace.uri);
60-
const path = config.get<string[]>('path', []);
61-
62-
if (path.length > 0) {
63-
return path;
64-
}
65-
66-
const legacyConfig = getConfiguration('python', workspace.uri);
67-
const legacyPath = legacyConfig.get<string>('formatting.blackPath', '');
68-
if (legacyPath.length > 0 && legacyPath !== 'black') {
69-
return [legacyPath];
70-
}
71-
return [];
72-
}
73-
7446
export function getInterpreterFromSetting(namespace: string, scope?: ConfigurationScope) {
7547
const config = getConfiguration(namespace, scope);
7648
return config.get<string[]>('interpreter');
@@ -105,13 +77,11 @@ export async function getWorkspaceSettings(
10577
}
10678
}
10779

108-
const args = getArgs(namespace, workspace);
109-
const path = getPath(namespace, workspace);
11080
const workspaceSetting = {
11181
cwd: workspace.uri.fsPath,
11282
workspace: workspace.uri.toString(),
113-
args: resolveVariables(args, workspace),
114-
path: resolveVariables(path, workspace),
83+
args: resolveVariables(config.get<string[]>('args', []), workspace),
84+
path: resolveVariables(config.get<string[]>('path', []), workspace),
11585
interpreter: resolveVariables(interpreter, workspace),
11686
importStrategy: config.get<string>('importStrategy', 'fromEnvironment'),
11787
showNotifications: config.get<string>('showNotifications', 'off'),
@@ -177,3 +147,26 @@ export function logDefaultFormatter(): void {
177147
}
178148
});
179149
}
150+
151+
export function logLegacySettings(): void {
152+
getWorkspaceFolders().forEach((workspace) => {
153+
try {
154+
const legacyConfig = getConfiguration('python', workspace.uri);
155+
const legacyArgs = legacyConfig.get<string[]>('formatting.blackArgs', []);
156+
const legacyPath = legacyConfig.get<string>('formatting.blackPath', '');
157+
if (legacyArgs.length > 0) {
158+
traceWarn(`"python.formatting.blackArgs" is deprecated. Use "black-formatter.args" instead.`);
159+
traceWarn(`"python.formatting.blackArgs" for workspace ${workspace.uri.fsPath}:`);
160+
traceWarn(`\n${JSON.stringify(legacyArgs, null, 4)}`);
161+
}
162+
163+
if (legacyPath.length > 0 && legacyPath !== 'black') {
164+
traceWarn(`"python.formatting.blackPath" is deprecated. Use "black-formatter.path" instead.`);
165+
traceWarn(`"python.formatting.blackPath" for workspace ${workspace.uri.fsPath}:`);
166+
traceWarn(`\n${JSON.stringify(legacyPath, null, 4)}`);
167+
}
168+
} catch (err) {
169+
traceWarn(`Error while logging legacy settings: ${err}`);
170+
}
171+
});
172+
}

src/extension.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getWorkspaceSettings,
1414
ISettings,
1515
logDefaultFormatter,
16+
logLegacySettings,
1617
} from './common/settings';
1718
import { loadServerDefaults } from './common/setup';
1819
import { getProjectRoot } from './common/utilities';
@@ -72,10 +73,22 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
7273
registerLanguageStatusItem(serverId, serverName, `${serverId}.showLogs`),
7374
);
7475

76+
// This is needed to ensure that the formatter is registered before the
77+
// language server is started. If the language server takes too long to start,
78+
// and user triggers formatting, they can see a weird message that formatting
79+
// although registered by extension it is not supported.
7580
registerEmptyFormatter();
7681

82+
// This is needed to inform users that they might have not set this extension
83+
// as the formatter. Instructions are printed in the output channel on how to
84+
// set it.
7785
logDefaultFormatter();
7886

87+
// This is needed to inform users that they might have some legacy settings that
88+
// are no longer supported. Instructions are printed in the output channel on how
89+
// to update them.
90+
logLegacySettings();
91+
7992
setImmediate(async () => {
8093
const interpreter = getInterpreterFromSetting(serverId);
8194
if (interpreter === undefined || interpreter.length === 0) {

0 commit comments

Comments
 (0)