@volar/vue-typescript
Advanced tools
Comparing version 0.33.9 to 0.34.0
@@ -8,8 +8,4 @@ import type * as ts from 'typescript/lib/tsserverlibrary'; | ||
projectVersion: string | undefined; | ||
context: string[]; | ||
contextItems: ts.CompletionEntry[]; | ||
components: string[]; | ||
componentItems: ts.CompletionEntry[]; | ||
props: string[]; | ||
setupReturns: string[]; | ||
} | ||
@@ -16,0 +12,0 @@ export interface VueCompilerOptions { |
@@ -33,14 +33,8 @@ import type { TextRange } from '@volar/vue-code-gen'; | ||
getAll: () => import("./vueFile").VueFile[]; | ||
getTeleport: (lsType: "template" | "script", fileName: string) => import(".").Teleport | undefined; | ||
getEmbeddeds: (lsType: "template" | "script" | "nonTs") => Generator<{ | ||
getTeleport: (fileName: string) => import(".").Teleport | undefined; | ||
getEmbeddeds: () => Generator<{ | ||
vueFile: import("./vueFile").VueFile; | ||
embedded: import("./vueFile").Embedded; | ||
} | { | ||
vueFile: import("./vueFile").VueFile; | ||
embedded: import("./vueFile").Embedded; | ||
} | { | ||
vueFile: import("./vueFile").VueFile; | ||
embedded: import("./vueFile").Embedded; | ||
}, void, unknown>; | ||
fromEmbeddedLocation: (lsType: "template" | "script" | "nonTs", fileName: string, start: number, end?: number | undefined, filter?: ((data: import("@volar/vue-code-gen").EmbeddedFileMappingData) => boolean) | undefined, sourceMapFilter?: ((sourceMap: import(".").EmbeddedFileSourceMap) => boolean) | undefined) => Generator<{ | ||
fromEmbeddedLocation: (fileName: string, start: number, end?: number | undefined, filter?: ((data: import("@volar/vue-code-gen").EmbeddedFileMappingData) => boolean) | undefined, sourceMapFilter?: ((sourceMap: import(".").EmbeddedFileSourceMap) => boolean) | undefined) => Generator<{ | ||
fileName: string; | ||
@@ -66,3 +60,3 @@ range: { | ||
fromEmbeddedFile: (file: EmbeddedFile<unknown>) => import("./vueFile").VueFile | undefined; | ||
fromEmbeddedFileName: (lsType: "template" | "script" | "nonTs", fileName: string) => { | ||
fromEmbeddedFileName: (fileName: string) => { | ||
vueFile: import("./vueFile").VueFile; | ||
@@ -72,9 +66,8 @@ embedded: import("./vueFile").Embedded; | ||
}; | ||
getTsLs: (lsType: 'template' | 'script') => ts.LanguageService; | ||
getTsLsHost: (lsType: 'template' | 'script') => ts.LanguageServiceHost; | ||
update: (shouldUpdateTemplateScript: boolean) => void; | ||
getTsLs: () => ts.LanguageService; | ||
getTsLsHost: () => ts.LanguageServiceHost; | ||
update: () => void; | ||
getScriptContentVersion: () => number; | ||
dispose: () => void; | ||
onInitProgress(cb: (p: number) => void): void; | ||
getLocalTypesFiles: (lsType: 'script' | 'template') => { | ||
getLocalTypesFiles: () => { | ||
fileNames: string[]; | ||
@@ -81,0 +74,0 @@ code: string; |
@@ -16,8 +16,4 @@ "use strict"; | ||
let scriptContentVersion = 0; // only update by `<script>` / `<script setup>` / *.ts content | ||
let scriptProjectVersion = 0; // update by script LS virtual files / *.ts | ||
let templateProjectVersion = 0; | ||
let lastScriptProjectVersionWhenTemplateProjectVersionUpdate = -1; | ||
let tsProjectVersion = 0; // update by script LS virtual files / *.ts | ||
const vueFiles = (0, vueFiles_1.createVueFiles)(); | ||
const templateScriptUpdateFileNames = new Set(); | ||
const initProgressCallback = []; | ||
const plugins = [ | ||
@@ -27,10 +23,5 @@ (0, html_1.default)(), | ||
]; | ||
const templateTsHost = options.vueCompilerOptions.experimentalDisableTemplateSupport ? undefined : createTsLsHost('template'); | ||
const scriptTsHost = createTsLsHost('script'); | ||
const templateTsLsRaw = templateTsHost ? ts.createLanguageService(templateTsHost) : undefined; | ||
const scriptTsLsRaw = ts.createLanguageService(scriptTsHost); | ||
if (templateTsHost && templateTsLsRaw) { | ||
(0, ts_1.injectCacheLogicToLanguageServiceHost)(ts, templateTsHost, templateTsLsRaw); | ||
} | ||
(0, ts_1.injectCacheLogicToLanguageServiceHost)(ts, scriptTsHost, scriptTsLsRaw); | ||
const tsLsHost = createTsLsHost(); | ||
const tsLsRaw = ts.createLanguageService(tsLsHost); | ||
(0, ts_1.injectCacheLogicToLanguageServiceHost)(ts, tsLsHost, tsLsRaw); | ||
const localTypesScript = ts.ScriptSnapshot.fromString(localTypes.getTypesCode(isVue2)); | ||
@@ -40,15 +31,11 @@ return { | ||
vueFiles, | ||
getTsLs: (lsType) => lsType === 'template' ? templateTsLsRaw : scriptTsLsRaw, | ||
getTsLsHost: (lsType) => lsType === 'template' ? templateTsHost : scriptTsHost, | ||
getTsLs: () => tsLsRaw, | ||
getTsLsHost: () => tsLsHost, | ||
update, | ||
getScriptContentVersion: () => scriptContentVersion, | ||
dispose: () => { | ||
scriptTsLsRaw.dispose(); | ||
templateTsLsRaw?.dispose(); | ||
tsLsRaw.dispose(); | ||
}, | ||
onInitProgress(cb) { | ||
initProgressCallback.push(cb); | ||
}, | ||
getLocalTypesFiles: (lsType) => { | ||
const fileNames = getLocalTypesFiles(lsType); | ||
getLocalTypesFiles: () => { | ||
const fileNames = getLocalTypesFiles(); | ||
const code = localTypes.getTypesCode(isVue2); | ||
@@ -61,8 +48,6 @@ return { | ||
}; | ||
function getLocalTypesFiles(lsType) { | ||
if (lsType === 'script') | ||
return []; | ||
function getLocalTypesFiles() { | ||
return vueFiles.getDirs().map(dir => path.join(dir, localTypes.typesFileName)); | ||
} | ||
function update(shouldUpdateTemplateScript) { | ||
function update() { | ||
const newVueProjectVersion = options.vueLsHost.getVueProjectVersion?.(); | ||
@@ -114,10 +99,7 @@ if (newVueProjectVersion === undefined || newVueProjectVersion !== vueProjectVersion) { | ||
if (finalUpdateFileNames.length) { | ||
updateSourceFiles(finalUpdateFileNames, shouldUpdateTemplateScript); | ||
updateSourceFiles(finalUpdateFileNames); | ||
} | ||
} | ||
else if (shouldUpdateTemplateScript && templateScriptUpdateFileNames.size) { | ||
updateSourceFiles([], shouldUpdateTemplateScript); | ||
} | ||
} | ||
function createTsLsHost(lsType) { | ||
function createTsLsHost() { | ||
const scriptSnapshots = new Map(); | ||
@@ -137,6 +119,6 @@ const fileVersions = new WeakMap(); | ||
if (fileExists) { | ||
updateSourceFiles([fileNameTrim], false); // create virtual files | ||
updateSourceFiles([fileNameTrim]); // create virtual files | ||
} | ||
} | ||
return !!vueFiles.fromEmbeddedFileName(lsType, fileName); | ||
return !!vueFiles.fromEmbeddedFileName(fileName); | ||
} | ||
@@ -149,3 +131,3 @@ else { | ||
getProjectVersion: () => { | ||
return options.vueLsHost.getProjectVersion?.() + '-' + (lsType === 'template' ? templateProjectVersion : scriptProjectVersion).toString(); | ||
return options.vueLsHost.getProjectVersion?.() + '-' + tsProjectVersion.toString(); | ||
}, | ||
@@ -183,8 +165,2 @@ getScriptFileNames, | ||
}; | ||
if (lsType === 'template') { | ||
_tsHost.getCompilationSettings = () => ({ | ||
...options.vueLsHost.getCompilationSettings(), | ||
jsx: ts.JsxEmit.Preserve, | ||
}); | ||
} | ||
const tsHost = new Proxy(_tsHost, { | ||
@@ -197,4 +173,4 @@ get: (target, property) => { | ||
function getScriptFileNames() { | ||
const tsFileNames = getLocalTypesFiles(lsType); | ||
for (const mapped of vueFiles.getEmbeddeds(lsType)) { | ||
const tsFileNames = getLocalTypesFiles(); | ||
for (const mapped of vueFiles.getEmbeddeds()) { | ||
tsFileNames.push(mapped.embedded.file.fileName); // virtual .ts | ||
@@ -217,3 +193,3 @@ } | ||
} | ||
let mapped = vueFiles.fromEmbeddedFileName(lsType, fileName); | ||
let mapped = vueFiles.fromEmbeddedFileName(fileName); | ||
if (mapped) { | ||
@@ -245,3 +221,3 @@ if (fileVersions.has(mapped.embedded.file)) { | ||
} | ||
const mapped = vueFiles.fromEmbeddedFileName(lsType, fileName); | ||
const mapped = vueFiles.fromEmbeddedFileName(fileName); | ||
if (mapped) { | ||
@@ -255,3 +231,3 @@ const text = mapped.embedded.file.content; | ||
if (tsScript) { | ||
if (lsType === 'template' && basename === 'runtime-dom.d.ts') { | ||
if (basename === 'runtime-dom.d.ts') { | ||
// allow arbitrary attributes | ||
@@ -267,11 +243,5 @@ let tsScriptText = tsScript.getText(0, tsScript.getLength()); | ||
} | ||
function updateSourceFiles(fileNames, shouldUpdateTemplateScript) { | ||
function updateSourceFiles(fileNames) { | ||
let vueScriptContentsUpdate = false; | ||
let vueScriptsUpdated = false; | ||
let templateScriptUpdated = false; | ||
if (shouldUpdateTemplateScript) { | ||
for (const cb of initProgressCallback) { | ||
cb(0); | ||
} | ||
} | ||
for (const fileName of fileNames) { | ||
@@ -286,3 +256,3 @@ const sourceFile = vueFiles.get(fileName); | ||
if (!sourceFile) { | ||
vueFiles.set(fileName, (0, vueFile_1.createVueFile)(fileName, scriptText, scriptVersion, plugins, options.vueCompilerOptions, options.typescript, options.baseCssModuleType, options.getCssClasses)); | ||
vueFiles.set(fileName, (0, vueFile_1.createVueFile)(fileName, scriptText, scriptVersion, plugins, options.vueCompilerOptions, options.typescript, options.baseCssModuleType, options.getCssClasses, tsLsRaw, tsLsHost)); | ||
vueScriptContentsUpdate = true; | ||
@@ -299,7 +269,3 @@ vueScriptsUpdated = true; | ||
} | ||
if (updates.templateScriptUpdated) { | ||
templateScriptUpdated = true; | ||
} | ||
} | ||
templateScriptUpdateFileNames.add(fileName); | ||
} | ||
@@ -310,26 +276,4 @@ if (vueScriptContentsUpdate) { | ||
if (vueScriptsUpdated) { | ||
scriptProjectVersion++; | ||
templateProjectVersion++; | ||
tsProjectVersion++; | ||
} | ||
if (shouldUpdateTemplateScript && lastScriptProjectVersionWhenTemplateProjectVersionUpdate !== scriptContentVersion) { | ||
lastScriptProjectVersionWhenTemplateProjectVersionUpdate = scriptContentVersion; | ||
let currentNums = 0; | ||
for (const fileName of templateScriptUpdateFileNames) { | ||
if (templateTsLsRaw && templateTsHost && vueFiles.get(fileName)?.updateTemplateScript(templateTsLsRaw, templateTsHost)) { | ||
templateScriptUpdated = true; | ||
} | ||
currentNums++; | ||
for (const cb of initProgressCallback) { | ||
cb(currentNums / templateScriptUpdateFileNames.size); | ||
} | ||
} | ||
templateScriptUpdateFileNames.clear(); | ||
for (const cb of initProgressCallback) { | ||
cb(1); | ||
} | ||
initProgressCallback.length = 0; | ||
} | ||
if (templateScriptUpdated) { | ||
templateProjectVersion++; | ||
} | ||
} | ||
@@ -345,4 +289,3 @@ function unsetSourceFiles(uris) { | ||
scriptContentVersion++; | ||
scriptProjectVersion++; | ||
templateProjectVersion++; | ||
tsProjectVersion++; | ||
} | ||
@@ -349,0 +292,0 @@ } |
@@ -16,3 +16,2 @@ "use strict"; | ||
content: customBlock.content, | ||
lsType: 'nonTs', | ||
capabilities: { | ||
@@ -19,0 +18,0 @@ diagnostics: true, |
import { Ref } from '@vue/reactivity'; | ||
import { Embedded, EmbeddedFile, Sfc } from '../vueFile'; | ||
export declare function useSfcEntryForTemplateLs(fileName: string, script: Ref<Sfc['script']>, scriptSetup: Ref<Sfc['scriptSetup']>, template: Ref<Sfc['template']>, hasTsDoc: Ref<boolean>, isVue2: boolean): { | ||
export declare function useSfcEntryForTemplateLs(fileName: string, script: Ref<Sfc['script']>, scriptSetup: Ref<Sfc['scriptSetup']>, isVue2: boolean): { | ||
file: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown>>; | ||
embedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
}; |
@@ -10,44 +10,25 @@ "use strict"; | ||
const localTypes_1 = require("../utils/localTypes"); | ||
function useSfcEntryForTemplateLs(fileName, script, scriptSetup, template, hasTsDoc, isVue2) { | ||
function useSfcEntryForTemplateLs(fileName, script, scriptSetup, isVue2) { | ||
const file = (0, reactivity_1.computed)(() => { | ||
const baseFileName = path.basename(fileName); | ||
const tsScriptFileName = hasTsDoc.value ? '__VLS_script_ts' : '__VLS_script'; | ||
let content = ''; | ||
content += '// @ts-nocheck\n'; | ||
content += `import * as __VLS_types from './__VLS_types';\n`; | ||
if (script.value || scriptSetup.value) { | ||
content += `import { __VLS_options as __VLS_options_ts } from './${baseFileName}.${tsScriptFileName}';\n`; | ||
content += `import { __VLS_options, __VLS_name } from './${baseFileName}.__VLS_script';\n`; | ||
content += `export { __VLS_options, __VLS_name } from './${baseFileName}.__VLS_script';\n`; | ||
content += `export * from './${baseFileName}.__VLS_script';\n`; | ||
content += `import __VLS_component_ts from './${baseFileName}.${tsScriptFileName}';\n`; | ||
content += `import __VLS_component from './${baseFileName}.__VLS_script';\n`; | ||
content += `export { default as __VLS_component } from './${baseFileName}.__VLS_script';\n`; | ||
} | ||
else { | ||
content += `export var __VLS_name = undefined;\n`; | ||
content += `export var __VLS_options = {};\n`; | ||
content += `export var __VLS_component = (await import('${(0, localTypes_1.getVueLibraryName)(isVue2)}')).defineComponent({});\n`; | ||
content += `var __VLS_options_ts = {};\n`; | ||
content += `var __VLS_component_ts = (await import('${(0, localTypes_1.getVueLibraryName)(isVue2)}')).defineComponent({});\n`; | ||
content += `var __VLS_name = undefined;\n`; | ||
content += `var __VLS_options = {};\n`; | ||
content += `var __VLS_component = (await import('${(0, localTypes_1.getVueLibraryName)(isVue2)}')).defineComponent({});\n`; | ||
} | ||
content += `declare var __VLS_ctx: __VLS_types.ComponentContext<typeof __VLS_component_ts>;\n`; | ||
content += `declare var __VLS_ctx: __VLS_types.ComponentContext<typeof __VLS_component>;\n`; | ||
content += `declare var __VLS_ComponentsWrap: typeof __VLS_options & { components: { } };\n`; | ||
content += `declare var __VLS_Components: NonNullable<typeof __VLS_component extends { components: infer C } ? C : {}> & typeof __VLS_ComponentsWrap.components & __VLS_types.GlobalComponents & __VLS_types.PickComponents<typeof __VLS_ctx> & __VLS_types.SelfComponent<typeof __VLS_name, typeof __VLS_component>;\n`; | ||
content += `__VLS_ctx.${string_1.SearchTexts.Context};\n`; | ||
content += `__VLS_Components.${string_1.SearchTexts.Components};\n`; | ||
content += `({} as __VLS_types.OptionsSetupReturns<typeof __VLS_options_ts>).${string_1.SearchTexts.SetupReturns};\n`; | ||
content += `({} as __VLS_types.OptionsProps<typeof __VLS_options_ts>).${string_1.SearchTexts.Props};\n`; | ||
content += `({} as __VLS_types.GlobalAttrs).${string_1.SearchTexts.GlobalAttrs};`; | ||
content += `\n`; | ||
content += `export default {} as typeof __VLS_component & {\n`; | ||
content += `__VLS_raw: typeof __VLS_component\n`; | ||
content += `__VLS_options: typeof __VLS_options,\n`; | ||
content += template.value ? `__VLS_slots: typeof import ('./${baseFileName}.__VLS_template').default,\n` : `// no template\n`; | ||
content += `};\n`; | ||
content += `({} as __VLS_types.GlobalAttrs).${string_1.SearchTexts.GlobalAttrs};\n`; | ||
const file = { | ||
fileName: fileName + '.ts', | ||
fileName: fileName + '.__VLS_middle.ts', | ||
lang: 'ts', | ||
content, | ||
lsType: 'template', | ||
capabilities: { | ||
@@ -54,0 +35,0 @@ diagnostics: false, |
@@ -19,3 +19,2 @@ "use strict"; | ||
content: script.value.content, | ||
lsType: 'nonTs', | ||
capabilities: { | ||
@@ -22,0 +21,0 @@ diagnostics: false, |
@@ -10,6 +10,4 @@ import { Ref, ComputedRef } from '@vue/reactivity'; | ||
file: T extends "script" ? ComputedRef<EmbeddedFile<undefined>> : ComputedRef<EmbeddedFile<undefined> | undefined>; | ||
fileTs: ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
embedded: ComputedRef<Embedded | undefined>; | ||
embeddedTs: ComputedRef<Embedded | undefined>; | ||
teleport: ComputedRef<Teleport>; | ||
}; |
@@ -35,3 +35,2 @@ "use strict"; | ||
const file = { | ||
lsType, | ||
fileName: fileName + '.' + lang.value, | ||
@@ -53,3 +52,2 @@ lang: lang.value, | ||
const file = { | ||
lsType, | ||
fileName: fileName + '.__VLS_script.' + lang.value, | ||
@@ -70,22 +68,2 @@ lang: lang.value, | ||
}); | ||
const fileTs = (0, reactivity_1.computed)(() => { | ||
if (lsType === 'template' && file.value && ['js', 'jsx'].includes(lang.value)) { | ||
const tsLang = lang.value === 'jsx' ? 'tsx' : 'ts'; | ||
const _file = { | ||
lsType, | ||
fileName: fileName + '.__VLS_script_ts.' + tsLang, | ||
lang: tsLang, | ||
content: file.value.content, | ||
capabilities: { | ||
diagnostics: false, | ||
foldingRanges: false, | ||
formatting: false, | ||
documentSymbol: false, | ||
codeActions: false, | ||
}, | ||
data: undefined, | ||
}; | ||
return _file; | ||
} | ||
}); | ||
const embedded = (0, reactivity_1.computed)(() => { | ||
@@ -99,16 +77,2 @@ if (file.value) { | ||
}); | ||
const embeddedTs = (0, reactivity_1.computed)(() => { | ||
if (embedded.value && fileTs.value) { | ||
return { | ||
file: fileTs.value, | ||
sourceMap: new sourceMaps_1.EmbeddedFileSourceMap(embedded.value.sourceMap.mappings.map(mapping => ({ | ||
...mapping, | ||
data: { | ||
...mapping.data, | ||
capabilities: {} | ||
}, | ||
}))), | ||
}; | ||
} | ||
}); | ||
const teleport = (0, reactivity_1.computed)(() => { | ||
@@ -124,5 +88,3 @@ const teleport = new sourceMaps_1.Teleport(); | ||
file: file, | ||
fileTs, | ||
embedded, | ||
embeddedTs, | ||
teleport, | ||
@@ -129,0 +91,0 @@ }; |
@@ -16,3 +16,2 @@ "use strict"; | ||
content: style.content, | ||
lsType: 'nonTs', | ||
capabilities: { | ||
@@ -19,0 +18,0 @@ diagnostics: true, |
@@ -14,3 +14,2 @@ "use strict"; | ||
content: template.value.content, | ||
lsType: 'nonTs', | ||
capabilities: { | ||
@@ -17,0 +16,0 @@ diagnostics: true, |
import { CodeGen } from '@volar/code-gen'; | ||
import type { parseScriptSetupRanges } from '@volar/vue-code-gen/out/parsers/scriptSetupRanges'; | ||
import { Ref } from '@vue/reactivity'; | ||
import { ITemplateScriptData, VueCompilerOptions } from '../types'; | ||
import { Teleport } from '../utils/sourceMaps'; | ||
import { VueCompilerOptions } from '../types'; | ||
import type { TextRange } from '@volar/vue-code-gen'; | ||
@@ -10,3 +9,3 @@ import { Embedded, EmbeddedFile, Sfc } from '../vueFile'; | ||
import { EmbeddedFileMappingData } from '@volar/vue-code-gen'; | ||
export declare function useSfcTemplateScript(fileName: string, template: Ref<Sfc['template']>, scriptSetup: Ref<Sfc['scriptSetup']>, scriptSetupRanges: Ref<ReturnType<typeof parseScriptSetupRanges> | undefined>, styles: Ref<Sfc['styles']>, templateScriptData: ITemplateScriptData, styleFiles: ReturnType<typeof useSfcStyles>['files'], styleEmbeddeds: ReturnType<typeof useSfcStyles>['embeddeds'], templateData: Ref<{ | ||
export declare function useSfcTemplateScript(ts: typeof import('typescript/lib/tsserverlibrary'), fileName: string, template: Ref<Sfc['template']>, script: Ref<Sfc['script']>, scriptSetup: Ref<Sfc['scriptSetup']>, scriptSetupRanges: Ref<ReturnType<typeof parseScriptSetupRanges> | undefined>, styles: Ref<Sfc['styles']>, styleFiles: ReturnType<typeof useSfcStyles>['files'], styleEmbeddeds: ReturnType<typeof useSfcStyles>['embeddeds'], templateData: Ref<{ | ||
lang: string; | ||
@@ -17,3 +16,3 @@ htmlToTemplate: (start: number, end: number) => { | ||
} | undefined; | ||
} | undefined>, sfcTemplateCompileResult: Ref<ReturnType<(typeof import('@volar/vue-code-gen'))['compileSFCTemplate']> | undefined>, sfcStyles: ReturnType<(typeof import('./useSfcStyles'))['useSfcStyles']>['files'], scriptLang: Ref<string>, compilerOptions: VueCompilerOptions, baseCssModuleType: string, getCssVBindRanges: (cssEmbeddeFile: EmbeddedFile) => TextRange[], getCssClasses: (cssEmbeddeFile: EmbeddedFile) => Record<string, TextRange[]>): { | ||
} | undefined>, sfcTemplateCompileResult: Ref<ReturnType<(typeof import('@volar/vue-code-gen'))['compileSFCTemplate']> | undefined>, sfcStyles: ReturnType<(typeof import('./useSfcStyles'))['useSfcStyles']>['files'], scriptLang: Ref<string>, compilerOptions: VueCompilerOptions, baseCssModuleType: string, getCssVBindRanges: (cssEmbeddeFile: EmbeddedFile) => TextRange[], getCssClasses: (cssEmbeddeFile: EmbeddedFile) => Record<string, TextRange[]>, isVue2: boolean): { | ||
templateCodeGens: import("@vue/reactivity").ComputedRef<{ | ||
@@ -35,9 +34,7 @@ codeGen: CodeGen<EmbeddedFileMappingData>; | ||
embedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
file: Ref<EmbeddedFile<unknown> | undefined>; | ||
formatFile: Ref<EmbeddedFile<unknown> | undefined>; | ||
file: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
formatFile: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
formatEmbedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
teleport: Ref<Teleport | undefined>; | ||
inlineCssFile: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
inlineCssEmbedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
update: () => void; | ||
}; |
@@ -11,3 +11,5 @@ "use strict"; | ||
const path = require("path"); | ||
function useSfcTemplateScript(fileName, template, scriptSetup, scriptSetupRanges, styles, templateScriptData, styleFiles, styleEmbeddeds, templateData, sfcTemplateCompileResult, sfcStyles, scriptLang, compilerOptions, baseCssModuleType, getCssVBindRanges, getCssClasses) { | ||
const transform_1 = require("@volar/vue-code-gen/out/transform"); | ||
const localTypes_1 = require("../utils/localTypes"); | ||
function useSfcTemplateScript(ts, fileName, template, script, scriptSetup, scriptSetupRanges, styles, styleFiles, styleEmbeddeds, templateData, sfcTemplateCompileResult, sfcStyles, scriptLang, compilerOptions, baseCssModuleType, getCssVBindRanges, getCssClasses, isVue2) { | ||
const baseFileName = path.basename(fileName); | ||
@@ -36,3 +38,3 @@ const cssModuleClasses = (0, reactivity_1.computed)(() => styleFiles.value.reduce((obj, style) => { | ||
return; | ||
return templateGen.generate(templateData.value.lang, sfcTemplateCompileResult.value.ast, compilerOptions.experimentalCompatMode === 2, Object.values(cssScopedClasses.value).map(map => Object.keys(map)).flat(), templateData.value.htmlToTemplate, !!scriptSetup.value, { | ||
return templateGen.generate(ts, templateData.value.lang, sfcTemplateCompileResult.value.ast, compilerOptions.experimentalCompatMode === 2, Object.values(cssScopedClasses.value).map(map => Object.keys(map)).flat(), templateData.value.htmlToTemplate, !!scriptSetup.value, { | ||
getEmitCompletion: string_1.SearchTexts.EmitCompletion, | ||
@@ -45,13 +47,22 @@ getPropsCompletion: string_1.SearchTexts.PropsCompletion, | ||
codeGen.addText(`import * as __VLS_types from './__VLS_types';\n`); | ||
codeGen.addText(`import { __VLS_options, __VLS_name, __VLS_component } from './${baseFileName}';\n`); | ||
if (script.value || scriptSetup.value) { | ||
codeGen.addText(`import { __VLS_options, __VLS_name } from './${baseFileName}.__VLS_script';\n`); | ||
codeGen.addText(`import __VLS_component from './${baseFileName}.__VLS_script';\n`); | ||
} | ||
else { | ||
codeGen.addText(`var __VLS_name = undefined;\n`); | ||
codeGen.addText(`var __VLS_options = {};\n`); | ||
codeGen.addText(`var __VLS_component = (await import('${(0, localTypes_1.getVueLibraryName)(isVue2)}')).defineComponent({});\n`); | ||
} | ||
writeImportTypes(); | ||
codeGen.addText(`declare var __VLS_ctxRaw: InstanceType<typeof __VLS_component>;\n`); | ||
codeGen.addText(`declare var __VLS_ctx: __VLS_types.ExtractRawComponents<typeof __VLS_ctxRaw>;\n`); | ||
codeGen.addText(`declare var __VLS_ctx: InstanceType<typeof __VLS_component>;\n`); | ||
codeGen.addText(`declare var __VLS_vmUnwrap: typeof __VLS_options & { components: { } };\n`); | ||
/* Components */ | ||
codeGen.addText('/* Components */\n'); | ||
codeGen.addText('declare var __VLS_wrapComponentsRaw: NonNullable<typeof __VLS_component extends { components: infer C } ? C : {}> & __VLS_types.GlobalComponents & typeof __VLS_vmUnwrap.components & __VLS_types.PickComponents<typeof __VLS_ctxRaw>;\n'); // has __VLS_options | ||
codeGen.addText('declare var __VLS_ownComponent: __VLS_types.SelfComponent<typeof __VLS_name, typeof __VLS_component & { __VLS_raw: typeof __VLS_component, __VLS_options: typeof __VLS_options, __VLS_slots: typeof __VLS_slots }>;\n'); | ||
codeGen.addText('declare var __VLS_wrapComponents: typeof __VLS_wrapComponentsRaw & Omit<typeof __VLS_ownComponent, keyof typeof __VLS_wrapComponentsRaw>;\n'); | ||
codeGen.addText('declare var __VLS_rawComponents: __VLS_types.ConvertInvalidComponents<__VLS_types.ExtractRawComponents<typeof __VLS_wrapComponents>> & JSX.IntrinsicElements;\n'); // sort by priority | ||
codeGen.addText('declare var __VLS_otherComponents: NonNullable<typeof __VLS_component extends { components: infer C } ? C : {}> & __VLS_types.GlobalComponents & typeof __VLS_vmUnwrap.components & __VLS_types.PickComponents<typeof __VLS_ctx>;\n'); | ||
codeGen.addText('declare var __VLS_ownComponent: __VLS_types.SelfComponent<typeof __VLS_name, typeof __VLS_component>;\n'); | ||
codeGen.addText('declare var __VLS_allComponents: typeof __VLS_otherComponents & Omit<typeof __VLS_ownComponent, keyof typeof __VLS_otherComponents>;\n'); | ||
codeGen.addText('declare var __VLS_rawComponents: __VLS_types.ConvertInvalidComponents<typeof __VLS_allComponents> & JSX.IntrinsicElements;\n'); // sort by priority | ||
codeGen.addText(`__VLS_allComponents.${string_1.SearchTexts.Components};\n`); | ||
codeGen.addText(`({} as __VLS_types.GlobalAttrs).${string_1.SearchTexts.GlobalAttrs};\n`); | ||
/* CSS Module */ | ||
@@ -72,5 +83,2 @@ codeGen.addText('/* CSS Module */\n'); | ||
codeGen.addText('declare var __VLS_styleScopedClasses: __VLS_StyleScopedClasses | keyof __VLS_StyleScopedClasses | (keyof __VLS_StyleScopedClasses)[];\n'); | ||
/* Props */ | ||
codeGen.addText(`/* Props */\n`); | ||
const ctxMappings = writeProps(); | ||
codeGen.addText(`/* CSS variable injection */\n`); | ||
@@ -86,3 +94,2 @@ writeCssVars(); | ||
cssScopedMappings, | ||
ctxMappings, | ||
}; | ||
@@ -144,65 +151,4 @@ function writeImportTypes() { | ||
} | ||
function writeProps() { | ||
const propsSet = new Set(templateScriptData.props); | ||
const mappings = []; | ||
for (const propName of templateScriptData.context) { | ||
codeGen.addText(`declare let `); | ||
const templateSideRange = codeGen.addText(propName); | ||
codeGen.addText(`: typeof __VLS_ctx.`); | ||
const scriptSideRange = codeGen.addText(propName); | ||
codeGen.addText(`;`); | ||
mappings.push({ | ||
data: { | ||
isAdditionalReference: false, | ||
toSource: { | ||
capabilities: { | ||
definitions: true, | ||
references: true, | ||
rename: true, | ||
}, | ||
}, | ||
toTarget: { | ||
capabilities: { | ||
definitions: true, | ||
references: true, | ||
rename: true, | ||
}, | ||
}, | ||
}, | ||
mode: SourceMaps.Mode.Offset, | ||
sourceRange: scriptSideRange, | ||
mappedRange: templateSideRange, | ||
}); | ||
if (propsSet.has(propName)) { | ||
codeGen.addText(` __VLS_options.props.`); | ||
const scriptSideRange2 = codeGen.addText(propName); | ||
codeGen.addText(`;`); | ||
mappings.push({ | ||
data: { | ||
isAdditionalReference: true, | ||
toSource: { | ||
capabilities: { | ||
definitions: true, | ||
references: true, | ||
rename: true, | ||
}, | ||
}, | ||
toTarget: { | ||
capabilities: { | ||
definitions: true, | ||
references: true, | ||
rename: true, | ||
}, | ||
}, | ||
}, | ||
mode: SourceMaps.Mode.Offset, | ||
sourceRange: scriptSideRange2, | ||
mappedRange: templateSideRange, | ||
}); | ||
} | ||
codeGen.addText(`\n`); | ||
} | ||
return mappings; | ||
} | ||
function writeCssVars() { | ||
const emptyLocalVars = {}; | ||
for (let i = 0; i < sfcStyles.value.length; i++) { | ||
@@ -213,15 +159,25 @@ const style = sfcStyles.value[i]; | ||
const bindText = style.content.substring(cssBind.start, cssBind.end); | ||
codeGen.addCode(bindText, cssBind, SourceMaps.Mode.Offset, { | ||
vueTag: 'style', | ||
vueTagIndex: i, | ||
capabilities: { | ||
basic: true, | ||
references: true, | ||
definitions: true, | ||
diagnostic: true, | ||
rename: true, | ||
completion: true, | ||
semanticTokens: true, | ||
}, | ||
}); | ||
(0, transform_1.walkInterpolationFragment)(ts, bindText, (frag, fragOffset) => { | ||
if (fragOffset === undefined) { | ||
codeGen.addText(frag); | ||
} | ||
else { | ||
codeGen.addCode(frag, { | ||
start: cssBind.start + fragOffset, | ||
end: cssBind.start + fragOffset + frag.length, | ||
}, SourceMaps.Mode.Offset, { | ||
vueTag: 'style', | ||
vueTagIndex: i, | ||
capabilities: { | ||
basic: true, | ||
references: true, | ||
definitions: true, | ||
diagnostic: true, | ||
rename: true, | ||
completion: true, | ||
semanticTokens: true, | ||
}, | ||
}); | ||
} | ||
}, emptyLocalVars); | ||
codeGen.addText(';\n'); | ||
@@ -284,3 +240,2 @@ } | ||
const file = { | ||
lsType: 'nonTs', | ||
fileName: fileName + '.template.css', | ||
@@ -314,5 +269,40 @@ lang: 'css', | ||
}); | ||
const file = (0, reactivity_1.ref)(); | ||
const formatFile = (0, reactivity_1.ref)(); | ||
const teleport = (0, reactivity_1.ref)(); | ||
const file = (0, reactivity_1.computed)(() => { | ||
if (data.value) { | ||
const lang = scriptLang.value === 'js' ? 'jsx' : scriptLang.value === 'ts' ? 'tsx' : scriptLang.value; | ||
const embeddedFile = { | ||
fileName: fileName + '.__VLS_template.' + lang, | ||
lang: lang, | ||
content: data.value.codeGen.getText(), | ||
capabilities: { | ||
diagnostics: true, | ||
foldingRanges: false, | ||
formatting: false, | ||
documentSymbol: false, | ||
codeActions: false, | ||
}, | ||
data: undefined, | ||
}; | ||
return embeddedFile; | ||
} | ||
}); | ||
const formatFile = (0, reactivity_1.computed)(() => { | ||
if (templateCodeGens.value) { | ||
const lang = scriptLang.value === 'js' ? 'jsx' : scriptLang.value === 'ts' ? 'tsx' : scriptLang.value; | ||
const embeddedFile = { | ||
fileName: fileName + '.__VLS_template.format.' + lang, | ||
lang: lang, | ||
content: templateCodeGens.value.formatCodeGen.getText(), | ||
capabilities: { | ||
diagnostics: false, | ||
foldingRanges: false, | ||
formatting: true, | ||
documentSymbol: true, | ||
codeActions: false, | ||
}, | ||
data: undefined, | ||
}; | ||
return embeddedFile; | ||
} | ||
}); | ||
return { | ||
@@ -324,6 +314,4 @@ templateCodeGens, | ||
formatEmbedded, | ||
teleport, | ||
inlineCssFile, | ||
inlineCssEmbedded, | ||
update, // TODO: cheapComputed | ||
}; | ||
@@ -343,47 +331,2 @@ function parseMappingSourceRange(data, range) { | ||
} | ||
function update() { | ||
const newLang = scriptLang.value === 'js' ? 'jsx' : scriptLang.value === 'ts' ? 'tsx' : scriptLang.value; | ||
if (data.value?.codeGen.getText() !== file.value?.content || (file.value && file.value.lang !== newLang)) { | ||
if (data.value) { | ||
file.value = { | ||
lsType: 'template', | ||
fileName: fileName + '.__VLS_template.' + newLang, | ||
lang: newLang, | ||
content: data.value.codeGen.getText(), | ||
capabilities: { | ||
diagnostics: true, | ||
foldingRanges: false, | ||
formatting: false, | ||
documentSymbol: false, | ||
codeActions: false, | ||
}, | ||
data: undefined, | ||
}; | ||
formatFile.value = templateCodeGens.value ? { | ||
lsType: 'nonTs', | ||
fileName: fileName + '.__VLS_template.format.' + newLang, | ||
lang: newLang, | ||
content: templateCodeGens.value.formatCodeGen.getText(), | ||
capabilities: { | ||
diagnostics: false, | ||
foldingRanges: false, | ||
formatting: true, | ||
documentSymbol: true, | ||
codeActions: false, | ||
}, | ||
data: undefined, | ||
} : undefined; | ||
const sourceMap = new sourceMaps_1.Teleport(); | ||
for (const mapped of data.value.ctxMappings) { | ||
sourceMap.mappings.push(mapped); | ||
} | ||
teleport.value = sourceMap; | ||
} | ||
else { | ||
file.value = undefined; | ||
teleport.value = undefined; | ||
formatFile.value = undefined; | ||
} | ||
} | ||
} | ||
} | ||
@@ -390,0 +333,0 @@ exports.useSfcTemplateScript = useSfcTemplateScript; |
@@ -70,8 +70,4 @@ "use strict"; | ||
export type TemplateSlots<T> = T extends { __VLS_slots: infer S } ? S : {}; | ||
export type HasTemplateSlotsType<T> = T extends { __VLS_slots: infer _ } ? true : false; | ||
export type HasScriptSlotsType<T> = T extends new (...args: any) => { ${slots}?: infer _ } ? true : false; | ||
export type DefaultSlots<W, R> = HasTemplateSlotsType<W> extends true ? {} | ||
: HasScriptSlotsType<R> extends true ? {} | ||
: Record<string, any>; | ||
export type DefaultSlots<C> = HasScriptSlotsType<C> extends true ? {} : Record<string, any>; | ||
export type SlotsComponent<T> = T extends new (...args: any) => { ${slots}?: infer S } ? T : new (...args: any) => { ${slots}: {} }; | ||
@@ -90,3 +86,2 @@ export type ScriptSlots<T> = T extends { ${slots}?: infer S } | ||
export type ComponentContext<T> = T extends new (...args: any) => any ? InstanceType<T> : T extends (...args: any) => any ? ReturnType<T> : T; | ||
export type OptionsSetupReturns<T> = T extends { setup(): infer R } ? R : {}; | ||
export type OptionsProps<T> = T extends { props: infer R } ? R : {}; | ||
@@ -100,4 +95,2 @@ export type SelectComponent<T1, T2> = T1 extends (new (...args: any) => any) ? T1 : T1 extends ((...args: any) => any) ? T1 : T2; | ||
export type ExtractRawComponents<T> = { [K in keyof T]: ExtractRawComponent<T[K]> }; | ||
export type ExtractRawComponent<T> = T extends { __VLS_raw: infer C } ? C : T; | ||
export type ExtractEmit2<T> = | ||
@@ -104,0 +97,0 @@ T extends FunctionalComponent<infer _, infer E> ? SetupContext<E>['emit'] |
export declare const SearchTexts: { | ||
Context: string; | ||
Components: string; | ||
Props: string; | ||
SetupReturns: string; | ||
GlobalAttrs: string; | ||
@@ -7,0 +4,0 @@ PropsCompletion: (tag: string) => string; |
@@ -5,6 +5,3 @@ "use strict"; | ||
exports.SearchTexts = { | ||
Context: '/* __VLS_.SearchTexts.Context */', | ||
Components: '/* __VLS_.SearchTexts.Components */', | ||
Props: '/* __VLS_.SearchTexts.Props */', | ||
SetupReturns: '/* __VLS_.SearchTexts.SetupReturns */', | ||
GlobalAttrs: '/* __VLS_.SearchTexts.GlobalAttrs */', | ||
@@ -11,0 +8,0 @@ PropsCompletion: (tag) => `/* __VLS_.SearchTexts.Completion.Props.${tag} */`, |
@@ -44,3 +44,2 @@ import { TextRange } from '@volar/vue-code-gen'; | ||
content: string; | ||
lsType: 'template' | 'script' | 'nonTs'; | ||
capabilities: { | ||
@@ -55,3 +54,3 @@ diagnostics: boolean; | ||
} | ||
export declare function createVueFile(fileName: string, _content: string, _version: string, plugins: VueLanguagePlugin[], compilerOptions: VueCompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary'), baseCssModuleType: string, getCssClasses: (cssEmbeddeFile: EmbeddedFile) => Record<string, TextRange[]>): { | ||
export declare function createVueFile(fileName: string, _content: string, _version: string, plugins: VueLanguagePlugin[], compilerOptions: VueCompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary'), baseCssModuleType: string, getCssClasses: (cssEmbeddeFile: EmbeddedFile) => Record<string, TextRange[]>, tsLs: ts.LanguageService | undefined, tsHost: ts.LanguageServiceHost | undefined): { | ||
fileName: string; | ||
@@ -86,8 +85,6 @@ getContent: () => string; | ||
scriptUpdated: boolean; | ||
templateScriptUpdated: boolean; | ||
}; | ||
updateTemplateScript: (templateTsLs: ts.LanguageService, tempalteTsHost: ts.LanguageServiceHost) => boolean; | ||
getTemplateData: () => ITemplateScriptData; | ||
getScriptTsFile: () => EmbeddedFile<undefined>; | ||
getEmbeddedTemplate: () => Embedded | undefined; | ||
getTemplateScriptData: () => ITemplateScriptData; | ||
getDescriptor: () => Sfc; | ||
@@ -153,24 +150,15 @@ getScriptAst: () => _0.SourceFile | undefined; | ||
embedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
file: import("@vue/reactivity").Ref<EmbeddedFile<unknown> | undefined>; | ||
formatFile: import("@vue/reactivity").Ref<EmbeddedFile<unknown> | undefined>; | ||
file: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
formatFile: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
formatEmbedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
teleport: import("@vue/reactivity").Ref<Teleport | undefined>; | ||
inlineCssFile: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
inlineCssEmbedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
update: () => void; | ||
}; | ||
sfcEntryForTemplateLs: { | ||
file: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown>>; | ||
embedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
}; | ||
sfcScriptForScriptLs: { | ||
lang: import("@vue/reactivity").ComputedRef<string>; | ||
file: import("@vue/reactivity").ComputedRef<EmbeddedFile<undefined>>; | ||
fileTs: import("@vue/reactivity").ComputedRef<EmbeddedFile<unknown> | undefined>; | ||
embedded: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
embeddedTs: import("@vue/reactivity").ComputedRef<Embedded | undefined>; | ||
teleport: import("@vue/reactivity").ComputedRef<Teleport>; | ||
}; | ||
templateScriptData: ITemplateScriptData; | ||
}; | ||
}; |
@@ -11,3 +11,2 @@ "use strict"; | ||
const useSfcCustomBlocks_1 = require("./use/useSfcCustomBlocks"); | ||
const useSfcEntryForTemplateLs_1 = require("./use/useSfcEntryForTemplateLs"); | ||
const useSfcScript_1 = require("./use/useSfcScript"); | ||
@@ -22,3 +21,3 @@ const useSfcScriptGen_1 = require("./use/useSfcScriptGen"); | ||
; | ||
function createVueFile(fileName, _content, _version, plugins, compilerOptions, ts, baseCssModuleType, getCssClasses) { | ||
function createVueFile(fileName, _content, _version, plugins, compilerOptions, ts, baseCssModuleType, getCssClasses, tsLs, tsHost) { | ||
// refs | ||
@@ -39,11 +38,7 @@ const content = (0, reactivity_1.ref)(''); | ||
}; | ||
const templateScriptData = (0, reactivity_1.shallowReactive)({ | ||
let templateScriptData = { | ||
projectVersion: undefined, | ||
context: [], | ||
contextItems: [], | ||
components: [], | ||
componentItems: [], | ||
props: [], | ||
setupReturns: [], | ||
}); | ||
}; | ||
const cssVars = new WeakMap(); | ||
@@ -86,4 +81,3 @@ // computeds | ||
const sfcScriptForScriptLs = (0, useSfcScriptGen_1.useSfcScriptGen)('script', fileName, content, (0, reactivity_1.computed)(() => sfc.script), (0, reactivity_1.computed)(() => sfc.scriptSetup), (0, reactivity_1.computed)(() => scriptRanges.value), (0, reactivity_1.computed)(() => scriptSetupRanges.value), sfcTemplateCompileResult, (0, reactivity_1.computed)(() => sfcStyles.files.value), compilerOptions.experimentalCompatMode === 2, getCssVBindRanges); | ||
const sfcEntryForTemplateLs = (0, useSfcEntryForTemplateLs_1.useSfcEntryForTemplateLs)(fileName, (0, reactivity_1.computed)(() => sfc.script), (0, reactivity_1.computed)(() => sfc.scriptSetup), (0, reactivity_1.computed)(() => sfc.template), (0, reactivity_1.computed)(() => !!sfcScriptForTemplateLs.fileTs.value), compilerOptions.experimentalCompatMode === 2); | ||
const sfcTemplateScript = (0, useSfcTemplateScript_1.useSfcTemplateScript)(fileName, (0, reactivity_1.computed)(() => sfc.template), (0, reactivity_1.computed)(() => sfc.scriptSetup), (0, reactivity_1.computed)(() => scriptSetupRanges.value), (0, reactivity_1.computed)(() => sfc.styles), templateScriptData, sfcStyles.files, sfcStyles.embeddeds, sfcTemplateCompiled, sfcTemplateCompileResult, sfcStyles.files, sfcScriptForScriptLs.lang, compilerOptions, baseCssModuleType, getCssVBindRanges, getCssClasses); | ||
const sfcTemplateScript = (0, useSfcTemplateScript_1.useSfcTemplateScript)(ts, fileName, (0, reactivity_1.computed)(() => sfc.template), (0, reactivity_1.computed)(() => sfc.script), (0, reactivity_1.computed)(() => sfc.scriptSetup), (0, reactivity_1.computed)(() => scriptSetupRanges.value), (0, reactivity_1.computed)(() => sfc.styles), sfcStyles.files, sfcStyles.embeddeds, sfcTemplateCompiled, sfcTemplateCompileResult, sfcStyles.files, sfcScriptForScriptLs.lang, compilerOptions, baseCssModuleType, getCssVBindRanges, getCssClasses, compilerOptions.experimentalCompatMode === 2); | ||
const sfcRefSugarRanges = (0, reactivity_1.computed)(() => (sfcScriptSetup.ast.value ? { | ||
@@ -96,8 +90,2 @@ refs: (0, refSugarRanges_1.parseRefSugarDeclarationRanges)(ts, sfcScriptSetup.ast.value, ['$ref', '$computed', '$shallowRef', '$fromRefs']), | ||
const _all = []; | ||
if (sfcTemplateScript.file.value && sfcTemplateScript.teleport.value) { | ||
_all.push({ | ||
file: sfcTemplateScript.file.value, | ||
teleport: sfcTemplateScript.teleport.value, | ||
}); | ||
} | ||
if (sfcScriptForTemplateLs.file.value && sfcScriptForTemplateLs.teleport.value) { | ||
@@ -150,13 +138,5 @@ _all.push({ | ||
embeddeds.push({ | ||
self: sfcEntryForTemplateLs.embedded.value, | ||
embeddeds: [], | ||
}); | ||
embeddeds.push({ | ||
self: sfcScriptForTemplateLs.embedded.value, | ||
embeddeds: [], | ||
}); | ||
embeddeds.push({ | ||
self: sfcScriptForTemplateLs.embeddedTs.value, | ||
embeddeds: [], | ||
}); | ||
// styles | ||
@@ -201,6 +181,5 @@ for (const style of sfcStyles.embeddeds.value) { | ||
update: (0, untrack_1.untrack)(update), | ||
updateTemplateScript: (0, untrack_1.untrack)(updateTemplateScript), | ||
getTemplateData: (0, untrack_1.untrack)(getTemplateData), | ||
getScriptTsFile: (0, untrack_1.untrack)(() => sfcScriptForScriptLs.file.value), | ||
getEmbeddedTemplate: (0, untrack_1.untrack)(() => sfcTemplate.embedded.value), | ||
getTemplateScriptData: (0, untrack_1.untrack)(() => templateScriptData), | ||
getDescriptor: (0, untrack_1.untrack)(() => (0, reactivity_1.unref)(sfc)), | ||
@@ -221,5 +200,3 @@ getScriptAst: (0, untrack_1.untrack)(() => sfcScript.ast.value), | ||
sfcTemplateScript, | ||
sfcEntryForTemplateLs, | ||
sfcScriptForScriptLs, | ||
templateScriptData, | ||
}, | ||
@@ -238,3 +215,2 @@ }; | ||
updateCustomBlocks(parsedSfc.value.descriptor.customBlocks); | ||
sfcTemplateScript.update(); // TODO | ||
const scriptLang_2 = sfcScriptForScriptLs.file.value.lang; | ||
@@ -245,4 +221,3 @@ const scriptText_2 = sfcScriptForScriptLs.file.value.content; | ||
scriptContentUpdated: lastUpdated.script || lastUpdated.scriptSetup, | ||
scriptUpdated: scriptLang_1 !== scriptLang_2 || scriptText_1 !== scriptText_2, | ||
templateScriptUpdated: templateScriptContent !== templateScriptContent_2, | ||
scriptUpdated: scriptLang_1 !== scriptLang_2 || scriptText_1 !== scriptText_2 || templateScriptContent !== templateScriptContent_2, // TODO | ||
}; | ||
@@ -357,6 +332,10 @@ function updateTemplate(block) { | ||
} | ||
function updateTemplateScript(templateTsLs, tempalteTsHost) { | ||
const newVersion = tempalteTsHost.getProjectVersion?.(); | ||
function getTemplateData() { | ||
if (!tsHost) | ||
return templateScriptData; | ||
if (!tsLs) | ||
return templateScriptData; | ||
const newVersion = tsHost.getProjectVersion?.(); | ||
if (templateScriptData.projectVersion === newVersion) { | ||
return false; | ||
return templateScriptData; | ||
} | ||
@@ -367,37 +346,20 @@ templateScriptData.projectVersion = newVersion; | ||
}; | ||
const file = sfcEntryForTemplateLs.file.value; | ||
const context = file.content.indexOf(string_1.SearchTexts.Context) >= 0 ? templateTsLs.getCompletionsAtPosition(file.fileName, file.content.indexOf(string_1.SearchTexts.Context), options)?.entries ?? [] : []; | ||
let components = file.content.indexOf(string_1.SearchTexts.Components) >= 0 ? templateTsLs.getCompletionsAtPosition(file.fileName, file.content.indexOf(string_1.SearchTexts.Components), options)?.entries ?? [] : []; | ||
const props = file.content.indexOf(string_1.SearchTexts.Props) >= 0 ? templateTsLs.getCompletionsAtPosition(file.fileName, file.content.indexOf(string_1.SearchTexts.Props), options)?.entries ?? [] : []; | ||
const setupReturns = file.content.indexOf(string_1.SearchTexts.SetupReturns) >= 0 ? templateTsLs.getCompletionsAtPosition(file.fileName, file.content.indexOf(string_1.SearchTexts.SetupReturns), options)?.entries ?? [] : []; | ||
const file = sfcTemplateScript.file.value; | ||
let components = file && file.content.indexOf(string_1.SearchTexts.Components) >= 0 ? tsLs.getCompletionsAtPosition(file.fileName, file.content.indexOf(string_1.SearchTexts.Components), options)?.entries ?? [] : []; | ||
components = components.filter(entry => { | ||
return entry.name.indexOf('$') === -1 && !entry.name.startsWith('_'); | ||
}); | ||
const contextNames = context.map(entry => entry.name); | ||
const componentNames = components.map(entry => entry.name); | ||
const propNames = props.map(entry => entry.name); | ||
const setupReturnNames = setupReturns.map(entry => entry.name); | ||
let dirty = false; | ||
if (!eqSet(new Set(contextNames), new Set(templateScriptData.context))) { | ||
templateScriptData.context = contextNames; | ||
templateScriptData.contextItems = context; | ||
dirty = true; | ||
} | ||
if (!eqSet(new Set(componentNames), new Set(templateScriptData.components))) { | ||
templateScriptData.components = componentNames; | ||
templateScriptData.componentItems = components; | ||
dirty = true; | ||
} | ||
if (!eqSet(new Set(propNames), new Set(templateScriptData.props))) { | ||
templateScriptData.props = propNames; | ||
dirty = true; | ||
} | ||
if (!eqSet(new Set(setupReturnNames), new Set(templateScriptData.setupReturns))) { | ||
templateScriptData.setupReturns = setupReturnNames; | ||
dirty = true; | ||
} | ||
if (dirty) { | ||
sfcTemplateScript.update(); // TODO | ||
templateScriptData = { | ||
projectVersion: newVersion, | ||
components: componentNames, | ||
componentItems: components, | ||
}; | ||
} | ||
return dirty; | ||
return templateScriptData; | ||
} | ||
@@ -404,0 +366,0 @@ function getCssVBindRanges(embeddedFile) { |
@@ -14,14 +14,8 @@ import type { EmbeddedFileMappingData } from '@volar/vue-code-gen'; | ||
getAll: () => VueFile[]; | ||
getTeleport: (lsType: 'script' | 'template', fileName: string) => Teleport | undefined; | ||
getEmbeddeds: (lsType: 'script' | 'template' | 'nonTs') => Generator<{ | ||
getTeleport: (fileName: string) => Teleport | undefined; | ||
getEmbeddeds: () => Generator<{ | ||
vueFile: VueFile; | ||
embedded: Embedded; | ||
} | { | ||
vueFile: VueFile; | ||
embedded: Embedded; | ||
} | { | ||
vueFile: VueFile; | ||
embedded: Embedded; | ||
}, void, unknown>; | ||
fromEmbeddedLocation: (lsType: 'script' | 'template' | 'nonTs', fileName: string, start: number, end?: number | undefined, filter?: ((data: EmbeddedFileMappingData) => boolean) | undefined, sourceMapFilter?: ((sourceMap: EmbeddedFileSourceMap) => boolean) | undefined) => Generator<{ | ||
fromEmbeddedLocation: (fileName: string, start: number, end?: number | undefined, filter?: ((data: EmbeddedFileMappingData) => boolean) | undefined, sourceMapFilter?: ((sourceMap: EmbeddedFileSourceMap) => boolean) | undefined) => Generator<{ | ||
fileName: string; | ||
@@ -47,3 +41,3 @@ range: { | ||
fromEmbeddedFile: (file: EmbeddedFile) => VueFile | undefined; | ||
fromEmbeddedFileName: (lsType: 'script' | 'template' | 'nonTs', fileName: string) => { | ||
fromEmbeddedFileName: (fileName: string) => { | ||
vueFile: VueFile; | ||
@@ -50,0 +44,0 @@ embedded: Embedded; |
@@ -21,37 +21,21 @@ "use strict"; | ||
}); | ||
const sourceMapsByFileNameAndLsType = (0, reactivity_1.computed)(() => { | ||
const maps = { | ||
nonTs: new Map(), | ||
script: new Map(), | ||
template: new Map(), | ||
}; | ||
const sourceMapsByFileName = (0, reactivity_1.computed)(() => { | ||
const map = new Map(); | ||
for (const sourceFile of all.value) { | ||
for (const embedded of sourceFile.refs.allEmbeddeds.value) { | ||
maps[embedded.file.lsType].set(embedded.file.fileName.toLowerCase(), { vueFile: sourceFile, embedded }); | ||
map.set(embedded.file.fileName.toLowerCase(), { vueFile: sourceFile, embedded }); | ||
} | ||
} | ||
return maps; | ||
return map; | ||
}); | ||
const teleports = { | ||
template: (0, reactivity_1.computed)(() => { | ||
const map = new Map(); | ||
for (const key in vueFiles) { | ||
const sourceFile = vueFiles[key]; | ||
for (const { file, teleport } of sourceFile.refs.teleports.value) { | ||
map.set(file.fileName.toLowerCase(), teleport); | ||
} | ||
const teleports = (0, reactivity_1.computed)(() => { | ||
const map = new Map(); | ||
for (const key in vueFiles) { | ||
const sourceFile = vueFiles[key]; | ||
for (const { file, teleport } of sourceFile.refs.teleports.value) { | ||
map.set(file.fileName.toLowerCase(), teleport); | ||
} | ||
return map; | ||
}), | ||
script: (0, reactivity_1.computed)(() => { | ||
const map = new Map(); | ||
for (const key in vueFiles) { | ||
const sourceFile = vueFiles[key]; | ||
const embeddedFile = sourceFile.refs.sfcScriptForScriptLs.file.value; | ||
const sourceMap = sourceFile.refs.sfcScriptForScriptLs.teleport.value; | ||
map.set(embeddedFile.fileName.toLowerCase(), sourceMap); | ||
} | ||
return map; | ||
}), | ||
}; | ||
} | ||
return map; | ||
}); | ||
const dirs = (0, reactivity_1.computed)(() => [...new Set(fileNames.value.map(path.dirname))]); | ||
@@ -66,9 +50,9 @@ return { | ||
getAll: (0, untrack_1.untrack)(() => all.value), | ||
getTeleport: (0, untrack_1.untrack)((lsType, fileName) => teleports[lsType].value.get(fileName.toLowerCase())), | ||
getEmbeddeds: (0, untrack_1.untrack)(function* (lsType) { | ||
for (const sourceMap of sourceMapsByFileNameAndLsType.value[lsType]) { | ||
getTeleport: (0, untrack_1.untrack)((fileName) => teleports.value.get(fileName.toLowerCase())), | ||
getEmbeddeds: (0, untrack_1.untrack)(function* () { | ||
for (const sourceMap of sourceMapsByFileName.value) { | ||
yield sourceMap[1]; | ||
} | ||
}), | ||
fromEmbeddedLocation: (0, untrack_1.untrack)(function* (lsType, fileName, start, end, filter, sourceMapFilter) { | ||
fromEmbeddedLocation: (0, untrack_1.untrack)(function* (fileName, start, end, filter, sourceMapFilter) { | ||
if (fileName.endsWith(`/${localTypes.typesFileName}`)) | ||
@@ -78,3 +62,3 @@ return; | ||
end = start; | ||
const mapped = sourceMapsByFileNameAndLsType.value[lsType].get(fileName.toLowerCase()); | ||
const mapped = sourceMapsByFileName.value.get(fileName.toLowerCase()); | ||
if (mapped) { | ||
@@ -105,4 +89,4 @@ if (sourceMapFilter && !sourceMapFilter(mapped.embedded.sourceMap)) | ||
}), | ||
fromEmbeddedFileName: (0, untrack_1.untrack)(function (lsType, fileName) { | ||
return sourceMapsByFileNameAndLsType.value[lsType].get(fileName.toLowerCase()); | ||
fromEmbeddedFileName: (0, untrack_1.untrack)(function (fileName) { | ||
return sourceMapsByFileName.value.get(fileName.toLowerCase()); | ||
}), | ||
@@ -109,0 +93,0 @@ }; |
{ | ||
"name": "@volar/vue-typescript", | ||
"version": "0.33.9", | ||
"version": "0.34.0", | ||
"main": "out/index.js", | ||
@@ -19,8 +19,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"@volar/code-gen": "0.33.9", | ||
"@volar/pug-language-service": "0.33.9", | ||
"@volar/source-map": "0.33.9", | ||
"@volar/vue-code-gen": "0.33.9", | ||
"@vue/compiler-sfc": "^3.2.27", | ||
"@vue/reactivity": "^3.2.27" | ||
"@volar/code-gen": "0.34.0", | ||
"@volar/pug-language-service": "0.34.0", | ||
"@volar/source-map": "0.34.0", | ||
"@volar/vue-code-gen": "0.34.0", | ||
"@vue/compiler-sfc": "^3.2.31", | ||
"@vue/reactivity": "^3.2.31" | ||
}, | ||
@@ -30,3 +30,3 @@ "browser": { | ||
}, | ||
"gitHead": "9031e662fe238df7ec385ddde6a91e1e363a4af4" | ||
"gitHead": "1a70119c77eca70c56d5a99da0322c087a6cb33b" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118290
2589
+ Added@volar/code-gen@0.34.0(transitive)
+ Added@volar/pug-language-service@0.34.0(transitive)
+ Added@volar/shared@0.34.0(transitive)
+ Added@volar/source-map@0.34.0(transitive)
+ Added@volar/transforms@0.34.0(transitive)
+ Added@volar/vue-code-gen@0.34.0(transitive)
- Removed@volar/code-gen@0.33.9(transitive)
- Removed@volar/pug-language-service@0.33.9(transitive)
- Removed@volar/shared@0.33.9(transitive)
- Removed@volar/source-map@0.33.9(transitive)
- Removed@volar/transforms@0.33.9(transitive)
- Removed@volar/vue-code-gen@0.33.9(transitive)
- Removedvscode-jsonrpc@8.2.1(transitive)
Updated@volar/code-gen@0.34.0
Updated@volar/source-map@0.34.0
Updated@volar/vue-code-gen@0.34.0
Updated@vue/compiler-sfc@^3.2.31
Updated@vue/reactivity@^3.2.31