feat(content-mapper): add experimental content mapper for TypeScript 7 - #442
Draft
mizdra wants to merge 8 commits into
Draft
feat(content-mapper): add experimental content mapper for TypeScript 7#442mizdra wants to merge 8 commits into
mizdra wants to merge 8 commits into
Conversation
…ers as zero-width spans
…ion with the tsgo extension
🦋 Changeset detectedLatest commit: 0781f25 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ref: #377
Summary
The primary purpose of this PR is to prototype content mappers in a real-world tool and to give feedback to the TypeScript team, who are asking ecosystem tooling authors for input on the proposal (microsoft/typescript-go#2824).
TypeScript 7 (typescript-go) does not support TypeScript Server Plugins, so css-modules-kit cannot provide its language features through the current mechanism. This PR adds
@css-modules-kit/content-mapper, an experimental package implementing the proposed alternative: content mappers (microsoft/typescript-go#4712, unmerged).A content mapper transforms CSS Modules files into typed TypeScript code and hands it to tsgo. In editors, this enables language features such as Go to Definition, Find All References, Rename, and completion. In the plain
tscCLI, imports of CSS Modules type-check without any generated.d.tsfiles.What's included
.cssfiles are transformed into an empty module (export {}), so side-effect imports type-checkexamples/7-content-mapper) and a launch configurationtsgo (7-content-mapper)Intentionally not implemented
Some ts-plugin features are left out on purpose because the content mapper design makes them unnecessary:
cmkOptions.enabled: registering the mapper in the tsconfigcontentMappersfield is itself the opt-in, so a separate option to disable the plugin is unnecessary.d.tsfiles from module resolution: the content mapper provides types directly from the transformed code without generating.d.tsfiles, so there are no generated files to excludeKnown limitations
classNameattribute snippet), code fixes (e.g. adding a missing CSS rule), and the "Create CSS Module file" refactor. A content mapper can only transform file contents and has no way to customize language service responses; these features would require the middleware mechanism discussed separately in API usage patterns for complex editor extensions microsoft/typescript-go#2824@importor@value ... from), so the CI test job will be redHow to verify
vp test --project e2e(the first run clones and builds tsgo, which takes a few minutes)tsgo (7-content-mapper)from Run and Debug and try the language features inexamples/7-content-mapperexamples/7-content-mapper, run../../.tmp/typescript-go/built/tsgo -p tsconfig.json --loadExternalPlugins🤖 Generated with Claude Code