Conversation
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/19d44b3e-7bd1-4dc3-8327-ef40363fd5f7 Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/19d44b3e-7bd1-4dc3-8327-ef40363fd5f7 Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
There was a problem hiding this comment.
Update convertfourslash.mts to add any existing tests that need to be ported.
There was a problem hiding this comment.
Done in 38e7195. Added baselineGetFileReferences support to convertFourslash.mts (parser + generator + interface + union type membership), and generated TestGetFileReferences1 and TestGetFileReferences2 from the existing TypeScript fourslash tests.
internal/compiler/program.go
Outdated
| // that are recorded in the program's file-include-reasons map. These are references | ||
| // via triple-slash directives (/// <reference path="...">, /// <reference types="...">, | ||
| // /// <reference lib="...">), as opposed to module-symbol-based import references. | ||
| func (p *Program) GetNonModuleFileReferences(referencedFile *ast.SourceFile) []NonModuleFileReference { |
There was a problem hiding this comment.
Can this just live in ls? Explain why if not.
There was a problem hiding this comment.
Moved to ls in 38e7195. Instead of putting the logic on Program, I added a single exported method FileIncludeReason.GetSpanInReferrer(program) to compiler/fileInclude.go that handles the isReferencedFile() check + location retrieval + synthetic filtering + trivia-skipping (matching TypeScript's skipTrivia(file.text, importLiteral.pos)). The ls code calls program.GetIncludeReasons() + ref.GetSpanInReferrer() directly. The GetNonModuleFileReferences/NonModuleFileReference types on Program are removed.
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/dde8d3ba-1a19-4d77-abfa-20f0f4d53275 Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
internal/lsp/server.go
Outdated
| }, nil | ||
| } | ||
|
|
||
| func (s *Server) handleFindFileReferences(ctx context.Context, params *lsproto.FindFileReferencesParams, _ *lsproto.RequestMessage) (lsproto.CustomFindFileReferencesResponse, error) { |
There was a problem hiding this comment.
Does this need to be a cross-project aware call? Or did Strada really only do one project? I bet it does need to be cross-project a la registerMultiProjectReferenceRequestHandler.
There was a problem hiding this comment.
It should be cross-project. That's the challenge I was talking about in the original issue. Fix it @copilot.
There was a problem hiding this comment.
Fixed in f9bedbc. GetFileReferences now accepts a CrossProjectOrchestrator and uses it to search all initial projects (GetAllProjectsForInitialRequest) plus any additional projects discovered via GetProjectsLoadingProjectTree, deduplicating results across all of them. handleFindFileReferences is simplified to call getLanguageServiceAndCrossProjectOrchestrator and delegate to the LS. Also ported getFileReferences_server1, _server2, and _deduplicate from TypeScript's fourslash suite to validate the cross-project behavior.
…rchestrator Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/e57e7f66-ca9e-4e43-b376-fe3c262a720f Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Implements the "find file references" feature (right-click a JS/TS file in VS Code explorer → Find File References), which finds all files that import or triple-slash-reference a given file.
The core challenge:
getReferencesForNonModulewas a stub, and the multi-project search logic required a document position (which file-level queries don't have).Changes
Core algorithm (
internal/ls/findallreferences.go)getReferencesForNonModule()usingprogram.GetIncludeReasons()+FileIncludeReason.GetSpanInReferrer()to enumerate non-module references pointing to a fileGetFileReferences(ctx, uri, orchestrator)toLanguageService— dispatches togetReferencedSymbolsForModulefor module files (has exports), orgetReferencesForNonModulefor script files; when aCrossProjectOrchestratoris provided, searches all initial projects and expands viaGetProjectsLoadingProjectTreeto find additional projects in the dependency tree, deduplicating resultsCompiler helper (
internal/compiler/fileInclude.go)FileIncludeReason.GetSpanInReferrer(program)— exported method that returns the referring file name and text range for a file-include reason, with trivia-skipping matching TypeScript's behavior. The logic lives inlsviaprogram.GetIncludeReasons()+ this method.LSP protocol (
internal/lsp/lsproto/)custom/findFileReferencesrequest: params =FindFileReferencesParams{textDocument}(no position), result =Location[] | nullLSP server (
internal/lsp/server.go)handleFindFileReferences— usesgetLanguageServiceAndCrossProjectOrchestrator(same pattern asregisterMultiProjectReferenceRequestHandler) and delegates toGetFileReferenceswith the orchestrator, enabling full cross-project search including project dependency tree traversalVS Code extension (
_extension/)Client.findFileReferences(uri)callingcustom/findFileReferences_typescript.findAllFileReferencescommand (the standard VS Code command hooked by the explorer context menu) that calls the above and shows results viaeditor.action.showReferencesFourslash test infrastructure
VerifyBaselineFindFileReferencesto the fourslash frameworkTestFindFileReferences,TestFindFileReferencesNonModule, andTestGetFileReferences_deduplicate(cross-project deduplication)convertFourslash.mtsto supportverify.baselineGetFileReferences(...)and fix directory traversal so server-subdirectory tests are reachable when filtering by basename; portgetFileReferences1,getFileReferences2,getFileReferences_server1, andgetFileReferences_server2from the TypeScript fourslash suiteSide effect
Implementing
getReferencesForNonModulealso fixesfindAllReferenceson triple-slash/// <reference path/types/lib>nodes — previously they returned no span and omitted transitive referencing files (e.g.require("./b")in a.jsfile). ThefindAllReferencesTripleSlashsubmodule baseline is updated to match TypeScript's expected output, and the stale diff file is removed.Original prompt
Created from VS Code.
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.