Skip to content

Resolve a script's #r lines from its current text - #20645

Open
xperiandri wants to merge 9 commits into
dotnet:mainfrom
xperiandri:fix/script-options-current-text
Open

xperiandri wants to merge 9 commits into
dotnet:mainfrom
xperiandri:fix/script-options-current-text

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Stacked on #20523

When the caret leaves a line of a script, its #r "nuget: …" references are resolved again, but from the text the file had when its options were last computed rather than the text now in the editor. Edits made since then had not reached that copy, so leaving a #r line could resolve the half-typed package name it held at that point – the download the caret exists to prevent. They are now resolved from the buffer's current text.

The options the file is checked with still keep that line excluded until the next edit, as before.

🤖 Generated with Claude Code

xperiandri and others added 8 commits September 26, 2026 03:00
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>
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>
…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>
Copilot AI lite review requested due to automatic review settings September 26, 2026 18:37
@xperiandri
xperiandri requested a review from a team as a code owner September 26, 2026 18:37
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`vsintegration/src` docs/release-notes/.VisualStudio/18.vNext.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Two moderate issues remain in caret initialization and project-options cache reconnection.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This pull request updates script #r resolution to use the editor’s current text and tracks focused caret changes.

Changes:

  • Adds focused-caret tracking and tests.
  • Refreshes project options from current buffer text.
  • Removes legacy view-event helpers and adds release notes.
File Summary Review notes
vsintegration/​tests/​FSharp.Editor.Tests/​FSharp.Editor.Tests.fsproj Includes new tests. —
vsintegration/​tests/​FSharp.Editor.Tests/​FocusedCaretTests.fs Tests caret behavior. Exercises the failing null-container path.
vsintegration/​src/​FSharp.Editor/​LanguageService/​FSharpProjectOptionsManager.fs Uses current buffer text and caret tracking. Moderate: cached entries may not reconnect when a view appears.
vsintegration/​src/​FSharp.Editor/​LanguageService/​FocusedCaret.fs Publishes focused caret state. Moderate: accessing Container can throw before the null case.
vsintegration/​src/​FSharp.Editor/​FSharp.Editor.fsproj Includes caret tracking implementation. —
vsintegration/​src/​FSharp.Editor/​Common/​Extensions.fs Removes legacy view-event helpers. —
docs/​release-notes/​.VisualStudio/​18.vNext.md Documents the changes. —

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +276 to +278
focusedCaret
|> ValueOption.map _.LineChanged.Subscribe(updateProjectOptions)
|> ValueOption.toOption
@github-actions github-actions Bot added ⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager ⚠️ Affects-Restore Tooling check: PR touches NuGet packages or feeds labels Sep 26, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Design-Time, Affects-Restore
Affects-Design-Time: Compiler-service or IDE design-time behavior changes.
Affects-Restore: Package references, feeds, or restore inputs change.

Generated by PR Tooling Safety Check · gpt56 1.7M · ◷

This branch has not been deployed

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

Labels

⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager ⚠️ Affects-Restore Tooling check: PR touches NuGet packages or feeds

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants