Skip to content

Add on-demand project loading - #85234

Closed
JoeRobich wants to merge 25 commits into
mainfrom
dev/jorobich/on-demand-loading
Closed

JoeRobich wants to merge 25 commits into
mainfrom
dev/jorobich/on-demand-loading

Conversation

@JoeRobich

@JoeRobich JoeRobich commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Adds on-demand C# project loading to Roslyn LSP.

When on-demand loading is enabled, opening a C# file starts discovery. Context lookup reuses documents in registered workspaces before requesting a load. For files not already represented, Roslyn searches for the nearest project-file ancestor within the workspace folder, loads those projects and their transitive references, then re-resolves the request context against the updated workspace.

Request dispatch captures the LSP text and relevant load operations. Waiting for loading and projecting the captured text onto the loaded solution happen outside serialized dispatch, so unrelated requests and text-sync notifications can continue. Shared context clearing, cancellation isolation, and shutdown draining preserve request and service lifetimes.

Prerequisite stack

Review updates

  • 43766d3fb80: give canonical project cache initialization a single owner; joining and priority promotion do not repeat cache work.
  • 322bf860cfc: make load capture/completion explicit with ProjectLoadSnapshot and document discovery/traversal ownership.
  • 3998a166d64: use ValueTask<ValueTask<LspContext>?> for context capture, retain inline results or one shared resolution task in private clearable state, inject the loader into the workspace manager, and separate miscellaneous-document operations from deferred projection.
  • 73817c3c602: use a mutable reference-path set and remove architectural explanations from the IDE instructions without adding replacement documentation.

Local validation

  • Both affected test projects built for net10.0 with RunAnalyzersDuringBuild=true, with zero warnings/errors.
  • After the request-context refactor: 203 protocol tests passed with one existing platform skip; 139 host tests passed with four existing platform skips. These focused runs cover request ordering, captured text, shared clearing/cancellation, workspace lookup, metadata-as-source, loaders, and miscellaneous/file-based programs.
  • After the final cleanup: 35 loader tests passed with no skips, including ProjectReferencePathsAreResolvedAndDeduplicated.
  • Formatting verification and whitespace checks passed. Counts above describe separate focused runs, not a full-suite run.
Microsoft Reviewers: Open in CodeFlow

@JoeRobich
JoeRobich requested review from a team as code owners September 9, 2026 21:41
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@JoeRobich JoeRobich changed the title Dev/jorobich/on demand loading Add on-demand project loading- #84591 Sep 9, 2026
@JoeRobich JoeRobich changed the title Add on-demand project loading- #84591 Add on-demand project loading Sep 9, 2026
@JoeRobich
JoeRobich changed the base branch from dev/jorobich/canonical-project-loads to main September 10, 2026 22:13
Copilot AI lite review requested due to automatic review settings September 10, 2026 22:22
@JoeRobich
JoeRobich force-pushed the dev/jorobich/on-demand-loading branch from 0c47bcf to 893e355 Compare September 10, 2026 22:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Five unresolved moderate findings remain in project filtering, path containment, snapshot resolution, and loose-file fallback.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 3 Medium severity

New issues introduced by this change (3)
Severity Finding
Medium severity src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​LanguageServerProjectSystem.cs — Filter transitive references to supported languages
Medium severity src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​WorkspaceProjectDiscoveryService.cs — Use platform-correct path comparison for discovery
Medium severity src/​LanguageServer/​Protocol/​Handler/​RequestContext.cs — Do not change obsolete wrapper semantics to post-load state
What changed in this PR

Adds deferred, on-demand project discovery and loading for Roslyn LSP requests, including transitive references and asynchronous request-context resolution.

Changes:

  • Adds nearest-project discovery and on-demand project loading.
  • Adds lazy context resolution with request-state capture and cancellation.
  • Adds options, tests, design documentation, and IDE guidance.
