Skip to content

Respect parser whitespace in completions - #2904

Open
pradeep-ramola wants to merge 1 commit into
dotnet:mainfrom
pradeep-ramola:fix/completion-whitespace-boundaries
Open

pradeep-ramola wants to merge 1 commit into
dotnet:mainfrom
pradeep-ramola:fix/completion-whitespace-boundaries

Conversation

@pradeep-ramola

Copy link
Copy Markdown

Fixes #2903.

Summary

Use char.IsWhiteSpace to find the word around the completion cursor, matching CommandLineParser.SplitCommandLine rather than recognizing only ASCII spaces.

Tabs and other whitespace currently leave multiple parsed tokens in WordToComplete; this also causes ParseResult.GetCompletions() to throw while trying to find that joined string in the token list. Trailing whitespace now correctly produces an empty word, and words at explicitly selected cursor positions are bounded by the same separators as parsing.

  • No public API, tokenization, completion ranking, or shell-script changes.
  • Existing ordinary-space and beyond-end cursor behavior remains covered by the existing suite.
  • Added 18 cases for space, tab, CR, LF, CRLF, and U+00A0 across cursor-word extraction, trailing whitespace, and real option-value completion.
  • Original source: 15 regression failures and three ordinary-space controls passing.
  • Harden shell completion generation and suggestion shims #2902 only extracts a helper in this source file; it leaves these word-boundary calculations unchanged.

Testing

Windows, SDK 12.0.100-alpha.1.26571.102:

dotnet test src/System.CommandLine.Tests/System.CommandLine.Tests.csproj --framework net472
dotnet test src/System.CommandLine.Tests/System.CommandLine.Tests.csproj --framework net10.0
  • Full net472 suite: 956 passed, four existing skips.
  • Full net10.0 target suite: 960 passed, seven existing skips. This ran on the available .NET 12 preview runtime using DOTNET_ROLL_FORWARD=Major and DOTNET_ROLL_FORWARD_TO_PRERELEASE=1, not a native .NET 10 runtime.
  • Completion-only suites: 80 passed and two existing skips on each target.
  • The repository's test SDK emits an existing VSTEST_ARTIFACTS_DIRECTORY fallback notice.
  • dotnet format whitespace --verify-no-changes --no-restore passes for the changed production file. Checking the two existing test files reports formatting issues on unchanged lines, with no diagnostics in the added test blocks; unrelated formatting is left untouched.
  • git diff --check passes.

Prepared with AI assistance; implementation and regressions were validated locally. No claims about other platforms or native .NET 10 execution.

Match completion word boundaries with the whitespace predicate used by
command-line splitting. Cover cursor boundaries, trailing whitespace,
and option-value completions without changing tokenization or ranking.

Fix dotnet#2903
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.

Completion word boundaries ignore tabs and other parser whitespace

1 participant