Skip to content

Commit

Permalink
autoImportSpecifierExcludeRegexes and organizeImports preference
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Oct 25, 2024
1 parent 5ec41e9 commit ba4749a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
36 changes: 35 additions & 1 deletion packages/language-server/src/ls-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ export interface TsUserPreferencesConfig {
includePackageJsonAutoImports?: ts.UserPreferences['includePackageJsonAutoImports'];

preferTypeOnlyAutoImports?: ts.UserPreferences['preferTypeOnlyAutoImports'];

autoImportSpecifierExcludeRegexes?: string[];

organizeImports?: TsOrganizeImportPreferencesConfig;
}

interface TsOrganizeImportPreferencesConfig {
accentCollation: ts.UserPreferences['organizeImportsAccentCollation'];
caseFirst: ts.UserPreferences['organizeImportsCaseFirst'] | 'default';
caseSensitivity: ts.UserPreferences['organizeImportsIgnoreCase'];
locale: ts.UserPreferences['organizeImportsLocale'];
numericCollation: ts.UserPreferences['organizeImportsNumericCollation'];
typeOrder: ts.UserPreferences['organizeImportsTypeOrder'] | 'auto';
}

/**
Expand Down Expand Up @@ -474,10 +487,31 @@ export class LSConfigManager {
includeInlayVariableTypeHintsWhenTypeMatchesName:
inlayHints?.variableTypes?.suppressWhenTypeMatchesName === false,

interactiveInlayHints: true
autoImportSpecifierExcludeRegexes:
config.preferences?.autoImportSpecifierExcludeRegexes,

organizeImportsAccentCollation: config.preferences?.organizeImports?.accentCollation,
organizeImportsCaseFirst: this.withDefaultAsUndefined(
config.preferences?.organizeImports?.caseFirst,
'default'
),
organizeImportsIgnoreCase: this.withDefaultAsUndefined(
config.preferences?.organizeImports?.caseSensitivity,
'auto'
),
organizeImportsLocale: config.preferences?.organizeImports?.locale,
organizeImportsNumericCollation: config.preferences?.organizeImports?.numericCollation,
organizeImportsTypeOrder: this.withDefaultAsUndefined(
config.preferences?.organizeImports?.typeOrder,
'auto'
)
};
}

private withDefaultAsUndefined<T, O extends T>(value: T, def: O): Exclude<T, O> | undefined {
return value === def ? undefined : (value as Exclude<T, O>);
}

getTsUserPreferences(
lang: TsUserConfigLang,
normalizedWorkspacePath: string | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('ts user preferences', function () {
importModuleSpecifier: 'non-relative',
importModuleSpecifierEnding: undefined,
quoteStyle: 'single',
includePackageJsonAutoImports: undefined
includePackageJsonAutoImports: undefined,
organizeImports: undefined
};
}

Expand Down

0 comments on commit ba4749a

Please sign in to comment.