File Reviewed change / comment
src/​LanguageServer/​ProtocolUnitTests/​Workspaces/​LspWorkspaceManagerTests.cs Updates workspace-manager tests and composition support.
src/​LanguageServer/​ProtocolUnitTests/​HandlerTests.cs Tests deferred contexts, cancellation, snapshots, and mutation behavior.
src/​LanguageServer/​Protocol/​Workspaces/​LspWorkspaceManager.cs Supports document re-resolution; moderate (1 vote): preserve fallback handling for untracked loose file URIs and add a regression test.
src/​LanguageServer/​Protocol/​Workspaces/​IOnDemandProjectLoader.cs Defines the on-demand loading contract.
src/​LanguageServer/​Protocol/​Handler/​RequestContextFactory.cs Starts loading and captures request state.
src/​LanguageServer/​Protocol/​Handler/​RequestContext.cs Implements lazy context resolution; moderate (1 vote): use the captured document map during fallback resolution. Moderate (2 votes): preserve construction-time behavior for synchronous compatibility properties.
src/​LanguageServer/​Protocol/​Features/​Options/​LanguageServerProjectSystemOptionsStorage.cs Adds the on-demand loading option.
src/​LanguageServer/​Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/​RequestExecutionQueueTests.cs Tests serialized context-factory ordering.
src/​LanguageServer/​Microsoft.CommonLanguageServerProtocol.Framework.UnitTests/​Mocks/​TestRequestContext.cs Adapts test context creation.
src/​LanguageServer/​Microsoft.CommonLanguageServerProtocol.Framework.Example/​ExampleRequestContextFactory.cs Adapts the example context factory.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​WorkspaceProjectDiscoveryService.cs Finds ancestor projects within workspace folders; moderate (3 votes): use platform-sensitive path comparison for workspace containment.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​OnDemandProjectLoader.cs Performs project closure discovery and loading.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​LoadedProject.Target.cs Stores evaluated project-reference metadata.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​LoadedProject.cs Resolves and deduplicates project-reference paths.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​LanguageServerProjectSystem.cs Integrates project extensions and references; moderate (2 votes): filter references by supported in-process language services before queuing loads.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer.UnitTests/​WorkspaceProjectDiscoveryServiceTests.cs Tests filesystem project discovery.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer.UnitTests/​OnDemandProjectLoaderTests.cs Tests project and reference loading.
src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer.UnitTests/​LanguageServerProjectSystemTests.cs Tests project-path language resolution.
docs/​ide/​specs/​load-projects-on-demand.md Defines the on-demand loading design; nit (1 vote): use “dependent” instead of “dependant.”
.github/​memory/​testing/​ide.md Adds on-demand loading testing guidance.
.github/​memory/​FILE_MAP.md Updates the LanguageServer component map.
.github/​instructions/​IDE.instructions.md Documents LanguageServer loading and context conventions.

Load projects containing requested documents on demand, expand transitive project references, and use request-time workspace snapshots while preserving the existing one-shot project load lifecycle.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: accffd50-fd3c-4252-8872-c1c4a161ea55
Copilot AI review requested due to automatic review settings September 11, 2026 18:22
@JoeRobich
JoeRobich force-pushed the dev/jorobich/on-demand-loading branch from 893e355 to e2d21b4 Compare September 11, 2026 18:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Four unresolved review findings remain, including three critical issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 3 High severity

New issues introduced by this change (3)
Severity Finding
High severity src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​OnDemandProjectLoader.cs — Include in-flight on-demand closure loads in workspace waits View comment
High severity src/​LanguageServer/​Protocol/​Workspaces/​LspWorkspaceManager.cs — Serialize miscellaneous-workspace removal during async resolution View comment
High severity src/​LanguageServer/​Protocol/​Workspaces/​LspWorkspaceManager.cs — Use a non-moving builder when workspaces can be skipped View comment
Issues resolved since last review (3)
Severity Finding
Medium severity src/​LanguageServer/​Protocol/​Handler/​RequestContext.cs — Do not change obsolete wrapper semantics to post-load state View resolved comment
Medium severity src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​WorkspaceProjectDiscoveryService.cs — Use platform-correct path comparison for discovery View resolved comment
Medium severity src/​LanguageServer/​Microsoft.CodeAnalysis.LanguageServer/​HostWorkspace/​LanguageServerProjectSystem.cs — Filter transitive references to supported languages View resolved comment

