Skip to content

Add ILanguageGeneratorResolver to look up a generator by id or file extension [minor] - #218

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/184-language-generator-resolver
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/184-language-generator-resolver

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #184

What was missing

Generators are registered through DI and each one has a LanguageId and a FileExtension, but nothing turns an id or an extension into a generator. Each consumer wrote its own FirstOrDefault, so they could disagree on case and on the leading dot. The CLI work in #116 has nothing to map --language py or an output file's extension onto.

Change

  • New ILanguageGeneratorResolver and LanguageGeneratorResolver in Coder/Languages:
  • AddLanguageGenerators, and therefore AddCoder, registers the resolver with TryAddSingleton.
  • CoderEditorApp builds its preview lookup and the language list on the resolver instead of its own FirstOrDefault. Its constructor is unchanged, so Program, the UI gallery and the tests don't change.

Tests (LanguageGeneratorResolverTests)

  • Every built-in id resolves to its generator, including mixed and upper case.
  • Every built-in extension resolves to its generator, bare, dotted, upper-case, and as a path with / and \ separators.
  • Unknown ids and extensions return false and a null generator. Cases covered: empty, ., an extensionless path, a dot in a directory name only, and model.py.bak.
  • Generators lists all seven.
  • With a stub pair, a duplicate id or extension resolves to the first generator. A generator that declares its extension with a leading dot still resolves.

With the registration in ServiceCollectionExtensions reverted, 33 of the 35 cases fail. The other 2 construct the resolver directly. Full Coder.Test suite: 1225 passed, 0 failed. Coder.sln builds clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_012KjGQ13RexM4WYjuEaBtE6


Generated by Claude Code

…xtension [minor]

AddLanguageGenerators now registers a resolver over the generators, with
TryGetByLanguageId and TryGetByFileExtension. Both ignore case; the
extension lookup takes a bare or dotted extension or a file path. When two
generators claim the same id or extension, the first registered wins. The
editor's preview lookup goes through it instead of its own FirstOrDefault.

Fixes #184

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012KjGQ13RexM4WYjuEaBtE6
@sonarqubecloud

Copy link
Copy Markdown

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.

No way to resolve a language generator by id or file extension (implementation plan Task 3.2 "language detection mechanism" not started)

2 participants