Skip to content

Commit

Permalink
refactor(typescript): narrow getUserPreferences params
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 31, 2024
1 parent 9f261a7 commit 61b9529
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/typescript/lib/configs/getUserPreferences.ts
Expand Up @@ -2,13 +2,16 @@ import * as path from 'path-browserify';
import type * as ts from 'typescript';
import type { TextDocument } from 'vscode-languageserver-textdocument';
import { getConfigTitle } from '../shared';
import type { SharedContext } from '../semanticFeatures/types';
import type { ServiceContext } from '@volar/language-service';

export async function getUserPreferences(
ctx: SharedContext,
ctx: ServiceContext,
document: TextDocument,
): Promise<ts.UserPreferences> {

let currentDirectory = '';
if (ctx.language.typescript) {
currentDirectory = ctx.language.typescript.languageServiceHost.getCurrentDirectory();
}
const config = await ctx.env.getConfiguration?.<any>(getConfigTitle(document)) ?? {};
const preferencesConfig = config?.preferences ?? {};
const preferences: ts.UserPreferences = {
Expand All @@ -27,7 +30,7 @@ export async function getUserPreferences(
includeCompletionsWithSnippetText: config.suggest?.includeCompletionsWithSnippetText ?? true,
includeCompletionsWithClassMemberSnippets: config.suggest?.classMemberSnippets?.enabled ?? true,
includeCompletionsWithObjectLiteralMethodSnippets: config.suggest?.objectLiteralMethodSnippets?.enabled ?? true,
autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, ctx.languageServiceHost.getCurrentDirectory()),
autoImportFileExcludePatterns: getAutoImportFileExcludePatternsPreference(preferencesConfig, currentDirectory),
useLabelDetailsInCompletionEntries: true,
allowIncompleteCompletions: true,
displayPartsForJSDoc: true,
Expand Down

0 comments on commit 61b9529

Please sign in to comment.