Track active discovery closures, serialize miscellaneous workspace access, preserve partial workspace results, and update the option contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5615e2cd-8b86-40a5-808b-47f8fa893b35
@JoeRobich

Copy link
Copy Markdown
Member Author

Client configuration counterpart: dotnet/vscode-csharp#9758

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Unresolved critical and moderate issues affect fallback behavior, cancellation, unnecessary loading, and context refresh.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 High severity

Open findings (1)
Resolved findings (3)
Previously missed findings (1)

In code that hasn't changed since last review

Medium severity Avoid loading projects for handlers without solution context

src/​LanguageServer/​Protocol/​Handler/​RequestContextFactory.cs:76

DidOpenHandler, DidChangeHandler, and DidCloseHandler all provide a TextDocumentIdentifier but set RequiresLSPSolution to false, so this branch starts discovery and project loading for every open/change/close notification even though those handlers never access a solution or document context. That defeats the on-demand behavior and can load an entire project merely because a file was opened; gate this path on requiresLSPSolution (or otherwise only start it when a solution/document context will be consumed).

Restore transient loose-file documents, make synchronization tests cross-target compatible, and apply intentional cancellation semantics to miscellaneous workspace locking.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5615e2cd-8b86-40a5-808b-47f8fa893b35
Copilot AI review requested due to automatic review settings September 14, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

RequestContextFactory.cs may load projects for notifications that do not require solution context, and an end-to-end factory test is requested.

Review tier: Lite
Findings: None

Resolved findings (1)
Previously missed findings (1)

In code that hasn't changed since last review

Medium severity Avoid loading projects for handlers without solution context

src/​LanguageServer/​Protocol/​Handler/​RequestContextFactory.cs:73

DidOpenHandler, DidChangeHandler, and DidCloseHandler all provide a text-document identifier but set RequiresLSPSolution to false; they only update tracking state and never access the solution/document context. With on-demand loading enabled, this branch still starts directory discovery and MSBuild project loading for every open/change/close of an unloaded file, defeating the deferred-loading behavior and adding project-system work to these notifications. Gate this branch on requiresLSPSolution (or otherwise only start it for handlers that can consume the loaded context).

Rename the load tracking helper to satisfy VSTHRD200.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5615e2cd-8b86-40a5-808b-47f8fa893b35
Copilot AI review requested due to automatic review settings September 14, 2026 20:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Unresolved moderate findings remain in project loading and request-context behavior.

Review tier: Lite
Findings: None

Previously missed findings (1)

In code that hasn't changed since last review

Medium severity Do not start loading for handlers without solution context

src/​LanguageServer/​Protocol/​Handler/​RequestContextFactory.cs:73

DidOpenHandler, DidChangeHandler, and DidCloseHandler supply a document identifier but set RequiresLSPSolution to false; their contexts deliberately do not access solution or document state. This branch still starts discovery and MSBuild loading for every open/change/close of an unloaded file, defeating deferred loading and potentially loading a whole project solely because a file was opened. Gate this condition on requiresLSPSolution as well.

Copilot AI review requested due to automatic review settings September 18, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Three unresolved moderate findings remain involving document-type gating, stale solution capture, and cancellation-aware loading capture.

Review effort: Lite
Findings: None

Resolved since last review (4)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a8c23333-3896-4f49-825b-459d9cf925d0
Copilot AI review requested due to automatic review settings September 18, 2026 22:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Three moderate findings remain in project eligibility, cancellation, and context projection, requiring human review.

Review effort: Lite
Findings: None

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a8c23333-3896-4f49-825b-459d9cf925d0
Copilot AI review requested due to automatic review settings September 18, 2026 23:22
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a8c23333-3896-4f49-825b-459d9cf925d0

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Unresolved loader concurrency, document-eligibility, cancellation, and stale-context issues block approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Propagate request cancellation during workspace snapshot capture

src/​LanguageServer/​Protocol/​Workspaces/​IOnDemandProjectLoader.cs:18

