Skip to content

feat(cli): add public completion parsing API for external autocompletion#20

Open
JKamsker wants to merge 5 commits intospectreconsole:mainfrom
JKamsker:fix/autocomplete-public-api
Open

feat(cli): add public completion parsing API for external autocompletion#20
JKamsker wants to merge 5 commits intospectreconsole:mainfrom
JKamsker:fix/autocomplete-public-api

Conversation

@JKamsker
Copy link
Copy Markdown

@JKamsker JKamsker commented Feb 20, 2026

This PR adds a tiny, additive public surface to Spectre.Console.Cli so third-party autocompletion can work without reflection or internals access.

Why

External projects (e.g. my autocompletion lib on branch fix/autocomplete-public-api) previously had to use reflection/internal types to:

  • Determine the current command/leaf context from a partial command line
  • Access the app’s DI resolver to run dynamic suggestions

What’s included (surgical + additive)

  • New public Spectre.Console.Cli.ITypeResolverAccessor to expose the current ITypeResolver during execution
  • New public Spectre.Console.Cli.Completion.CommandLineParser + CommandLineParseResult + CommandLineMappedParameter to parse args against the command model and return:
    • leaf Help.ICommandInfo?
    • CommandType / SettingsType
    • mapped ICommandParameterInfo + value pairs
    • remaining arguments
  • Minimal wiring in Internal/CommandExecutor.cs to register:
    • ICommandAppSettings
    • Help.ICommandModel
    • ITypeResolverAccessor (populated for the lifetime of the resolver)

Consumer reference

JKToolKit autocompletion refactor using only public contracts

Notes

  • No breaking changes; no behavioral changes for normal command execution
  • The new completion API is a thin wrapper over existing internal parsing behavior

@patriksvensson
Copy link
Copy Markdown
Contributor

@JKamsker Looks good! Would need to have some test coverage, though, before we can get this merged.

@JKamsker JKamsker force-pushed the fix/autocomplete-public-api branch from 58958f7 to 55114fd Compare February 20, 2026 19:33
@JKamsker JKamsker marked this pull request as ready for review February 20, 2026 21:25
@JKamsker
Copy link
Copy Markdown
Author

Thanks for the quick reply @patriksvensson ! I have added some tests (i hope they suffice 😅 ) and i am confident the pr is ready for review

@JKamsker
Copy link
Copy Markdown
Author

JKamsker commented Mar 3, 2026

Hey @patriksvensson is there anything i can do to get this across the finishing line?

@patriksvensson
Copy link
Copy Markdown
Contributor

@JKamsker I haven't got around to review this yet. Will try to do it in the upcoming week. Sorry about this.

@JKamsker
Copy link
Copy Markdown
Author

JKamsker commented Mar 4, 2026

Thank you for the response, @patriksvensson!

As a side note: I'm not entirely convinced that registering ICommandModel, ICommandAppSettings, and ITypeResolverAccessor into the DI container is the cleanest way to enable external autocompletion, but I haven't been able to come up with a better alternative. If you have any ideas for a different design, I'd really appreciate the input!

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.

2 participants