Skip to content

Conversation

Copy link
Contributor

Copilot AI commented May 20, 2025

Problem

The issue is that when debugging F# Compiler Service (FCS) tests, you can't see the actual source text content in range objects. This happens because the Range.DebugCode property tries to read source files from disk, but in FCS tests, source code is often parsed directly from strings without writing to disk files.

As shown in the screenshot, range objects show nonexistent file: Test.fsx instead of showing the actual text content:

Range debug display showing nonexistent file

Solution

This PR adds support for in-memory source texts in range.fs, allowing range objects to display their text content in the debugger even when the source files don't exist on disk.

The implementation consists of:

  1. A ConcurrentDictionary in the FileIndex module to store in-memory source texts
  2. Simple API functions to register/retrieve/clear in-memory source texts:
    • registerInMemorySourceText
    • tryGetInMemorySourceText
    • clearInMemorySourceTexts
  3. Modified Range.DebugCode to check the in-memory store first before trying to access the file on disk
  4. Updates to the Common.fs file in FCS tests to automatically register source texts

Example Usage

// Register an in-memory source
let filePath = "test-in-memory.fs"
let sourceText = "let x = 42\nlet y = 87"
FileIndex.registerInMemorySourceText filePath sourceText |> ignore

// Create a range for the in-memory source
let range = Range.mkRange filePath (Position.mkPos 1 4) (Position.mkPos 2 5)

// Now the range will show actual text content in the debugger
// Instead of "nonexistent file: test-in-memory.fs"

The changes are minimal and focused on solving this specific issue without disrupting other functionality.

Fixes #18521.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dc.services.visualstudio.com
    • Triggering command: /home/REDACTED/work/fsharp/fsharp/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/fsharp/fsharp/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/fsharp/fsharp/artifacts/toolset/9.0.0-beta.25266.2.txt (dns block)
  • pkgs.dev.azure.com
    • Triggering command: /home/REDACTED/work/fsharp/fsharp/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /warnaserror /p:TreatWarningsAsErrors=true /p:ContinuousIntegrationBuild=false /home/REDACTED/work/fsharp/fsharp/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/fsharp/fsharp/artifacts/toolset/9.0.0-beta.25266.2.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions
Copy link
Contributor

✅ No release notes required

Copilot AI and others added 2 commits May 20, 2025 10:48
Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com>
Co-authored-by: vzarytovskii <1260985+vzarytovskii@users.noreply.github.com>
Copilot AI changed the title [WIP] Can't see range text in FCS tests Add in-memory source text support for Range.DebugCode in F# Compiler Service May 20, 2025
Copilot AI requested a review from vzarytovskii May 20, 2025 10:59
@vzarytovskii
Copy link
Member

Yeah no

@T-Gro T-Gro deleted the copilot/fix-18521 branch May 20, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Can't see range text in FCS tests

2 participants