Svelte: find_referencing_symbols on a .ts symbol returns every import of its module ($/getFileReferences merged into symbol references)
Preconditions:
- I have made sure it's an actual issue, not a question (use GitHub Discussions instead).
- I have actually encountered this issue in practice. Issues that are based on (AI-based) code analysis only will be closed without comment.
- I have consulted the user guide and verified that the issue cannot be resolved by adjusting configuration/following recommended workflows.
- I have looked for similar issues and discussions, including closed ones.
Issue details:
- I have provided a meaningful title and description.
- I have explained how the issue arose and, where possible, added instructions on how to reproduce it.
- I have added details on my setup: Serena version, MCP client, OS, the programming language(s), relevant configuration adjustments and project specifics.
- If the issue relates to an application of Serena to an open-source project, I have added the link. (closed-source project)
Setup: serena-agent 1.7.0 (the code below is unchanged on main @ 7a2968335f), LSP backend, language_servers: ["svelte"] (Serena-installed svelte-language-server 0.18.0 / typescript 6.0.3 / typescript-language-server 5.1.3 / typescript-svelte-plugin 0.3.52), start-mcp-server --transport streamable-http, a custom context with fixed_tools (navigation tools only), otherwise default config. MCP client: MCP Python SDK streamable-HTTP client (evaluating Serena for Claude Code). macOS 26.2, Node 22.21.1. Project: SvelteKit 2 / Svelte 5, ~2,100 .ts/.svelte files, moduleResolution: "bundler".
Problem
For a symbol exported from a .ts module, find_referencing_symbols returns every import of that module, including imports of other symbols. It also misses some of the symbol's real usages in .svelte files.
Repro (names simplified): lib/roles.ts exports roleLabel, ROLES, isRole and type Role. roleLabel is used 5 times in total. A.svelte imports it and calls it inside $derived(roleLabel(role)). B.svelte imports it and calls it twice in template markup. Other components import only ROLES, isRole or Role from the same module.
find_referencing_symbols(name_path="roleLabel", relative_path="lib/roles.ts")
Expected: the 5 usages. textDocument/references from typescript-language-server + typescript-svelte-plugin on the same project returns exactly those 5.
Actual:
- It returns import lines of other symbols from
lib/roles.ts(e.g.import type { Role } from '$lib/roles'), in.svelteand.tsfiles that never useroleLabel. - In
B.svelteit returns the closing} from '$lib/roles';line of the import, and neither template call. - In
A.svelteit returns the correct import, plus the unrelated import line just above it (attributed toscript/<otherImport>). The$derived(roleLabel(role))call is missing.
Cause of the extra hits
For .ts/.js files, SvelteLanguageServer.request_references merges the result of the svelte LS request $/getFileReferences into the symbol's references: svelte_language_server.py#L643-L647. $/getFileReferences returns references to the file, meaning every import of the module, not references to the symbol.
I have not traced the missing .svelte usages. For those files the log shows Could not find containing symbol for <file>.svelte:<line>:<col>. Returning file symbol instead, so they may be dropped when references are grouped by containing symbol.
Source: oraios/serena