4
4
import { ConfigurationChangeEvent , ConfigurationScope , Uri , WorkspaceConfiguration , WorkspaceFolder } from 'vscode' ;
5
5
import { getInterpreterDetails } from './python' ;
6
6
import { getConfiguration , getWorkspaceFolders } from './vscodeapi' ;
7
- import { traceInfo , traceLog , traceWarn } from './logging' ;
7
+ import { traceError , traceInfo , traceLog , traceWarn } from './logging' ;
8
8
import { EXTENSION_ID } from './constants' ;
9
9
import { TransportKind } from 'vscode-languageclient/node' ;
10
+ import { trace } from 'console' ;
10
11
11
12
export interface ISettings {
12
13
cwd : string ;
@@ -30,10 +31,23 @@ export function getExtensionSettings(namespace: string, includeInterpreter?: boo
30
31
31
32
function resolveVariables (
32
33
value : string [ ] ,
34
+ key : string ,
33
35
workspace ?: WorkspaceFolder ,
34
36
interpreter ?: string [ ] ,
35
37
env ?: NodeJS . ProcessEnv ,
36
38
) : 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
+
37
51
const substitutions = new Map < string , string > ( ) ;
38
52
const home = process . env . HOME || process . env . USERPROFILE ;
39
53
if ( home ) {
@@ -75,7 +89,7 @@ function resolveVariables(
75
89
76
90
function getCwd ( config : WorkspaceConfiguration , workspace : WorkspaceFolder ) : string {
77
91
const cwd = config . get < string > ( 'cwd' , workspace . uri . fsPath ) ;
78
- return resolveVariables ( [ cwd ] , workspace ) [ 0 ] ;
92
+ return resolveVariables ( [ cwd ] , 'cwd' , workspace ) [ 0 ] ;
79
93
}
80
94
81
95
export function getInterpreterFromSetting ( namespace : string , scope ?: ConfigurationScope ) {
@@ -115,12 +129,15 @@ export async function getWorkspaceSettings(
115
129
const workspaceSetting = {
116
130
cwd : getCwd ( config , workspace ) ,
117
131
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 ) ,
121
135
importStrategy : config . get < string > ( 'importStrategy' , 'useBundled' ) ,
122
136
showNotifications : config . get < string > ( 'showNotifications' , 'off' ) ,
123
137
} ;
138
+ traceInfo (
139
+ `Workspace settings for ${ workspace . uri . fsPath } (client side): ${ JSON . stringify ( workspaceSetting , null , 4 ) } ` ,
140
+ ) ;
124
141
return workspaceSetting ;
125
142
}
126
143
@@ -149,6 +166,7 @@ export async function getGlobalSettings(namespace: string, includeInterpreter?:
149
166
importStrategy : getGlobalValue < string > ( config , 'importStrategy' ) ?? 'useBundled' ,
150
167
showNotifications : getGlobalValue < string > ( config , 'showNotifications' ) ?? 'off' ,
151
168
} ;
169
+ traceInfo ( `Global settings (client side): ${ JSON . stringify ( setting , null , 4 ) } ` ) ;
152
170
return setting ;
153
171
}
154
172
0 commit comments