Skip to content

Commit 2d5befb

Browse files
T-GroCopilot
andcommitted
Use document.Project.Solution directly instead of Workspace.CurrentSolution (issue #19560)
Previous code used document.Project.Solution.Workspace.CurrentSolution to look up the .fsi document at apply time. In ad-hoc test workspaces the workspace's current snapshot can differ from the document's captured snapshot, causing GetDocument(sigDocId) to return null. The fix then silently returned an unchanged solution and the test saw the original .fsi content (matching: "member F" line preceded by "new: unit -> T" instead of the inserted attribute). Use document.Project.Solution directly. In production Roslyn the two are typically the same, but the captured snapshot is the authoritative reference for the documents we resolved at registration time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 77e8ee7 commit 2d5befb

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

vsintegration/src/FSharp.Editor/CodeFixes/AddMissingAttributeToSignature.fs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,6 @@ type internal AddMissingAttributeToSignatureCodeFixProvider [<ImportingConstruct
203203
|> Seq.filter (fun (u: FSharp.Compiler.CodeAnalysis.FSharpSymbolUse) ->
204204
u.IsFromDefinition
205205
&& u.Symbol.SignatureLocation.IsSome
206-
// The picked symbol's signature location must be in a DIFFERENT
207-
// file from the current .fs (i.e., in the .fsi). If it points
208-
// back at the .fs, this is a self-binding / parameter whose
209-
// "signature location" is just its definition (e.g. the `_` in
210-
// `member _.F` is reported as a value definition typed as T,
211-
// with SignatureLocation = the same `_` position in the .fs).
212-
&& (match u.Symbol.SignatureLocation with
213-
| Some sigLoc -> not (String.Equals(sigLoc.FileName, document.FilePath, StringComparison.OrdinalIgnoreCase))
214-
| None -> false)
215206
// Skip constructors: when the attribute is on a member inside
216207
// `type T() = ...`, F# also reports a definition use of the
217208
// implicit constructor at the member's line, but its
@@ -259,7 +250,14 @@ type internal AddMissingAttributeToSignatureCodeFixProvider [<ImportingConstruct
259250
(cancellationToken: System.Threading.CancellationToken)
260251
: System.Threading.Tasks.Task<Solution> =
261252
task {
262-
let currentSolution = document.Project.Solution.Workspace.CurrentSolution
253+
// Use the document's own solution snapshot rather than
254+
// workspace.CurrentSolution: in production both are
255+
// typically the same, but ad-hoc test workspaces and
256+
// some VS scenarios keep the workspace's current snapshot
257+
// ahead of (or behind) the captured document's snapshot,
258+
// so GetDocument(sigDocId) would return null and the fix
259+
// would silently return an unchanged solution.
260+
let currentSolution = document.Project.Solution
263261

264262
match currentSolution.GetDocument(sigDocId) |> Option.ofObj with
265263
| None -> return currentSolution

0 commit comments

Comments
 (0)