Skip to content

Exclude files in generated/ from completion candidates#185

Merged
mizdra merged 4 commits into
mainfrom
ignore-generated-files-for-completion
Jun 7, 2025
Merged

Exclude files in generated/ from completion candidates#185
mizdra merged 4 commits into
mainfrom
ignore-generated-files-for-completion

Conversation

@mizdra
Copy link
Copy Markdown
Owner

@mizdra mizdra commented Jun 7, 2025

No description provided.

@mizdra mizdra added the Type: Bug Bug or Bug fixes label Jun 7, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 7, 2025

🦋 Changeset detected

Latest commit: 3ad5607

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@css-modules-kit/ts-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mizdra mizdra changed the title Ignore generated files for completion Exclude files in generated/ from completion candidates Jun 7, 2025
@mizdra mizdra marked this pull request as ready for review June 7, 2025 15:32
@mizdra mizdra requested a review from Copilot June 7, 2025 15:34
Copy link
Copy Markdown

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 ensures that files under the generated/ directory are excluded from TypeScript auto-import completions and code fixes by appending the plugin’s dtsOutDir to the autoImportFileExcludePatterns.

  • Introduces createPreferencesForCompletion to merge exclusion patterns into TS user preferences
  • Propagates CMKConfig (containing dtsOutDir) through the language-service proxy to completion and code-fix features
  • Updates e2e fixtures/tests to include a generated .d.ts file and test error-code imports

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/ts-plugin/src/util.ts Added createPreferencesForCompletion util to append exclusion patterns
packages/ts-plugin/src/language-service/proxy.ts Passed config into getCompletionsAtPosition and getCodeFixesAtPosition
packages/ts-plugin/src/language-service/feature/completion.ts Used new util when calling languageService.getCompletionsAtPosition
packages/ts-plugin/src/language-service/feature/code-fix.ts Used new util when calling languageService.getCodeFixesAtPosition
packages/ts-plugin/src/index.ts Wired config through createLanguageServicePlugin
packages/ts-plugin/e2e/feature/completion.test.ts Added generated .d.ts fixture for exclusion testing
packages/ts-plugin/e2e/feature/code-fix.test.ts Imported new error codes and added generated fixture
.changeset/bright-parts-lie.md Updated changeset message
Comments suppressed due to low confidence (2)

packages/ts-plugin/e2e/feature/completion.test.ts:23

  • Add an assertion after retrieving completions to verify that entries for generated/ files are not present, ensuring the exclusion behavior is actually tested.
// Generated files should be excluded from import statement suggestions

packages/ts-plugin/src/util.ts:22

  • [nitpick] Add a JSDoc comment above createPreferencesForCompletion explaining its purpose, parameters, and return value to improve maintainability.
export function createPreferencesForCompletion<T extends ts.UserPreferences>(preferences: T, config: CMKConfig): T {

return (fileName, start, end, errorCodes, formatOptions, preferences) => {
const prior = Array.from(
languageService.getCodeFixesAtPosition(fileName, start, end, errorCodes, formatOptions, preferences) ?? [],
languageService.getCodeFixesAtPosition(
Copy link

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

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

Wrap the getCodeFixesAtPosition call in a nullish coalescing default (?? []) before passing to Array.from to avoid undefined being passed to Array.from, which would throw at runtime.

Copilot uses AI. Check for mistakes.
@mizdra mizdra merged commit 3ec5b22 into main Jun 7, 2025
6 checks passed
@mizdra mizdra deleted the ignore-generated-files-for-completion branch June 7, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Bug or Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants