Skip to content

Use the checker's document source for script snapshots - #20751

Open
nojaf wants to merge 2 commits into
dotnet:mainfrom
nojaf:fix-issue-20750-script-document-source
Open

nojaf wants to merge 2 commits into
dotnet:mainfrom
nojaf:fix-issue-20750-script-document-source

Conversation

@nojaf

@nojaf nojaf commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

This fixes points 1 to 3 of #20750. FsAutoComplete wants to stop installing a process-wide FileSystem shim and give each checker its own view of the files (ionide/FsAutoComplete#1555). For scripts, DocumentSource.Custom did not work well enough for that yet.

  • The checker's document source is used. FSharpChecker.GetProjectSnapshotFromScript fell back to DocumentSource.FileSystem when no documentSource was passed, also when the checker was created with DocumentSource.Custom. The TransparentCompiler's GetProjectOptionsFromScript always passed DocumentSource.FileSystem. Both now use the document source of the checker.
  • Stable versions. FSharpFileSnapshot.CreateFromDocumentSource used DateTime.Now.Ticks as the version, so every call gave unchanged files a new version and the TransparentCompiler caches missed. This hit the #loaded files of a script and every FSharpProjectOptions based call on a TransparentCompiler created with DocumentSource.Custom. It now gets the text when the snapshot is created and uses its checksum as the version. Files read from disk keep the last write time.
  • None reads from disk. When the custom source returned None, getting the source failed with "Couldn't get source for file". The file is now read from disk, as the BackgroundCompiler does (FSharpSource.fs).

API change: FSharpFileSnapshot.CreateFromDocumentSource now returns Async<FSharpFileSnapshot>, because the custom source is async and the version needs the text. The type is marked experimental and nothing outside FCS calls it. Surface area baseline is updated.

A custom source is now called for every file each time a snapshot is created, not only when a file needs parsing. Before, those calls missed the caches and reparsed everything anyway.

Not in this PR (see this comment):

documentSource on FSharpChecker.Create is still marked "likely to be removed in the future". If that is the plan, the question from #20750 still stands: how should an editor give the TransparentCompiler the text of open files that a script #loads?

Part of #20750

Checklist

  • Test cases added

  • Performance benchmarks added in case of performance changes

  • Release notes entry updated:

    Please make sure to add an entry with short succinct description of the change as well as link to this pull request to the respective release notes file, if applicable.

    Release notes files:

    • If anything under src/Compiler has been changed, please make sure to make an entry in docs/release-notes/.FSharp.Compiler.Service/<version>.md, where <version> is usually "highest" one, e.g. 42.8.200
    • If language feature was added (i.e. LanguageFeatures.fsi was changed), please add it to docs/release-notes/.Language/preview.md
    • If a change to FSharp.Core was made, please make sure to edit docs/release-notes/.FSharp.Core/<version>.md where version is "highest" one, e.g. 8.0.200.

    Information about the release notes entries format can be found in the documentation.
    Example:

    If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

Tests: three new theories in tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs, each run with the BackgroundCompiler and the TransparentCompiler. All six fail on main and pass with this change.

GetProjectSnapshotFromScript fell back to the file system when no
document source was passed, also when the checker was created with
DocumentSource.Custom. The TransparentCompiler's
GetProjectOptionsFromScript always passed DocumentSource.FileSystem. Both
now use the document source of the checker.

A file from a custom document source got DateTime.Now as its version, so
every snapshot gave unchanged files a new version and the
TransparentCompiler caches missed. CreateFromDocumentSource now gets the
text when the snapshot is created and uses its checksum as the version.
It returns Async<FSharpFileSnapshot> for that reason.

When the custom source returned None, getting the source failed with
"Couldn't get source for file". The file is now read from disk, as the
BackgroundCompiler does.

See dotnet#20750.
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.200.md

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

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

1 participant