Skip to content

Duplicate callsite ranges for a single method call in callHierarchy/outgoingCalls #65526

Open

Description

@char8x

🔎 Search Terms

"callsite", "callHierarchy"

🕗 Version & Regression Information

Version Observed result
6.0.2, 6.0.3 The LSP startup command is unsupported, repro script cannot determine whether duplicate ranges occur.
7.0.2 Duplicate ranges reproduced.
7.1.0-dev.20261116.1 Duplicate ranges reproduced.

⏯ Playground Link

No response

💻 Code

Minimal reproduction

interface G { m(): void; }
function probe(g: G) { g.m(); }

Steps to reproduce

Use Node.js 22.21 or later and pnpm. In a new reproduction directory, install the pinned dependencies:

mkdir ts-call-hierarchy-repro
cd ts-call-hierarchy-repro
pnpm add --save-exact typescript@7.0.2 vscode-jsonrpc@10.0.0
pnpm exec tsc --version

Confirm that the version output is Version 7.0.2. Save the following JavaScript as repro.mjs in that directory:

import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { mkdtemp, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
import { createMessageConnection } from "vscode-jsonrpc/node";

const cwd = await mkdtemp(join(tmpdir(), "ts-call-hierarchy-"));
const text = "interface G { m(): void; }\nfunction probe(g: G) { g.m(); }\n";

await writeFile(join(cwd, "repro.ts"), text);
await writeFile(
  join(cwd, "tsconfig.json"),
  JSON.stringify({
    compilerOptions: { noEmit: true, types: [] },
    files: ["repro.ts"],
  }),
);

const server = spawn("tsc", ["--lsp", "--stdio"], {
  cwd,
  stdio: ["pipe", "pipe", "inherit"],
});
const serverExited = new Promise((resolve) => {
  server.once("exit", (code, signal) => resolve({ code, signal }));
  server.once("error", (error) => resolve({ error }));
});
const rpc = createMessageConnection(server.stdout, server.stdin);

rpc.onRequest("workspace/configuration", ({ items }) => items.map(() => null));
for (const method of [
  "client/registerCapability",
  "client/unregisterCapability",
  "window/workDoneProgress/create",
]) {
  rpc.onRequest(method, () => null);
}
rpc.listen();

async function withTimeout(promise, milliseconds, label) {
  let timer;
  try {
    return await Promise.race([
      promise,
      new Promise((_, reject) => {
        timer = setTimeout(() => reject(new Error(`Timeout: ${label}`)), milliseconds);
      }),
    ]);
  } finally {
    clearTimeout(timer);
  }
}

async function request(method, ...params) {
  return await withTimeout(rpc.sendRequest(method, ...params), 15_000, method);
}

try {
  await request("initialize", {
    processId: null,
    rootUri: pathToFileURL(cwd).href,
    capabilities: {
      workspace: {
        didChangeWatchedFiles: { dynamicRegistration: true },
      },
    },
  });
  await rpc.sendNotification("initialized", {});

  const uri = pathToFileURL(join(cwd, "repro.ts")).href;
  await rpc.sendNotification("textDocument/didOpen", {
    textDocument: { uri, languageId: "typescript", version: 1, text },
  });

  const [item] = await request("textDocument/prepareCallHierarchy", {
    textDocument: { uri },
    position: { line: 1, character: 9 },
  });
  const result = await request("callHierarchy/outgoingCalls", { item });
  console.log(JSON.stringify(result));

  assert.equal(result.length, 1);
  assert.equal(result[0].to.name, "m");
  const ranges = result[0].fromRanges;
  assert.equal(ranges.length, 2);
  assert.deepEqual(ranges[0], ranges[1]);
  console.log("PASS: two identical ranges for one method call");

  await request("shutdown");
  await rpc.sendNotification("exit");
  const status = await withTimeout(serverExited, 5_000, "server exit");
  if (status.error) throw status.error;
  if (status.code === 0 && status.signal === null) {
    console.log("Server shutdown completed (code 0)");
  } else {
    console.error(`Server shutdown abnormal: code ${status.code}, signal ${status.signal}`);
    process.exitCode = 1;
  }
} finally {
  rpc.dispose();
  if (server.pid && server.exitCode === null && server.signalCode === null) {
    console.error("Terminating server after failure or shutdown timeout");
    if (!server.kill()) console.error("Failed to send termination signal to server");
  }
}

Run it with:

pnpm exec node repro.mjs

🙁 Actual behavior

The callHierarchy/outgoingCalls result contains one outgoing target named m, with two identical entries in fromRanges (excerpt):

"fromRanges": [
  {
    "start": { "line": 1, "character": 23 },
    "end": { "line": 1, "character": 26 }
  },
  {
    "start": { "line": 1, "character": 23 },
    "end": { "line": 1, "character": 26 }
  }
]

Both entries identify the same g.m expression, from line 1, character 23 to line 1, character 26 (zero-based coordinates, exclusive end). There is only one method declaration and one method call.

PASS: two identical ranges for one method call means that the script successfully reproduced the duplicate ranges, its assertions check the observed bug.

In both tested 7.x versions, after returning the query result and printing PASS, the server prints context canceled during shutdown and exits with code 1, which the script reports separately.

🙂 Expected behavior

fromRanges should contain a single entry for the single source occurrence.

Additional information about the issue

No response

Activity

  1. zhengdaodeguL commented on Nov 17, 2026

    @zhengdaodeguL

    Fixed in #65553. Root cause: callSiteCollector.collect recorded the same call-site target twice for g.m() — once in the CallExpression branch and again in the PropertyAccessExpression branch — and recordCallSite appended a range on each call. The fix tracks already-recorded targets in the collector and skips duplicates, while distinct call sites are still recorded. Added regression tests for both outgoing and incoming calls (outgoing failed pre-fix with 2 != 1).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Symbol NavigationRelates to go-to-definition, find-all-references, highlighting/occurrences.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions