@volar/typescript
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -132,2 +132,5 @@ "use strict"; | ||
snapshotSnapshot = ts.ScriptSnapshot.fromString(patchedText); | ||
if (sourceFile.generated.languagePlugin.typescript?.getExtraScripts) { | ||
console.warn('getExtraScripts() is not available in this use case.'); | ||
} | ||
} | ||
@@ -134,0 +137,0 @@ } |
@@ -67,4 +67,5 @@ "use strict"; | ||
let scriptKind = ts.ScriptKind.TS; | ||
if (sourceFile.generated) { | ||
const script = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code); | ||
if (sourceFile.generated?.languagePlugin.typescript) { | ||
const { getScript, getExtraScripts } = sourceFile.generated.languagePlugin.typescript; | ||
const script = getScript(sourceFile.generated.code); | ||
if (script) { | ||
@@ -74,2 +75,5 @@ scriptKind = script.scriptKind; | ||
} | ||
if (getExtraScripts) { | ||
console.warn('getExtraScripts() is not available in this use case.'); | ||
} | ||
} | ||
@@ -97,2 +101,3 @@ sourceFile2 = ts.createSourceFile(fileName, patchedText, 99, true, scriptKind); | ||
(0, decorateProgram_1.decorateProgram)(files, program); | ||
program.__volar__ = { files }; | ||
return program; | ||
@@ -99,0 +104,0 @@ function resolveModuleName(name, containingFile, options, redirectedReference) { |
import type { FileRegistry } from '@volar/language-core'; | ||
export declare function notEmpty<T>(value: T | null | undefined): value is T; | ||
export declare function getVirtualFileAndMap(files: FileRegistry, fileName: string): readonly [{ | ||
code: import("@volar/language-core").VirtualCode<string>; | ||
extension: string; | ||
scriptKind: import("typescript").ScriptKind; | ||
}, import("@volar/language-core").SourceFile, import("@volar/language-core").SourceMap<import("@volar/language-core").CodeInformation>] | readonly [undefined, undefined, undefined]; | ||
export declare function getVirtualFileAndMap(files: FileRegistry, fileName: string): readonly [import("@volar/language-core").ServiceScript, import("@volar/language-core").SourceFile, import("@volar/language-core").SourceMap<import("@volar/language-core").CodeInformation>] | readonly [undefined, undefined, undefined]; |
@@ -37,3 +37,3 @@ "use strict"; | ||
}); | ||
let languageServiceHost = createLanguageServiceHost(); | ||
let { languageServiceHost, getExtraScript } = createLanguageServiceHost(); | ||
for (const language of languagePlugins) { | ||
@@ -97,2 +97,3 @@ if (language.typescript?.resolveLanguageServiceHost) { | ||
languageServiceHost, | ||
getExtraScript, | ||
}, | ||
@@ -104,2 +105,3 @@ }; | ||
let tsFileRegistry = new language_core_1.FileMap(sys.useCaseSensitiveFileNames); | ||
let extraScriptRegistry = new language_core_1.FileMap(sys.useCaseSensitiveFileNames); | ||
let lastTsVirtualFileSnapshots = new Set(); | ||
@@ -162,10 +164,14 @@ let lastOtherVirtualFileSnapshots = new Set(); | ||
getProjectVersion() { | ||
syncProject(); | ||
sync(); | ||
return tsProjectVersion + ('version' in sys ? `:${sys.version}` : ''); | ||
}, | ||
getScriptFileNames() { | ||
syncProject(); | ||
sync(); | ||
return [...tsFileRegistry.keys()]; | ||
}, | ||
getScriptKind(fileName) { | ||
sync(); | ||
if (extraScriptRegistry.has(fileName)) { | ||
return extraScriptRegistry.get(fileName).scriptKind; | ||
} | ||
const sourceFile = files.get(fileNameToFileId(fileName)); | ||
@@ -200,4 +206,11 @@ if (sourceFile?.generated) { | ||
}; | ||
return languageServiceHost; | ||
function syncProject() { | ||
return { | ||
languageServiceHost, | ||
getExtraScript, | ||
}; | ||
function getExtraScript(fileName) { | ||
sync(); | ||
return extraScriptRegistry.get(fileName); | ||
} | ||
function sync() { | ||
const newProjectVersion = projectHost.getProjectVersion?.(); | ||
@@ -209,2 +222,3 @@ const shouldUpdate = newProjectVersion === undefined || newProjectVersion !== lastProjectVersion; | ||
lastProjectVersion = newProjectVersion; | ||
extraScriptRegistry.clear(); | ||
const newTsVirtualFileSnapshots = new Set(); | ||
@@ -219,7 +233,12 @@ const newOtherVirtualFileSnapshots = new Set(); | ||
newTsVirtualFileSnapshots.add(script.code.snapshot); | ||
tsFileNamesSet.add(fileName); // virtual .ts | ||
tsFileNamesSet.add(fileName); | ||
} | ||
for (const file of (0, language_core_2.forEachEmbeddedCode)(sourceFile.generated.code)) { | ||
newOtherVirtualFileSnapshots.add(file.snapshot); | ||
for (const extraScript of sourceFile.generated.languagePlugin.typescript?.getExtraScripts?.(fileName, sourceFile.generated.code) ?? []) { | ||
newTsVirtualFileSnapshots.add(extraScript.code.snapshot); | ||
tsFileNamesSet.add(extraScript.fileName); | ||
extraScriptRegistry.set(extraScript.fileName, extraScript); | ||
} | ||
for (const code of (0, language_core_2.forEachEmbeddedCode)(sourceFile.generated.code)) { | ||
newOtherVirtualFileSnapshots.add(code.snapshot); | ||
} | ||
} | ||
@@ -245,2 +264,6 @@ else { | ||
function getScriptSnapshot(fileName) { | ||
sync(); | ||
if (extraScriptRegistry.has(fileName)) { | ||
return extraScriptRegistry.get(fileName).code.snapshot; | ||
} | ||
const sourceFile = files.get(fileNameToFileId(fileName)); | ||
@@ -258,2 +281,3 @@ if (sourceFile?.generated) { | ||
function getScriptVersion(fileName) { | ||
sync(); | ||
if (!scriptVersions.has(fileName)) { | ||
@@ -263,2 +287,9 @@ scriptVersions.set(fileName, { lastVersion: 0, map: new WeakMap() }); | ||
const version = scriptVersions.get(fileName); | ||
if (extraScriptRegistry.has(fileName)) { | ||
const snapshot = extraScriptRegistry.get(fileName).code.snapshot; | ||
if (!version.map.has(snapshot)) { | ||
version.map.set(snapshot, version.lastVersion++); | ||
} | ||
return version.map.get(snapshot).toString(); | ||
} | ||
const sourceFile = files.get(fileNameToFileId(fileName)); | ||
@@ -265,0 +296,0 @@ if (sourceFile?.generated) { |
@@ -21,3 +21,3 @@ "use strict"; | ||
tsc = replace(tsc, /function createProgram\(.+\) {/, s => `var createProgram = require(${JSON.stringify(proxyApiPath)}).proxyCreateProgram(` | ||
+ `new Proxy({}, { get(_target, p, _receiver) {return eval(p); } } ), ` | ||
+ `new Proxy({}, { get(_target, p, _receiver) { return eval(p); } } ), ` | ||
+ `_createProgram, ` | ||
@@ -24,0 +24,0 @@ + `[${extsText}], ` |
{ | ||
"name": "@volar/typescript", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "2.0.0", | ||
"@volar/language-core": "2.0.1", | ||
"path-browserify": "^1.0.1" | ||
@@ -22,5 +22,5 @@ }, | ||
"@types/path-browserify": "latest", | ||
"@volar/language-service": "2.0.0" | ||
"@volar/language-service": "2.0.1" | ||
}, | ||
"gitHead": "95217136d2727bb7304443d91cfde3dbe711369c" | ||
"gitHead": "b1fbf6eed522624ccccfb17a8999edfbc1d8d9bb" | ||
} |
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
162218
40
3542
+ Added@volar/language-core@2.0.1(transitive)
+ Added@volar/source-map@2.0.1(transitive)
- Removed@volar/language-core@2.0.0(transitive)
- Removed@volar/source-map@2.0.0(transitive)
Updated@volar/language-core@2.0.1