Skip to content

Conversation

@mattiamanzati
Copy link
Contributor

Summary

  • Fixes auto-import with namespace import packages generating malformed code when the identifier is at the beginning of the file

Closes #414

Problem

When using namespaceImportPackages configuration and auto-completing an export like isAnyKeyword from effect/SchemaAST, the code was incorrectly generated as:

SchemaAST.import * as SchemaAST from "effect/SchemaAST";

Solution

The issue was in src/completions/middlewareAutoImports.ts where the order of text changes added to TypeScript's ChangeTracker was incorrect. The prefix (SchemaAST.) was being inserted before the import statement, but both targeted position 0. When the editor applies these changes sequentially with offset adjustment, the import ended up being placed after the prefix text.

The fix swaps the order of operations - the import statement is now added first, followed by the prefix. This ensures correct output:

import * as SchemaAST from "effect/SchemaAST";

SchemaAST.isAnyKeyword

@changeset-bot
Copy link

changeset-bot bot commented Jan 4, 2026

🦋 Changeset detected

Latest commit: 11dd8b4

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

This PR includes changesets to release 1 package
Name Type
@effect/language-service 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

@mattiamanzati mattiamanzati merged commit 477271d into main Jan 4, 2026
3 checks passed
@mattiamanzati mattiamanzati deleted the fix/auto-import-order branch January 4, 2026 13:49
@github-actions github-actions bot mentioned this pull request Jan 4, 2026
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.

Investigate auto-import with completions

2 participants