Skip to content

Commit 399a915

Browse files
authored
Add logging to make it easier to find settings issues (#496)
1 parent fd92564 commit 399a915

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

bundled/tool/lsp_server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ def initialize(params: lsp.InitializeParams) -> None:
268268
settings = params.initialization_options["settings"]
269269
_update_workspace_settings(settings)
270270
log_to_output(
271-
f"Settings used to run Server:\r\n{json.dumps(settings, indent=4, ensure_ascii=False)}\r\n"
271+
f"Settings received on server:\r\n{json.dumps(settings, indent=4, ensure_ascii=False)}\r\n"
272272
)
273273
log_to_output(
274-
f"Global settings:\r\n{json.dumps(GLOBAL_SETTINGS, indent=4, ensure_ascii=False)}\r\n"
274+
f"Global settings received on server:\r\n{json.dumps(GLOBAL_SETTINGS, indent=4, ensure_ascii=False)}\r\n"
275275
)
276276

277277
paths = "\r\n ".join(sys.path)

src/common/settings.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import { ConfigurationChangeEvent, ConfigurationScope, Uri, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
55
import { getInterpreterDetails } from './python';
66
import { getConfiguration, getWorkspaceFolders } from './vscodeapi';
7-
import { traceInfo, traceLog, traceWarn } from './logging';
7+
import { traceError, traceInfo, traceLog, traceWarn } from './logging';
88
import { EXTENSION_ID } from './constants';
99
import { TransportKind } from 'vscode-languageclient/node';
10+
import { trace } from 'console';
1011

1112
export interface ISettings {
1213
cwd: string;
@@ -30,10 +31,23 @@ export function getExtensionSettings(namespace: string, includeInterpreter?: boo
3031

3132
function resolveVariables(
3233
value: string[],
34+
key: string,
3335
workspace?: WorkspaceFolder,
3436
interpreter?: string[],
3537
env?: NodeJS.ProcessEnv,
3638
): string[] {
39+
for (const v of value) {
40+
if (typeof v !== 'string') {
41+
traceError(`Value [${v}] must be "string" for \`black-formatter.${key}\`: ${value}`);
42+
throw new Error(`Value [${v}] must be "string" for \`black-formatter.${key}\`: ${value}`);
43+
}
44+
if (v.startsWith('--') && v.includes(' ')) {
45+
traceError(
46+
`Settings should be in the form ["--line-length=88"] or ["--line-length", "88"] but not ["--line-length 88"]`,
47+
);
48+
}
49+
}
50+
3751
const substitutions = new Map<string, string>();
3852
const home = process.env.HOME || process.env.USERPROFILE;
3953
if (home) {
@@ -75,7 +89,7 @@ function resolveVariables(
7589

7690
function getCwd(config: WorkspaceConfiguration, workspace: WorkspaceFolder): string {
7791
const cwd = config.get<string>('cwd', workspace.uri.fsPath);
78-
return resolveVariables([cwd], workspace)[0];
92+
return resolveVariables([cwd], 'cwd', workspace)[0];
7993
}
8094

8195
export function getInterpreterFromSetting(namespace: string, scope?: ConfigurationScope) {
@@ -115,12 +129,15 @@ export async function getWorkspaceSettings(
115129
const workspaceSetting = {
116130
cwd: getCwd(config, workspace),
117131
workspace: workspace.uri.toString(),
118-
args: resolveVariables(config.get<string[]>('args', []), workspace),
119-
path: resolveVariables(config.get<string[]>('path', []), workspace, interpreter),
120-
interpreter: resolveVariables(interpreter, workspace),
132+
args: resolveVariables(config.get<string[]>('args', []), 'args', workspace),
133+
path: resolveVariables(config.get<string[]>('path', []), 'path', workspace, interpreter),
134+
interpreter: resolveVariables(interpreter, 'interpreter', workspace),
121135
importStrategy: config.get<string>('importStrategy', 'useBundled'),
122136
showNotifications: config.get<string>('showNotifications', 'off'),
123137
};
138+
traceInfo(
139+
`Workspace settings for ${workspace.uri.fsPath} (client side): ${JSON.stringify(workspaceSetting, null, 4)}`,
140+
);
124141
return workspaceSetting;
125142
}
126143

@@ -149,6 +166,7 @@ export async function getGlobalSettings(namespace: string, includeInterpreter?:
149166
importStrategy: getGlobalValue<string>(config, 'importStrategy') ?? 'useBundled',
150167
showNotifications: getGlobalValue<string>(config, 'showNotifications') ?? 'off',
151168
};
169+
traceInfo(`Global settings (client side): ${JSON.stringify(setting, null, 4)}`);
152170
return setting;
153171
}
154172

0 commit comments

Comments
 (0)