Fixing scopes

This commit is contained in:
Matt Bierner
2026-02-18 07:45:46 -08:00
parent 3f8fc43e23
commit cd0e3f3485
3 changed files with 38 additions and 38 deletions

View File

@@ -16,7 +16,7 @@ import * as typeConverters from '../typeConverters';
import { ClientCapability, ITypeScriptServiceClient, ServerResponse } from '../typescriptService';
import TypingsStatus from '../ui/typingsStatus';
import { nulToken } from '../utils/cancellation';
import { readUnifiedConfig } from '../utils/configuration';
import { readUnifiedConfig, UnifiedConfigurationScope } from '../utils/configuration';
import FileConfigurationManager from './fileConfigurationManager';
import { applyCodeAction } from './util/codeAction';
import { conditionalRegistration, requireSomeCapability } from './util/dependentRegistration';
@@ -667,14 +667,14 @@ namespace CompletionConfiguration {
export function getConfigurationForResource(
modeId: string,
resource: vscode.Uri
scope: UnifiedConfigurationScope
): CompletionConfiguration {
const config = vscode.workspace.getConfiguration(modeId, resource);
const config = vscode.workspace.getConfiguration(modeId, scope);
return {
completeFunctionCalls: readUnifiedConfig<boolean>(CompletionConfiguration.completeFunctionCalls, false, { scope: resource, fallbackSection: modeId }),
pathSuggestions: readUnifiedConfig<boolean>(CompletionConfiguration.pathSuggestions, true, { scope: resource, fallbackSection: modeId }),
autoImportSuggestions: readUnifiedConfig<boolean>(CompletionConfiguration.autoImportSuggestions, true, { scope: resource, fallbackSection: modeId }),
nameSuggestions: readUnifiedConfig<boolean>(CompletionConfiguration.nameSuggestions, true, { scope: resource, fallbackSection: modeId }),
completeFunctionCalls: readUnifiedConfig<boolean>(CompletionConfiguration.completeFunctionCalls, false, { scope: scope, fallbackSection: modeId }),
pathSuggestions: readUnifiedConfig<boolean>(CompletionConfiguration.pathSuggestions, true, { scope: scope, fallbackSection: modeId }),
autoImportSuggestions: readUnifiedConfig<boolean>(CompletionConfiguration.autoImportSuggestions, true, { scope: scope, fallbackSection: modeId }),
nameSuggestions: readUnifiedConfig<boolean>(CompletionConfiguration.nameSuggestions, true, { scope: scope, fallbackSection: modeId }),
importStatementSuggestions: config.get<boolean>(CompletionConfiguration.importStatementSuggestions, true),
};
}
@@ -727,7 +727,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
}
const line = document.lineAt(position.line);
const completionConfiguration = CompletionConfiguration.getConfigurationForResource(this.language.id, document.uri);
const completionConfiguration = CompletionConfiguration.getConfigurationForResource(this.language.id, document);
if (!this.shouldTrigger(context, line, position, completionConfiguration)) {
return undefined;

View File

@@ -10,7 +10,7 @@ import { isTypeScriptDocument } from '../configuration/languageIds';
import { API } from '../tsServer/api';
import type * as Proto from '../tsServer/protocol/protocol';
import { ITypeScriptServiceClient } from '../typescriptService';
import { readUnifiedConfig } from '../utils/configuration';
import { readUnifiedConfig, UnifiedConfigurationScope } from '../utils/configuration';
import { Disposable } from '../utils/dispose';
import { equals } from '../utils/objects';
import { ResourceMap } from '../utils/resourceMap';
@@ -150,24 +150,24 @@ export default class FileConfigurationManager extends Disposable {
convertTabsToSpaces: options.insertSpaces,
// We can use \n here since the editor normalizes later on to its line endings.
newLineCharacter: '\n',
insertSpaceAfterCommaDelimiter: readUnifiedConfig<boolean>('format.insertSpaceAfterCommaDelimiter', true, { scope: document.uri, fallbackSection }),
insertSpaceAfterConstructor: readUnifiedConfig<boolean>('format.insertSpaceAfterConstructor', false, { scope: document.uri, fallbackSection }),
insertSpaceAfterSemicolonInForStatements: readUnifiedConfig<boolean>('format.insertSpaceAfterSemicolonInForStatements', true, { scope: document.uri, fallbackSection }),
insertSpaceBeforeAndAfterBinaryOperators: readUnifiedConfig<boolean>('format.insertSpaceBeforeAndAfterBinaryOperators', true, { scope: document.uri, fallbackSection }),
insertSpaceAfterKeywordsInControlFlowStatements: readUnifiedConfig<boolean>('format.insertSpaceAfterKeywordsInControlFlowStatements', true, { scope: document.uri, fallbackSection }),
insertSpaceAfterFunctionKeywordForAnonymousFunctions: readUnifiedConfig<boolean>('format.insertSpaceAfterFunctionKeywordForAnonymousFunctions', true, { scope: document.uri, fallbackSection }),
insertSpaceBeforeFunctionParenthesis: readUnifiedConfig<boolean>('format.insertSpaceBeforeFunctionParenthesis', false, { scope: document.uri, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis', false, { scope: document.uri, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets', false, { scope: document.uri, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces', true, { scope: document.uri, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces', true, { scope: document.uri, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces', false, { scope: document.uri, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces', false, { scope: document.uri, fallbackSection }),
insertSpaceAfterTypeAssertion: readUnifiedConfig<boolean>('format.insertSpaceAfterTypeAssertion', false, { scope: document.uri, fallbackSection }),
placeOpenBraceOnNewLineForFunctions: readUnifiedConfig<boolean>('format.placeOpenBraceOnNewLineForFunctions', false, { scope: document.uri, fallbackSection }),
placeOpenBraceOnNewLineForControlBlocks: readUnifiedConfig<boolean>('format.placeOpenBraceOnNewLineForControlBlocks', false, { scope: document.uri, fallbackSection }),
semicolons: readUnifiedConfig<Proto.SemicolonPreference>('format.semicolons', 'ignore' as Proto.SemicolonPreference, { scope: document.uri, fallbackSection }),
indentSwitchCase: readUnifiedConfig<boolean>('format.indentSwitchCase', true, { scope: document.uri, fallbackSection }),
insertSpaceAfterCommaDelimiter: readUnifiedConfig<boolean>('format.insertSpaceAfterCommaDelimiter', true, { scope: document, fallbackSection }),
insertSpaceAfterConstructor: readUnifiedConfig<boolean>('format.insertSpaceAfterConstructor', false, { scope: document, fallbackSection }),
insertSpaceAfterSemicolonInForStatements: readUnifiedConfig<boolean>('format.insertSpaceAfterSemicolonInForStatements', true, { scope: document, fallbackSection }),
insertSpaceBeforeAndAfterBinaryOperators: readUnifiedConfig<boolean>('format.insertSpaceBeforeAndAfterBinaryOperators', true, { scope: document, fallbackSection }),
insertSpaceAfterKeywordsInControlFlowStatements: readUnifiedConfig<boolean>('format.insertSpaceAfterKeywordsInControlFlowStatements', true, { scope: document, fallbackSection }),
insertSpaceAfterFunctionKeywordForAnonymousFunctions: readUnifiedConfig<boolean>('format.insertSpaceAfterFunctionKeywordForAnonymousFunctions', true, { scope: document, fallbackSection }),
insertSpaceBeforeFunctionParenthesis: readUnifiedConfig<boolean>('format.insertSpaceBeforeFunctionParenthesis', false, { scope: document, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis', false, { scope: document, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets', false, { scope: document, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces', true, { scope: document, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces', true, { scope: document, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces', false, { scope: document, fallbackSection }),
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: readUnifiedConfig<boolean>('format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces', false, { scope: document, fallbackSection }),
insertSpaceAfterTypeAssertion: readUnifiedConfig<boolean>('format.insertSpaceAfterTypeAssertion', false, { scope: document, fallbackSection }),
placeOpenBraceOnNewLineForFunctions: readUnifiedConfig<boolean>('format.placeOpenBraceOnNewLineForFunctions', false, { scope: document, fallbackSection }),
placeOpenBraceOnNewLineForControlBlocks: readUnifiedConfig<boolean>('format.placeOpenBraceOnNewLineForControlBlocks', false, { scope: document, fallbackSection }),
semicolons: readUnifiedConfig<Proto.SemicolonPreference>('format.semicolons', 'ignore' as Proto.SemicolonPreference, { scope: document, fallbackSection }),
indentSwitchCase: readUnifiedConfig<boolean>('format.indentSwitchCase', true, { scope: document, fallbackSection }),
};
}
@@ -211,7 +211,7 @@ export default class FileConfigurationManager extends Disposable {
return preferences;
}
private getAutoImportFileExcludePatternsPreference(scope: vscode.ConfigurationScope, fallbackSection: string, workspaceFolder: vscode.Uri | undefined): string[] | undefined {
private getAutoImportFileExcludePatternsPreference(scope: UnifiedConfigurationScope, fallbackSection: string, workspaceFolder: vscode.Uri | undefined): string[] | undefined {
const patterns = readUnifiedConfig<string[] | undefined>('preferences.autoImportFileExcludePatterns', undefined, { scope, fallbackSection });
return workspaceFolder && patterns?.map(p => {
// Normalization rules: https://github.com/microsoft/TypeScript/pull/49578
@@ -254,7 +254,7 @@ export const InlayHintSettingNames = Object.freeze({
enumMemberValuesEnabled: 'inlayHints.enumMemberValues.enabled',
});
export function getInlayHintsPreferences(scope: vscode.ConfigurationScope, fallbackSection: string) {
export function getInlayHintsPreferences(scope: UnifiedConfigurationScope, fallbackSection: string) {
return {
includeInlayParameterNameHints: getInlayParameterNameHintsPreference(scope, fallbackSection),
includeInlayParameterNameHintsWhenArgumentMatchesName: !readUnifiedConfig<boolean>(InlayHintSettingNames.parameterNamesSuppressWhenArgumentMatchesName, true, { scope, fallbackSection }),
@@ -267,7 +267,7 @@ export function getInlayHintsPreferences(scope: vscode.ConfigurationScope, fallb
} as const;
}
function getInlayParameterNameHintsPreference(scope: vscode.ConfigurationScope, fallbackSection: string) {
function getInlayParameterNameHintsPreference(scope: UnifiedConfigurationScope, fallbackSection: string) {
switch (readUnifiedConfig<string>(InlayHintSettingNames.parameterNamesEnabled, 'none', { scope, fallbackSection })) {
case 'none': return 'none';
case 'literals': return 'literals';
@@ -276,7 +276,7 @@ function getInlayParameterNameHintsPreference(scope: vscode.ConfigurationScope,
}
}
function getQuoteStylePreference(scope: vscode.ConfigurationScope, fallbackSection: string) {
function getQuoteStylePreference(scope: UnifiedConfigurationScope, fallbackSection: string) {
switch (readUnifiedConfig<string>('preferences.quoteStyle', 'auto', { scope, fallbackSection })) {
case 'single': return 'single';
case 'double': return 'double';
@@ -284,7 +284,7 @@ function getQuoteStylePreference(scope: vscode.ConfigurationScope, fallbackSecti
}
}
function getImportModuleSpecifierPreference(scope: vscode.ConfigurationScope, fallbackSection: string) {
function getImportModuleSpecifierPreference(scope: UnifiedConfigurationScope, fallbackSection: string) {
switch (readUnifiedConfig<string>('preferences.importModuleSpecifier', 'shortest', { scope, fallbackSection })) {
case 'project-relative': return 'project-relative';
case 'relative': return 'relative';
@@ -293,7 +293,7 @@ function getImportModuleSpecifierPreference(scope: vscode.ConfigurationScope, fa
}
}
function getImportModuleSpecifierEndingPreference(scope: vscode.ConfigurationScope, fallbackSection: string) {
function getImportModuleSpecifierEndingPreference(scope: UnifiedConfigurationScope, fallbackSection: string) {
switch (readUnifiedConfig<string>('preferences.importModuleSpecifierEnding', 'auto', { scope, fallbackSection })) {
case 'minimal': return 'minimal';
case 'index': return 'index';
@@ -302,7 +302,7 @@ function getImportModuleSpecifierEndingPreference(scope: vscode.ConfigurationSco
}
}
function getJsxAttributeCompletionStyle(scope: vscode.ConfigurationScope, fallbackSection: string) {
function getJsxAttributeCompletionStyle(scope: UnifiedConfigurationScope, fallbackSection: string) {
switch (readUnifiedConfig<string>('preferences.jsxAttributeCompletionStyle', 'auto', { scope, fallbackSection })) {
case 'braces': return 'braces';
case 'none': return 'none';
@@ -310,7 +310,7 @@ function getJsxAttributeCompletionStyle(scope: vscode.ConfigurationScope, fallba
}
}
function getOrganizeImportsPreferences(scope: vscode.ConfigurationScope, fallbackSection: string): Proto.UserPreferences {
function getOrganizeImportsPreferences(scope: UnifiedConfigurationScope, fallbackSection: string): Proto.UserPreferences {
const organizeImportsCollation = readUnifiedConfig<'ordinal' | 'unicode'>('preferences.organizeImports.unicodeCollation', 'ordinal', { scope, fallbackSection });
const organizeImportsCaseSensitivity = readUnifiedConfig<'auto' | 'caseInsensitive' | 'caseSensitive'>('preferences.organizeImports.caseSensitivity', 'auto', { scope, fallbackSection });
return {

View File

@@ -5,12 +5,12 @@
import * as vscode from 'vscode';
type ConfigurationScope = vscode.ConfigurationScope | null | undefined;
export type UnifiedConfigurationScope = vscode.TextDocument | null | undefined;
export const unifiedConfigSection = 'js/ts';
export type ReadUnifiedConfigOptions = {
readonly scope?: ConfigurationScope;
readonly scope?: UnifiedConfigurationScope;
readonly fallbackSection: string;
readonly fallbackSubSectionNameOverride?: string;
};
@@ -61,7 +61,7 @@ function hasModifiedValue(inspect: ReturnType<vscode.WorkspaceConfiguration['ins
export function hasModifiedUnifiedConfig(
subSectionName: string,
options: {
readonly scope?: ConfigurationScope;
readonly scope?: UnifiedConfigurationScope;
readonly fallbackSection: string;
}
): boolean {