Skip to content

Adds dynamic NuGet package resolution via #:package directives for C# file-based apps - #199

Open
ashar-builds wants to merge 5 commits into
Nimblesite:mainfrom
ashar-builds:main
Open

Adds dynamic NuGet package resolution via #:package directives for C# file-based apps#199
ashar-builds wants to merge 5 commits into
Nimblesite:mainfrom
ashar-builds:main

Conversation

@ashar-builds

Copy link
Copy Markdown
Contributor

TLDR

Adds dynamic NuGet package resolution via #:package directives for C# file-based apps and fixes a double-insertion bug for zero-length completion spans.

Details

1. Support for #:package Directives:

  • Added dynamic NuGet package restore capabilities in WorkspaceManager.SingleFile.cs and WorkspaceManager.cs.
  • When a #:package directive is encountered in a C# script or file-based app, the sidecar generates a temporary .csproj, executes a background dotnet restore, and extracts the PortableExecutableReferences to load into the AdhocWorkspace.
  • Implemented UpdateProjectlessClosureAsync to support real-time graph and package updates. As the user edits the document, new packages and included files are seamlessly resolved and injected into the active solution.

2. Autocomplete Double-Insertion Fix:

  • Fixed ComputeCompletionEditSpan overlap logic: Replaced OverlapsWith with IntersectsWith in WorkspaceManager.Helpers.cs.
  • Previously, zero-length completion spans (e.g., triggering completion immediately after typing a .) were failing the overlap check, causing the primary text edit to be incorrectly appended to the AdditionalEdits array alongside the main edit.
  • Cleaned up temporary workarounds in src/semantic.rs and WorkspaceManager.Helpers.cs to ensure standard LSP completion mechanisms are maintained without stripping insert_text or filter_text.

How Do The Automated Tests Prove It Works?

  • New Test Added: Added ResolveCompletion_with_empty_span_skips_primary_edit_in_additional_edits to WorkspaceManagerFeatureCoverageTests.cs. This test simulates the exact bug scenario by triggering completion at a 0-length span immediately following a dot (result.). It asserts that the primary completion edit (e.g., "ToString") is successfully filtered out and does not appear in the AdditionalEdits array.
  • Full Suite Verification: The C# Sidecar tests pass perfectly (466/466) and the Rust host tests pass (309/309 feature tests), proving this fix cleanly resolves the issue without regressing existing completion, navigation, or scripting features.

Introduce PackageRef and extend Closure to track package references. Update DocumentClosure to parse and collect #:package directives. Enhance WorkspaceManager to resolve NuGet packages using a temp MSBuild project and dotnet restore, integrating references into Roslyn projects. Track and update package references per document on live edits. Update tests and method signatures to support root text and package handling.
Added ResolveCompletion_with_empty_span_skips_primary_edit_in_additional_edits unit test to WorkspaceManagerFeatureCoverageTests. This test verifies that when completion is triggered on an empty span (e.g., after a dot), the primary edit is skipped in AdditionalEdits, preventing redundant insertion of completion text. Ensures correct behavior for cases like "ToString" completion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant