Open fleksin opened 3 years ago
PR is welcome.
I could have a go at this. Any clues on where to start adding support for *.vue files?
@darrenmothersele Some ideas:
.vue
files..vue
files and parse typescript code from them(maybe by @vue/compiler-dom
).program
or create a new Program
instance: https://github.com/plantain-00/type-coverage/blob/master/packages/core/src/core.ts#L27I've done a bit of digging this evening, here is what I've found.
Route 1 - using vue-tsc
vue-tsc
has a method named createProgramProxy
(https://github.com/johnsoncodehk/volar/blob/master/packages/vue-tsc/src/proxy.ts#L7), which could be used instead of ts.createProgram
(https://github.com/plantain-00/type-coverage/blob/master/packages/core/src/core.ts#L27)
Something along the lines of:
import { createProgramProxy } from "vue-tsc/out/proxy.js";
//...
export async function lint(project: string, options?: Partial<LintOptions>) {
//...
// If Vue project use createProgramProxy, otherwise, use ts.createProgram
const program = createProgramProxy(
{
rootNames: rootNames,
options: compilerOptions,
host: undefined, // Language host??
oldProgram: lintOptions.oldProgram,
},
compilerOptions,
undefined, // Language host??
lintOptions.oldProgram
);
// ...
}
However, the createProgramProxy
from vue-tsc
requires passing through a compiler (https://github.com/johnsoncodehk/volar/blob/master/packages/vue-tsc/src/proxy.ts#L28), in which this package is passing undefined
. a "compilerHost" is created deep within the typescript core repo, which seems like quite a big undertaking.... (https://github.com/microsoft/TypeScript/blob/d1fa945261a30616c5e3557d1a9fc18f3482af30/src/services/services.ts#L1397)
The volar package is currently undergoing a big refactor - https://github.com/johnsoncodehk/volar/pull/1050/files - so it might be worth looking at this once the refractor is out.
Route 2 - Learnings from vue-type-audit
Taking a look at a similar npm package (https://github.com/andoshin11/vue-type-audit), it looks like the "compilerHost" could be something similar to this:
https://github.com/andoshin11/vue-type-audit/blob/master/src/languageService/createHost.ts#L24
As the title suggests. It seems like it doesn't support as I tested it. Do we have plan adding this feature? if not, I'm considering making a PR