CaptureWorkspaceLoadSnapshotAsync is awaited while the request context is being created inside the serialized request queue, but it has no request cancellation token. If snapshot capture waits for the project-loader gate, canceling this request cannot stop that wait and can hold up all later LSP messages. Thread the queue token through capture for gate acquisition, while keeping the returned shared completion independent of per-accessor cancellation.

Medium severity Refresh contexts when snapshots were initially pending

src/​LanguageServer/​Protocol/​Workspaces/​LspWorkspaceManager.cs:286

The completion status is checked only after GetInitialSolutionContextAsync has captured its solution. If the snapshot is pending at entry, the load can commit after that initial solution is read but before this status check; the code then sees RanToCompletion and returns the stale pre-load context without deferred re-resolution. Record whether the snapshot was already complete before capturing the initial context, or always defer refresh for snapshots that were initially pending.

Comment on lines +105 to +107
var projectPaths = new HashSet<string>(PathUtilities.Comparer);
var loadTask = Task.Run(() => LoadDiscoveredProjectsAsync(filePath, directory, workspaceFolders, projectPaths, shutdownToken));
_activeLoads.Add(directory, (loadTask, projectPaths));
Copilot AI review requested due to automatic review settings September 18, 2026 23:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Two moderate findings remain: language-agnostic discovery and unnecessary deferred projection when loading is disabled.

Review effort: Lite
Findings: 1 High severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Gate project discovery to supported C# documents

src/​LanguageServer/​Protocol/​Handler/​RequestContextFactory.cs:75

This hook receives only the URI, so it cannot distinguish a C# document from the other files this server can open. DidOpenHandler provides a LanguageId, and the language provider recognizes F#/Razor/etc.; opening one of those files under a workspace therefore schedules discovery and can MSBuild-load every nearby C#/VB project, although this feature is described as on-demand C# project loading. Preserve the document language/extension and gate discovery to supported source documents, with a regression test for an unrelated language.

@JoeRobich

Copy link
Copy Markdown
Member Author

/azp run roslyn-CI

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e6c0e389-8d6e-4e9e-8377-3bc8e3507707
Copilot AI review requested due to automatic review settings September 22, 2026 00:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Unresolved critical and moderate review findings remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity

Open (2)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: e6c0e389-8d6e-4e9e-8377-3bc8e3507707
Copilot AI review requested due to automatic review settings September 22, 2026 01:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Active discovery can miss newly added projects for later demands, leaving documents in the miscellaneous fallback.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

private readonly ILanguageInfoProvider _languageInfoProvider;
private readonly RequestTelemetryLogger _requestTelemetryLogger;
private readonly IOnDemandProjectLoader? _onDemandProjectLoader;
private Func<Task>? _beforeApplyLspTextAsyncForTest;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is test only to make a race between GetInitialSolutionContextAsync and CaptureLspSolutionContextAsync deterministic for testing

/// This is always called serially in the <see cref="RequestExecutionQueue{RequestContextType}"/> when creating the <see cref="RequestContext"/>.
/// </summary>
public async Task<(Workspace?, Solution?)> GetLspSolutionInfoAsync(CancellationToken cancellationToken)
public async Task<(Workspace? Workspace, Solution? Solution)> GetLspSolutionInfoAsync(CancellationToken cancellationToken)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't expect needing CaptureLspDocumentContextAsync and this to both be public. We should only have one entry point per sln or document. Does anyone still call this?

/// This is always called serially in the <see cref="RequestExecutionQueue{RequestContextType}"/> when creating the <see cref="RequestContext"/>.
/// </summary>
public async Task<(Workspace?, Solution?, TextDocument?)> GetLspDocumentInfoAsync(TextDocumentIdentifier textDocumentIdentifier, CancellationToken cancellationToken)
public async Task<(Workspace? Workspace, Solution? Solution, TextDocument? Document)> GetLspDocumentInfoAsync(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't expect needing CaptureLspDocumentContextAsync and this to both be public. We should only have one entry point per sln or document. Does anyone still call this?


var initialDocumentInfo = await TryAddMiscellaneousDocumentAsync(textDocumentIdentifier.DocumentUri, trackedDocuments).ConfigureAwait(false);
if (initialDocumentInfo is { } documentInfo)
await RemoveMiscellaneousDocumentAsync(textDocumentIdentifier.DocumentUri, documentInfo.Workspace).ConfigureAwait(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this immediately trying to remove a misc document we added to misc?

var initialDocumentContext = RecordDocumentLookupResult(textDocumentIdentifier.DocumentUri, initialDocumentInfo);
var initialContext = initialDocumentContext is { Workspace: not null, Solution: not null }
? CreateLspContext(initialDocumentContext)
: await GetInitialSolutionContextAsync(cancellationToken).ConfigureAwait(false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we don't have a misc context, why do we need to get a solution context instead of having it be null? Wasn't it null before?

if (initialContext is null)
return null;

return !allowProjectLoading || _onDemandProjectLoader is null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit - these ternarys (and above ones) are a bit confusing, would prefer regular if/else etc

bool allowProjectLoading,
CancellationToken cancellationToken)
{
ProjectLoadSnapshot? snapshot = allowProjectLoading && _onDemandProjectLoader is not null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit - I think you could re-write as

// Task representing on demand in-progress loads.
Task? projectLoadTask = null
if (allowProjectLoading && _onDemandProjectLoader is not null)
{
     var snapshot = await _onDemandProjectLoader.Capture...
     if (snapshopt.Completion.Status != RanToCompletion)
     {
         // We have an uncompleted in progress load
         projectLoadTask = snapshot.Completion;     
     }     
}

...

if (!projectLoadTask)
    return new ...

return new ... (projectLoadTask)


var forkedFromVersion = workspaceCurrentSolution.SolutionStateContentVersion;
var sourceGeneratorChecksum = workspaceCurrentSolution.CompilationState.SourceGeneratorExecutionVersionMap.GetChecksum();
var cachedFork = cachedSolution.forkedFromVersion == forkedFromVersion &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

think we lost the step number comments - those should be brought back

}

async ValueTask TryOpenAndEditDocumentsInMutatingWorkspaceAsync(Workspace workspace)
// Prefer the actual workspace snapshot if text has caught up since this fork was cached.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this comment doesn't seem to match the behavior? We're returning the fork here

// didClose only update already-tracked state and should not start new project loads.
if (textDocumentIdentifier is not null && queueItem.MethodName == Methods.TextDocumentDidOpenName)
{
_lspServices.GetRequiredService<LspWorkspaceManager>().StartLoadingProject(textDocumentIdentifier.DocumentUri);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Historically we haven't done anything on open. Fine with this but if it simplifies things I also don't mind loading starting on the first request for the document

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was hoping it would be an optimization but I can also imagine that another request likely immediately follows the didOpen.

/// </summary>
internal async Task<LoadedProject> BeginLoadingProjectAsync(string projectPath)
/// <remarks>
/// High-priority requests also promote an existing queued load. Other requests leave its priority unchanged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why though?

Task projectLoadTask,
CancellationToken cancellationToken)
{
await TaskScheduler.Default.SwitchTo(alwaysYield: true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

/// <summary>
/// Shares a completed value or one resolution task across context copies, until any copy clears it.
/// </summary>
private sealed class SolutionContextState

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this entire type goes away if we just let this be a Task<LspWorkspaceManager.LspContext> instead? Or just replace all the value stuff with a Task (and yes we're allocating a bit more but it'll be a lot clearer) but keep the type, and then have this be what is returned from CaptureLspDocumentContextAsync, so that way you avoid the task-of-task confusion.

if (cancelAccessor)
cancellationSource.Cancel();

var expectedSolution = await Task.FromResult(initialSolution).WithCancellation(cancellationSource.Token);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just equivalent to cancellationSource.Token.ThrowIfCancellationRequested(); expectedSolution = initialSolution, which kinda doesn't make any sense here.

@JoeRobich

Copy link
Copy Markdown
Member Author

Continuing this work in #85805

@JoeRobich JoeRobich closed this Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants