volarjs / volar.js

💙🌊
https://volarjs.dev/
MIT License
963 stars 47 forks source link

refactor(language-core): pluginized source map factory function #207

Closed johnsoncodehk closed 2 months ago

johnsoncodehk commented 2 months ago

Closes #203

Define the factory function of the source map through Language.mapperFactory, which allows the insertion of customized mapping logic.

Motivation

Individual frameworks may require somewhat special mapping processing logic. For example, WebStorm-Angular requires special processing for overlapping mapping ranges. These processing may not be common to all frameworks, so it is best to make the mapping behavior itself customizable.

Usage

After creating the Language instance, set mapperFactory property to override the default SourceMap factory function.

createLanguageServicePlugin((ts, info) => ({
    languagePlugins: [/* ... */],
    setup(language) {
        language.mapperFactory = mappings => new MySourceMap(mappings);
    },
});