@volar/typescript
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -1,4 +0,4 @@ | ||
import { type FileRegistry } from '@volar/language-core'; | ||
import type { FileRegistry } from '@volar/language-core'; | ||
import type * as ts from 'typescript'; | ||
export declare function decorateLanguageServiceHost(virtualFiles: FileRegistry, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript')): void; | ||
export declare function decorateLanguageServiceHost(files: FileRegistry, languageServiceHost: ts.LanguageServiceHost, ts: typeof import('typescript')): void; | ||
export declare function searchExternalFiles(ts: typeof import('typescript'), project: ts.server.Project, exts: string[]): string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.searchExternalFiles = exports.decorateLanguageServiceHost = void 0; | ||
const language_core_1 = require("@volar/language-core"); | ||
const resolveModuleName_1 = require("../resolveModuleName"); | ||
function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts) { | ||
function decorateLanguageServiceHost(files, languageServiceHost, ts) { | ||
let extraProjectVersion = 0; | ||
const { languagePlugins } = virtualFiles; | ||
const { languagePlugins } = files; | ||
const exts = languagePlugins | ||
@@ -18,2 +17,3 @@ .map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? []) | ||
const getScriptSnapshot = languageServiceHost.getScriptSnapshot.bind(languageServiceHost); | ||
const getScriptVersion = languageServiceHost.getScriptVersion.bind(languageServiceHost); | ||
const getScriptKind = languageServiceHost.getScriptKind?.bind(languageServiceHost); | ||
@@ -34,3 +34,3 @@ // path completion | ||
if (languagePlugins.some(language => language.typescript?.extraFileExtensions.length)) { | ||
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => virtualFiles.get(fileName)); | ||
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => files.get(fileName)); | ||
if (resolveModuleNameLiterals) { | ||
@@ -69,2 +69,9 @@ languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, ...rest) => { | ||
}; | ||
languageServiceHost.getScriptVersion = fileName => { | ||
if (exts.some(ext => fileName.endsWith(ext))) { | ||
updateScript(fileName); | ||
return scripts.get(fileName)?.version.toString() ?? ''; | ||
} | ||
return getScriptVersion(fileName); | ||
}; | ||
if (getScriptKind) { | ||
@@ -84,36 +91,48 @@ languageServiceHost.getScriptKind = fileName => { | ||
function updateScript(fileName) { | ||
const version = languageServiceHost.getScriptVersion(fileName); | ||
if (version !== scripts.get(fileName)?.version) { | ||
let extension = '.ts'; | ||
let snapshotSnapshot; | ||
let scriptKind = ts.ScriptKind.TS; | ||
const snapshot = getScriptSnapshot(fileName); | ||
if (snapshot) { | ||
const version = getProjectVersion?.(); | ||
const cache = scripts.get(fileName); | ||
if (version === undefined || version !== cache?.projectVersion) { | ||
const file = files.get(fileName); | ||
const script = file?.generated?.languagePlugin.typescript?.getScript(file.generated.code); | ||
if (script?.code.snapshot !== cache?.snapshot) { | ||
let extension = '.ts'; | ||
let snapshotSnapshot; | ||
let scriptKind = ts.ScriptKind.TS; | ||
extraProjectVersion++; | ||
const sourceFile = virtualFiles.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot); | ||
if (sourceFile.generated) { | ||
const text = snapshot.getText(0, snapshot.getLength()); | ||
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n'); | ||
const script = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code); | ||
if (script) { | ||
if (script) { | ||
if (file?.generated) { | ||
const text = file.snapshot.getText(0, file.snapshot.getLength()); | ||
let patchedText = text.split('\n').map(line => ' '.repeat(line.length)).join('\n'); | ||
extension = script.extension; | ||
scriptKind = script.scriptKind; | ||
patchedText += script.code.snapshot.getText(0, script.code.snapshot.getLength()); | ||
snapshotSnapshot = ts.ScriptSnapshot.fromString(patchedText); | ||
if (file.generated.languagePlugin.typescript?.getExtraScripts) { | ||
console.warn('getExtraScripts() is not available in this use case.'); | ||
} | ||
} | ||
snapshotSnapshot = ts.ScriptSnapshot.fromString(patchedText); | ||
if (sourceFile.generated.languagePlugin.typescript?.getExtraScripts) { | ||
console.warn('getExtraScripts() is not available in this use case.'); | ||
} | ||
} | ||
else if (files.get(fileName)) { | ||
files.delete(fileName); | ||
} | ||
if (!cache) { | ||
scripts.set(fileName, { | ||
projectVersion: version, | ||
version: 0, | ||
extension, | ||
snapshot: snapshotSnapshot, | ||
kind: scriptKind, | ||
}); | ||
} | ||
else { | ||
cache.projectVersion = version; | ||
cache.version++; | ||
cache.extension = extension; | ||
cache.snapshot = snapshotSnapshot; | ||
cache.kind = scriptKind; | ||
} | ||
} | ||
else if (virtualFiles.get(fileName)) { | ||
extraProjectVersion++; | ||
virtualFiles.delete(fileName); | ||
else if (cache) { | ||
cache.projectVersion = version; | ||
} | ||
scripts.set(fileName, { | ||
version, | ||
extension, | ||
snapshot: snapshotSnapshot, | ||
kind: scriptKind, | ||
}); | ||
} | ||
@@ -120,0 +139,0 @@ return scripts.get(fileName); |
{ | ||
"name": "@volar/typescript", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "2.1.0", | ||
"@volar/language-core": "2.1.1", | ||
"path-browserify": "^1.0.1" | ||
@@ -22,5 +22,5 @@ }, | ||
"@types/path-browserify": "latest", | ||
"@volar/language-service": "2.1.0" | ||
"@volar/language-service": "2.1.1" | ||
}, | ||
"gitHead": "09e1792f0adafb02caf89a5a45a6fcaaf3177808" | ||
"gitHead": "e56916097fe7be2920aab6592a564a8e2ceafd14" | ||
} |
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
165260
3590
107
+ Added@volar/language-core@2.1.1(transitive)
+ Added@volar/source-map@2.1.1(transitive)
- Removed@volar/language-core@2.1.0(transitive)
- Removed@volar/source-map@2.1.0(transitive)
Updated@volar/language-core@2.1.1