Skip to content

Commit c37d81f

Browse files
authored
chore: send "js/ts" and "editor" settings in initialization options (#1367)
- `js/ts`: See microsoft/vscode#292934 - These also need to be sent without defaults resolved, because the server needs to fallback to using `typescript`/`javascript` if they're not explicitly specified. - `editor`: These settings also probably need to be accounted for somewhere with tsc integration, but definitely need to be passed to tsgo. Also removes some very long-deprecated settings.
1 parent 1a20786 commit c37d81f

3 files changed

Lines changed: 67 additions & 101 deletions

File tree

client/src/commands.ts

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,24 @@ export function startLanguageServer(
201201
middleware: {
202202
workspace: {
203203
configuration: (params, token, next) => {
204-
const response = next(params, token) as Record<string, unknown>[];
204+
const response =
205+
(next(params, token) as Record<string, unknown>[]).map((item) =>
206+
JSON.parse(JSON.stringify(item))
207+
) as Record<string, unknown>[];
205208
for (let i = 0; i < response.length; i++) {
206209
const item = params.items[i];
207210
if (item.section == "deno") {
208211
transformDenoConfiguration(extensionContext, response[i]);
209212
}
213+
if (item.section == "js/ts") {
214+
transformToRawConfig(
215+
item.section,
216+
item.scopeUri != null
217+
? vscode.Uri.parse(item.scopeUri)
218+
: null,
219+
response[i],
220+
);
221+
}
210222
}
211223
return response;
212224
},
@@ -227,11 +239,15 @@ export function startLanguageServer(
227239
}
228240
return actions.filter((action) => {
229241
const kind = (action as vscode.CodeAction).kind;
230-
return !kind?.contains(vscode.CodeActionKind.SourceOrganizeImports);
242+
return !kind?.contains(
243+
vscode.CodeActionKind.SourceOrganizeImports,
244+
);
231245
});
232246
},
233247
provideDocumentSymbols: (document, token, next) => {
234-
if (!isProvideSettingEnabled("symbols.document.enabled", document.uri)) {
248+
if (
249+
!isProvideSettingEnabled("symbols.document.enabled", document.uri)
250+
) {
235251
return [];
236252
}
237253
return next(document, token);
@@ -390,6 +406,41 @@ export function transformDenoConfiguration(
390406
}
391407
}
392408

409+
/** Remove fields that weren't explicitly set by the user. */
410+
export function transformToRawConfig(
411+
sectionName: string | undefined,
412+
scopeUri: vscode.Uri | null,
413+
sectionConfig: unknown,
414+
) {
415+
const config = vscode.workspace.getConfiguration(sectionName, scopeUri);
416+
if (typeof sectionConfig != "object" || sectionConfig == null) {
417+
return;
418+
}
419+
for (const [key, value] of Object.entries(sectionConfig)) {
420+
const inspection = config.inspect(key);
421+
if (
422+
inspection != null &&
423+
inspection.globalValue === undefined &&
424+
inspection.workspaceValue === undefined &&
425+
inspection.workspaceFolderValue === undefined &&
426+
inspection.globalLanguageValue === undefined &&
427+
inspection.workspaceLanguageValue === undefined &&
428+
inspection.workspaceFolderLanguageValue === undefined
429+
) {
430+
delete (sectionConfig as Record<string, unknown>)[key];
431+
} else if (value != null && typeof value == "object") {
432+
transformToRawConfig(
433+
`${sectionName}.${key}`,
434+
scopeUri,
435+
value as Record<string, unknown>,
436+
);
437+
if (Object.keys(value).length == 0) {
438+
delete (sectionConfig as Record<string, unknown>)[key];
439+
}
440+
}
441+
}
442+
}
443+
393444
function showWelcomePageIfFirstUse(
394445
context: vscode.ExtensionContext,
395446
extensionContext: DenoExtensionContext,

client/src/extension.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,20 @@ export async function activate(
174174
},
175175
diagnosticCollectionName: "deno",
176176
initializationOptions: () => {
177-
const denoConfiguration = vscode.workspace.getConfiguration().get(
178-
EXTENSION_NS,
179-
) as Record<string, unknown>;
180-
commands.transformDenoConfiguration(extensionContext, denoConfiguration);
177+
const config = vscode.workspace.getConfiguration();
178+
const denoConfig = config.get(EXTENSION_NS) as Record<string, unknown>;
179+
commands.transformDenoConfiguration(extensionContext, denoConfig);
180+
const jsTsConfig = JSON.parse(JSON.stringify(config.get("js/ts")));
181+
commands.transformToRawConfig("js/ts", null, jsTsConfig);
182+
const tsConfig = config.get("typescript");
183+
const jsConfig = config.get("javascript");
184+
const editorConfig = config.get("editor");
181185
return {
182-
...denoConfiguration,
183-
javascript: vscode.workspace.getConfiguration().get("javascript"),
184-
typescript: vscode.workspace.getConfiguration().get("typescript"),
185-
enableBuiltinCommands: true,
186+
...denoConfig,
187+
"js/ts": jsTsConfig,
188+
typescript: tsConfig,
189+
javascript: jsConfig,
190+
editor: editorConfig,
186191
} as object;
187192
},
188193
markdown: {

package.json

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -388,102 +388,12 @@
388388
"C:\\path\\to\\import_map.json"
389389
]
390390
},
391-
"deno.inlayHints.parameterNames.enabled": {
392-
"deprecationMessage": "Use `typescript.inlayHints.parameterNames.enabled` and `javascript.inlayHints.parameterNames.enabled`.",
393-
"type": "string",
394-
"enum": [
395-
"none",
396-
"literals",
397-
"all"
398-
],
399-
"enumDescriptions": [
400-
"Disable inlay hints for parameters.",
401-
"Display inlay hints for literal arguments.",
402-
"Display inlay hints for all literal and non-literal arguments."
403-
],
404-
"default": "none",
405-
"markdownDescription": "Enable/disable inlay hints for parameter names.",
406-
"scope": "resource"
407-
},
408-
"deno.inlayHints.parameterNames.suppressWhenArgumentMatchesName": {
409-
"deprecationMessage": "Use `typescript.inlayHints.parameterNames.suppressWhenArgumentMatchesName` and `javascript.inlayHints.parameterNames.suppressWhenArgumentMatchesName`.",
410-
"type": "boolean",
411-
"default": true,
412-
"markdownDescription": "Do not display an inlay hint when the argument name matches the parameter.",
413-
"scope": "resource"
414-
},
415-
"deno.inlayHints.parameterTypes.enabled": {
416-
"deprecationMessage": "Use `typescript.inlayHints.parameterTypes.enabled` and `javascript.inlayHints.parameterTypes.enabled`.",
417-
"type": "boolean",
418-
"default": false,
419-
"markdownDescription": "Enable/disable inlay hints for implicit parameter types.",
420-
"scope": "resource"
421-
},
422-
"deno.inlayHints.variableTypes.enabled": {
423-
"deprecationMessage": "Use `typescript.inlayHints.variableTypes.enabled` and `javascript.inlayHints.variableTypes.enabled`.",
424-
"type": "boolean",
425-
"default": false,
426-
"markdownDescription": "Enable/disable inlay hints for implicit variable types.",
427-
"scope": "resource"
428-
},
429-
"deno.inlayHints.variableTypes.suppressWhenTypeMatchesName": {
430-
"deprecationMessage": "Use `typescript.inlayHints.variableTypes.suppressWhenTypeMatchesName` and `javascript.inlayHints.variableTypes.suppressWhenTypeMatchesName`.",
431-
"type": "boolean",
432-
"default": true,
433-
"markdownDescription": "Suppress type hints where the variable name matches the implicit type.",
434-
"scope": "resource"
435-
},
436-
"deno.inlayHints.propertyDeclarationTypes.enabled": {
437-
"deprecationMessage": "Use `typescript.inlayHints.propertyDeclarationTypes.enabled` and `javascript.inlayHints.propertyDeclarationTypes.enabled`.",
438-
"type": "boolean",
439-
"default": false,
440-
"markdownDescription": "Enable/disable inlay hints for implicit property declarations.",
441-
"scope": "resource"
442-
},
443-
"deno.inlayHints.functionLikeReturnTypes.enabled": {
444-
"deprecationMessage": "Use `typescript.inlayHints.functionLikeReturnTypes.enabled` and `javascript.inlayHints.functionLikeReturnTypes.enabled`.",
445-
"type": "boolean",
446-
"default": false,
447-
"markdownDescription": "Enable/disable inlay hints for implicit function return types.",
448-
"scope": "resource"
449-
},
450-
"deno.inlayHints.enumMemberValues.enabled": {
451-
"deprecationMessage": "Use `typescript.inlayHints.enumMemberValues.enabled` and `javascript.inlayHints.enumMemberValues.enabled`.",
452-
"type": "boolean",
453-
"default": false,
454-
"markdownDescription": "Enable/disable inlay hints for enum values.",
455-
"scope": "resource"
456-
},
457391
"deno.maxTsServerMemory": {
458392
"type": "number",
459393
"markdownDescription": "Maximum amount of memory the TypeScript isolate can use. Defaults to 3072 (3GB).",
460394
"default": 3072,
461395
"scope": "resource"
462396
},
463-
"deno.suggest.autoImports": {
464-
"deprecationMessage": "Use `typescript.suggest.autoImports` and `javascript.suggest.autoImports`.",
465-
"type": "boolean",
466-
"default": true,
467-
"scope": "resource"
468-
},
469-
"deno.suggest.completeFunctionCalls": {
470-
"deprecationMessage": "Use `typescript.suggest.completeFunctionCalls` and `javascript.suggest.completeFunctionCalls`.",
471-
"type": "boolean",
472-
"default": false,
473-
"scope": "resource"
474-
},
475-
"deno.suggest.names": {
476-
"deprecationMessage": "Use `typescript.suggest.names` and `javascript.suggest.names`.",
477-
"type": "boolean",
478-
"default": true,
479-
"scope": "resource"
480-
},
481-
"deno.suggest.paths": {
482-
"deprecationMessage": "Use `typescript.suggest.paths` and `javascript.suggest.paths`.",
483-
"type": "boolean",
484-
"default": true,
485-
"scope": "resource"
486-
},
487397
"deno.suggest.imports.autoDiscover": {
488398
"type": "boolean",
489399
"default": true,

0 commit comments

Comments
 (0)