diff --git a/extensions/typescript-language-features/src/languageFeatures/completions.ts b/extensions/typescript-language-features/src/languageFeatures/completions.ts index a6378deaece..030bb84ea00 100644 --- a/extensions/typescript-language-features/src/languageFeatures/completions.ts +++ b/extensions/typescript-language-features/src/languageFeatures/completions.ts @@ -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(CompletionConfiguration.completeFunctionCalls, false, { scope: resource, fallbackSection: modeId }), - pathSuggestions: readUnifiedConfig(CompletionConfiguration.pathSuggestions, true, { scope: resource, fallbackSection: modeId }), - autoImportSuggestions: readUnifiedConfig(CompletionConfiguration.autoImportSuggestions, true, { scope: resource, fallbackSection: modeId }), - nameSuggestions: readUnifiedConfig(CompletionConfiguration.nameSuggestions, true, { scope: resource, fallbackSection: modeId }), + completeFunctionCalls: readUnifiedConfig(CompletionConfiguration.completeFunctionCalls, false, { scope: scope, fallbackSection: modeId }), + pathSuggestions: readUnifiedConfig(CompletionConfiguration.pathSuggestions, true, { scope: scope, fallbackSection: modeId }), + autoImportSuggestions: readUnifiedConfig(CompletionConfiguration.autoImportSuggestions, true, { scope: scope, fallbackSection: modeId }), + nameSuggestions: readUnifiedConfig(CompletionConfiguration.nameSuggestions, true, { scope: scope, fallbackSection: modeId }), importStatementSuggestions: config.get(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; diff --git a/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts b/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts index 0ee2aac2278..21f48f20d63 100644 --- a/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts +++ b/extensions/typescript-language-features/src/languageFeatures/fileConfigurationManager.ts @@ -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('format.insertSpaceAfterCommaDelimiter', true, { scope: document.uri, fallbackSection }), - insertSpaceAfterConstructor: readUnifiedConfig('format.insertSpaceAfterConstructor', false, { scope: document.uri, fallbackSection }), - insertSpaceAfterSemicolonInForStatements: readUnifiedConfig('format.insertSpaceAfterSemicolonInForStatements', true, { scope: document.uri, fallbackSection }), - insertSpaceBeforeAndAfterBinaryOperators: readUnifiedConfig('format.insertSpaceBeforeAndAfterBinaryOperators', true, { scope: document.uri, fallbackSection }), - insertSpaceAfterKeywordsInControlFlowStatements: readUnifiedConfig('format.insertSpaceAfterKeywordsInControlFlowStatements', true, { scope: document.uri, fallbackSection }), - insertSpaceAfterFunctionKeywordForAnonymousFunctions: readUnifiedConfig('format.insertSpaceAfterFunctionKeywordForAnonymousFunctions', true, { scope: document.uri, fallbackSection }), - insertSpaceBeforeFunctionParenthesis: readUnifiedConfig('format.insertSpaceBeforeFunctionParenthesis', false, { scope: document.uri, fallbackSection }), - insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis', false, { scope: document.uri, fallbackSection }), - insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets', false, { scope: document.uri, fallbackSection }), - insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces', true, { scope: document.uri, fallbackSection }), - insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces', true, { scope: document.uri, fallbackSection }), - insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces', false, { scope: document.uri, fallbackSection }), - insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces', false, { scope: document.uri, fallbackSection }), - insertSpaceAfterTypeAssertion: readUnifiedConfig('format.insertSpaceAfterTypeAssertion', false, { scope: document.uri, fallbackSection }), - placeOpenBraceOnNewLineForFunctions: readUnifiedConfig('format.placeOpenBraceOnNewLineForFunctions', false, { scope: document.uri, fallbackSection }), - placeOpenBraceOnNewLineForControlBlocks: readUnifiedConfig('format.placeOpenBraceOnNewLineForControlBlocks', false, { scope: document.uri, fallbackSection }), - semicolons: readUnifiedConfig('format.semicolons', 'ignore' as Proto.SemicolonPreference, { scope: document.uri, fallbackSection }), - indentSwitchCase: readUnifiedConfig('format.indentSwitchCase', true, { scope: document.uri, fallbackSection }), + insertSpaceAfterCommaDelimiter: readUnifiedConfig('format.insertSpaceAfterCommaDelimiter', true, { scope: document, fallbackSection }), + insertSpaceAfterConstructor: readUnifiedConfig('format.insertSpaceAfterConstructor', false, { scope: document, fallbackSection }), + insertSpaceAfterSemicolonInForStatements: readUnifiedConfig('format.insertSpaceAfterSemicolonInForStatements', true, { scope: document, fallbackSection }), + insertSpaceBeforeAndAfterBinaryOperators: readUnifiedConfig('format.insertSpaceBeforeAndAfterBinaryOperators', true, { scope: document, fallbackSection }), + insertSpaceAfterKeywordsInControlFlowStatements: readUnifiedConfig('format.insertSpaceAfterKeywordsInControlFlowStatements', true, { scope: document, fallbackSection }), + insertSpaceAfterFunctionKeywordForAnonymousFunctions: readUnifiedConfig('format.insertSpaceAfterFunctionKeywordForAnonymousFunctions', true, { scope: document, fallbackSection }), + insertSpaceBeforeFunctionParenthesis: readUnifiedConfig('format.insertSpaceBeforeFunctionParenthesis', false, { scope: document, fallbackSection }), + insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis', false, { scope: document, fallbackSection }), + insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets', false, { scope: document, fallbackSection }), + insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces', true, { scope: document, fallbackSection }), + insertSpaceAfterOpeningAndBeforeClosingEmptyBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces', true, { scope: document, fallbackSection }), + insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces', false, { scope: document, fallbackSection }), + insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: readUnifiedConfig('format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces', false, { scope: document, fallbackSection }), + insertSpaceAfterTypeAssertion: readUnifiedConfig('format.insertSpaceAfterTypeAssertion', false, { scope: document, fallbackSection }), + placeOpenBraceOnNewLineForFunctions: readUnifiedConfig('format.placeOpenBraceOnNewLineForFunctions', false, { scope: document, fallbackSection }), + placeOpenBraceOnNewLineForControlBlocks: readUnifiedConfig('format.placeOpenBraceOnNewLineForControlBlocks', false, { scope: document, fallbackSection }), + semicolons: readUnifiedConfig('format.semicolons', 'ignore' as Proto.SemicolonPreference, { scope: document, fallbackSection }), + indentSwitchCase: readUnifiedConfig('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('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(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(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('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('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('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('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 { diff --git a/extensions/typescript-language-features/src/utils/configuration.ts b/extensions/typescript-language-features/src/utils/configuration.ts index c1d85755be7..e0038500cf4 100644 --- a/extensions/typescript-language-features/src/utils/configuration.ts +++ b/extensions/typescript-language-features/src/utils/configuration.ts @@ -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