Skip to content

Conversation

@johnfav03
Copy link
Contributor

@johnfav03 johnfav03 commented Oct 2, 2025

Implements and tests User Preferences for Auto Imports; the specific preferences included are shown below.

importModuleSpecifierPreference: "shortest" | "project-relative" | "relative" | "non-relative";
importModuleSpecifierEnding: "auto" | "minimal" | "index" | "js";
includePackageJsonAutoImports: "auto" | "on" | "off";
allowRenameOfImportPath: boolean;
autoImportFileExcludePatterns: string[];
autoImportSpecifierExcludeRegexes: string[];
preferTypeOnlyAutoImports: boolean;

@johnfav03 johnfav03 changed the title added userpref gating for package.json auto imports added userpref gating for user preferences for auto imports Nov 13, 2025
@johnfav03 johnfav03 changed the title added userpref gating for user preferences for auto imports added gating for user preferences for auto imports Nov 13, 2025
@johnfav03 johnfav03 marked this pull request as ready for review November 17, 2025 19:09
Copilot finished reviewing on behalf of johnfav03 November 17, 2025 19:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds user preference gating for auto-import functionality in the TypeScript language server. The changes enable configurable behavior for module specifier preferences, import path endings, file/specifier exclusion patterns, type-only auto-imports, and import path renaming.

Key changes include:

  • Converting several boolean preferences to core.Tristate for consistency (PreferTypeOnlyAutoImports, AllowRenameOfImportPath)
  • Implementing user preference filtering for auto-imports via AutoImportFileExcludePatterns and AutoImportSpecifierExcludeRegexes
  • Adding support for module specifier preferences (ImportModuleSpecifierPreference, ImportModuleSpecifierEnding)
  • Exporting GetSubPatternFromSpec in the vfs package for pattern matching
  • Adding comprehensive test coverage for the new preference options

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
testdata/baselines/reference/fourslash/autoImports/*.baseline.md Baseline outputs for new auto-import preference tests
internal/vfs/utilities.go Exported GetSubPatternFromSpec for use in auto-import filtering
internal/modulespecifiers/types.go Added allowRenameOfImportPath field to UserPreferences struct
internal/modulespecifiers/specifiers.go Added baseUrl fallback logic and path component counting function
internal/lsp/server.go Updated rename handler to accept user preferences parameter
internal/ls/lsutil/userpreferences.go Converted preference fields to core.Tristate and removed comment markers
internal/ls/findallreferences.go Added preference gating for import path renaming
internal/ls/codeactions_importfixes.go Passed user preferences to auto-import filtering
internal/ls/autoimportsexportinfo.go Passed user preferences to export info collection
internal/ls/autoimports.go Implemented file and specifier exclusion pattern filtering
internal/ls/autoimportfixes.go Updated to use core.Tristate for type-only preferences
internal/fourslash/tests/*.go Added comprehensive tests for all new preference options
internal/fourslash/fourslash.go Updated test harness to preserve user preferences in baselines
internal/fourslash/_scripts/failingTests.txt Removed now-passing test from failing list
Comments suppressed due to low confidence (1)

internal/vfs/utilities.go:166

  • The matcher parameter is immediately overwritten at line 166 with wildcardMatchers[usage], making the parameter effectively unused. This means all callers are passing a value that gets ignored.

Either:

  1. Remove the overwrite at line 166 to use the passed-in matcher parameter, OR
  2. Remove the matcher parameter entirely and just use wildcardMatchers[usage] throughout the function (and update all call sites accordingly)

Given that all current call sites pass wildcardMatchers[usage] anyway, option 2 might be simpler and clearer.

func GetSubPatternFromSpec(
	spec string,
	basePath string,
	usage Usage,
	matcher WildcardMatcher,
) string {
	matcher = wildcardMatchers[usage]

@johnfav03 johnfav03 requested a review from jakebailey November 21, 2025 18:49
@jakebailey
Copy link
Member

Is the test generator just missing these options such that all tests are new handwritten ones?

if preferences.AutoImportFileExcludePatterns == nil {
return nil
}
var patterns []*regexp2.Regexp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I so wish this feature had not been Regexp based

@johnfav03
Copy link
Contributor Author

Is the test generator just missing these options such that all tests are new handwritten ones?

Isabel mentioned that I'd need to handwrite tests using BaselineAutoImportsCompletions as codefixProvider hasn't been ported yet

@andrewbranch
Copy link
Member

Codefixes were ported in #2053

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants