Exclude files in generated/ from completion candidates#185
Conversation
🦋 Changeset detectedLatest commit: 3ad5607 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
generated/ from completion candidates
There was a problem hiding this comment.
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
createPreferencesForCompletionto merge exclusion patterns into TS user preferences - Propagates
CMKConfig(containingdtsOutDir) through the language-service proxy to completion and code-fix features - Updates e2e fixtures/tests to include a generated
.d.tsfile 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
createPreferencesForCompletionexplaining 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( |
There was a problem hiding this comment.
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.
No description provided.