volarjs / volar.js

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

feat(language-core): reimplement multi-source mapping #194

Closed johnsoncodehk closed 3 months ago

johnsoncodehk commented 3 months ago

https://github.com/volarjs/volar.js/commit/c4b297b2426ec8b032eec16c5396263bc03e2163 removed multi-source support, but to support Angular use cases, this PR re-implements it.

Changes

Example:

export const angularLanguagePlugin: LanguagePlugin<string> = {
    createVirtualCode(fileName, languageId, snapshot, { getAssociatedScript }) {
        if (fileName.endsWith('app.component.ts')) {

            // Register dependencies
            const templateScript = getAssociatedScript('.../template.html');

            if (templateScript) {
                return {
                    mappings: [
                        // Mappings for app.component.ts
                    ],
                    associatedScriptMappings: new Map([
                        [templateScript.id, [
                            // Mappings for template.html
                        ]],
                    ])
                }
            }
        }
    },
};
piotrtomiak commented 3 months ago

@johnsoncodehk - thanks for taking a look at this so quickly! I am now trying to rebase my changes on top of these changes.

piotrtomiak commented 3 months ago

@johnsoncodehk - I've finally managed to rebase the changes. It took more, because I as off most of yesterday. The PR is here: https://github.com/volarjs/volar.js/pull/197