Repository navigation
Read script carets without blocking the UI thread - #20523
xperiandri wants to merge 10 commits into
Conversation
✅ Release notes checked
|
This comment has been minimized.
This comment has been minimized.
89eaf2a to
550abf6
Compare
T-Gro
left a comment
There was a problem hiding this comment.
🤖🕵️ Please shorten the description using this guidance. Focus on the problem and why the change is needed, in simplified technical English. Leave the implementation inventory to the Files tab and retain necessary caveats.
550abf6 to
29779b0
Compare
86f3ffa to
4c110d6
Compare
xperiandri
left a comment
There was a problem hiding this comment.
Addressing the inline review feedback in the updated branch.
4c110d6 to
40c0cb9
Compare
This comment has been minimized.
This comment has been minimized.
Head branch was pushed to by a user without write access
530c52d to
75fa3cb
Compare
eeab5c6 to
eb5c1bd
Compare
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
eb5c1bd to
a423d23
Compare
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
T-Gro
left a comment
There was a problem hiding this comment.
The diff is still way too big - apply the NoBloat instructions and CodeCompaction skill.
Especially the massive code comments would benefit not just with drastic reduction, but ideally with well named functions/arguments/bindings/types making the intention clear.
If a well named piece of code just tells what the comment says - delete the comment.
- This diff adds 17 new code comment lines and 1666 new code comment chars.
- Comments bypass the type system and become stale maintenance state. Keep only durable public contracts; express implementation intent through names, functions, active patterns, discriminated unions, and types.
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* Note when a shared field needs option instead of voption The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR #20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * Require volatile access for a field shared between threads without a lock An atomic-sized write prevents tearing but does not publish the value: the field also needs [<VolatileField>] or equivalent synchronization. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
66fc40e to
d689d96
Compare
The voption guidance said no field is ever a reason to pick option, including ones shared between threads. That is wrong for a lock-free field: option is always one atomic-sized reference, voption is a struct that can span more than one word and tear on an unsynchronized write. PR dotnet#20523 hit this for a Position field a text-view listener writes and the project options reactor reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@T-Gro compacted in 87ca3bf. The diff adds 6 comment lines (553 characters) now, down from 17 (1670): the two license headers, and one line each for what the type is for, why the field is an The diff is +168/−127 (was +179/−127). What is left is the tracker, its tests and the reactor wiring, and |
87ca3bf to
d30b3cd
Compare
The project options reactor looked up the caret itself through ServiceProvider.GlobalProvider, the RDT, IVsTextView and an IVsTextViewEvents connection point, all of which need the UI thread. When the UI thread synchronously waited on project options (breakpoint validation when a document frame is shown), the reactor waited for the UI thread and the UI thread for the reactor. An IWpfTextViewCreationListener now publishes the caret of the focused editor into the text buffer's properties, and the reactor only reads it. Only scripts look for it: FCS uses the caret only to skip the `#r "nuget: ..."` line being typed. Fixes dotnet#20522 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Only the shared FocusedCaret.Position field needed to become `option` for the atomic reference write; the reactor's own local binding was converted along with it for no reason. Route it back through ValueOption and land on `option` once, at the two points that need it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The caret belongs to the buffer, which outlives the view. A view closed while it held focus left its line published, and the reactor went on skipping the `#r "nuget: …"` on a line no editor was on. `FocusedCaretTests` covers what the reactor reads and when it is told to read again: a move to another line, a move along one, focus leaving, focus already gone, and a text no view is open on. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ITextCaret.PositionChanged is raised only for explicit caret moves, not when the caret merely follows a text edit. A line pasted or typed above the caret therefore left the old line published, and FCS skipped the wrong `#r`. The tracker now also republishes on a layout that brings a new snapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Option.map _.Line allocated two options on every caret move; the match compares the lines in place. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…aves a line The options recomputed when the caret moves to another line were built from the text captured when the cache entry was created. Edits made since then had not reached them, so leaving a `#r "nuget: ..."` line could resolve the half-typed name it held at that point - the extra package download the caret was introduced to avoid. Read the buffer's current text instead; it is a snapshot read and needs no UI thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The type, the field and the two subscriptions keep one line each; the rest said what the names, the types or the tests already say. Two test names now carry what their comments said, and one no longer claims the opposite of what it asserts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
d30b3cd to
63d7506
Compare
Fixes #20522
Visual Studio could hang for good: the project options reactor asked the UI thread for a script's caret (to know whether an
#r "nuget: …"line was still being typed) while the UI thread was itself synchronously waiting on the reactor, resolving a breakpoint in the same file. The UI thread now publishes the caret itself, through the text buffer the reactor already reads; the reactor never waits on the UI thread again, and only scripts look for a caret at all.Moving focus away from a script now submits its pending
#r "nuget: …"line, where before only moving the caret to another line did — the caret is unknown once nothing has focus.