Skip to content

Incremental completion returns a stale cross-line replacement span with multiple referenced projects #55

Description

@KazariEX

With typescript-native-bridge@6.0.3-bridge.10.tsgo.7.0.2, two referenced projects include the same source file and declaration file. After deleting a line, retyping it one character at a time, and requesting completion after the first identifier character B, completionInfo returns an optionalReplacementSpan that crosses into the next line.

The response still contains the Buffer alias, but an editor can discard the semantic completion because the replacement range is invalid.

Reproduction

package.json:

{
  "private": true,
  "devDependencies": {
    "@types/node": "26.1.1",
    "typescript": "npm:typescript-native-bridge@6.0.3-bridge.10.tsgo.7.0.2"
  }
}

tsconfig.json:

{
  "references": [
    { "path": "./first/tsconfig.json" },
    { "path": "./.secondary/tsconfig.json" }
  ],
  "files": []
}

first/tsconfig.json:

{
  "compilerOptions": {
    "composite": true,
    "types": [
      "node"
    ]
  },
  "include": [
    "../repro.ts",
    "../.secondary/empty.d.ts"
  ]
}

.secondary/tsconfig.json:

{
  "compilerOptions": {
    "composite": true,
    "types": [
      "node"
    ]
  },
  "include": [
    "../repro.ts",
    "./empty.d.ts"
  ]
}

.secondary/empty.d.ts:

export {};

repro.ts:

import { Buffer } from "node:buffer";

export function encode(value: string) {
  const actual = Buffer.from(value);

  return actual.toString("base64url");
}
  1. Run pnpm install.
  2. Open the project and select the workspace TypeScript version.
  3. Open repro.ts.
  4. Delete all of line 4, including its trailing newline. The blank line previously at line 5 should now be line 4.
  5. On line 4, type two spaces followed by const actual = B, one character at a time. Do not paste the complete text.
  6. With the caret immediately after B, press Ctrl+Space to invoke completion.

Expected

The result contains the Buffer alias and replaces only the newly typed B: 4:18 → 4:19.

Actual

The editor does not show the semantic Buffer completion, and B remains an unresolved identifier.

The underlying completion response contains the Buffer alias, but its optionalReplacementSpan is the cross-line range 4:18 → 5:23. TypeScript 6.0.3 returns the correct 4:18 → 4:19 range for the same edit sequence.


This issue was created with assistance from a code agent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions