@volar/typescript
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -296,3 +296,3 @@ "use strict"; | ||
else { | ||
return getEncodedSemanticClassifications(fileName, span); | ||
return getEncodedSemanticClassifications(fileName, span, format); | ||
} | ||
@@ -299,0 +299,0 @@ }; |
@@ -5,5 +5,7 @@ "use strict"; | ||
const language_core_1 = require("@volar/language-core"); | ||
const resolveModuleName_1 = require("../resolveModuleName"); | ||
function decorateLanguageServiceHost(virtualFiles, languageServiceHost, ts) { | ||
let extraProjectVersion = 0; | ||
const exts = virtualFiles.languagePlugins | ||
const { languagePlugins } = virtualFiles; | ||
const exts = languagePlugins | ||
.map(plugin => plugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? []) | ||
@@ -31,30 +33,25 @@ .flat(); | ||
} | ||
if (resolveModuleNameLiterals) { | ||
languageServiceHost.resolveModuleNameLiterals = (moduleNames, containingFile, redirectedReference, options, ...rest) => { | ||
const resolvedModules = resolveModuleNameLiterals(moduleNames, containingFile, redirectedReference, options, ...rest); | ||
return moduleNames.map((name, i) => { | ||
if (exts.some(ext => name.text.endsWith(ext))) { | ||
const resolved = resolveModuleName(name.text, containingFile, options, redirectedReference); | ||
if (resolved.resolvedModule) { | ||
return resolved; | ||
} | ||
} | ||
return resolvedModules[i]; | ||
}); | ||
}; | ||
if (languagePlugins.some(language => language.typescript?.extraFileExtensions.length)) { | ||
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => virtualFiles.get(fileName)); | ||
if (resolveModuleNameLiterals) { | ||
languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, ...rest) => { | ||
return [ | ||
...resolveModuleNameLiterals(moduleLiterals.filter(name => !exts.some(ext => name.text.endsWith(ext))), containingFile, redirectedReference, options, ...rest), | ||
...moduleLiterals | ||
.filter(name => exts.some(ext => name.text.endsWith(ext))) | ||
.map(name => resolveModuleName(name.text, containingFile, options, undefined, redirectedReference)), | ||
]; | ||
}; | ||
} | ||
if (resolveModuleNames) { | ||
languageServiceHost.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile) => { | ||
return [ | ||
...resolveModuleNames(moduleNames.filter(name => !exts.some(ext => name.endsWith(ext))), containingFile, reusedNames, redirectedReference, options, containingSourceFile), | ||
...moduleNames | ||
.filter(name => exts.some(ext => name.endsWith(ext))) | ||
.map(moduleName => resolveModuleName(moduleName, containingFile, options, undefined, redirectedReference).resolvedModule), | ||
]; | ||
}; | ||
} | ||
} | ||
else if (resolveModuleNames) { | ||
languageServiceHost.resolveModuleNames = (moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile) => { | ||
const resolvedModules = resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference, options, containingSourceFile); | ||
return moduleNames.map((name, i) => { | ||
if (exts.some(ext => name.endsWith(ext))) { | ||
const resolved = resolveModuleName(name, containingFile, options, redirectedReference); | ||
if (resolved.resolvedModule) { | ||
return resolved.resolvedModule; | ||
} | ||
} | ||
return resolvedModules[i]; | ||
}); | ||
}; | ||
} | ||
if (getProjectVersion) { | ||
@@ -85,31 +82,2 @@ languageServiceHost.getProjectVersion = () => { | ||
} | ||
function resolveModuleName(name, containingFile, options, redirectedReference) { | ||
const resolved = ts.resolveModuleName(name, containingFile, options, { | ||
readFile(fileName) { | ||
return languageServiceHost.readFile(fileName); | ||
}, | ||
fileExists(fileName) { | ||
if (exts.some(ext => fileName.endsWith(ext + '.d.ts'))) { | ||
return fileExists(fileName.slice(0, -'.d.ts'.length)); | ||
} | ||
return languageServiceHost.fileExists(fileName); | ||
}, | ||
}, undefined, redirectedReference); | ||
if (resolved.resolvedModule) { | ||
resolved.resolvedModule.resolvedFileName = resolved.resolvedModule.resolvedFileName.slice(0, -'.d.ts'.length); | ||
const script = updateScript(resolved.resolvedModule.resolvedFileName); | ||
if (script) { | ||
resolved.resolvedModule.extension = script.extension; | ||
} | ||
} | ||
return resolved; | ||
} | ||
// fix https://github.com/vuejs/language-tools/issues/3332 | ||
function fileExists(fileName) { | ||
if (languageServiceHost.fileExists(fileName)) { | ||
const fileSize = ts.sys.getFileSize?.(fileName) ?? languageServiceHost.readFile(fileName)?.length ?? 0; | ||
return fileSize < 4 * 1024 * 1024; | ||
} | ||
return false; | ||
} | ||
function updateScript(fileName) { | ||
@@ -116,0 +84,0 @@ const version = languageServiceHost.getScriptVersion(fileName); |
@@ -7,2 +7,3 @@ "use strict"; | ||
const path = require("path-browserify"); | ||
const resolveModuleName_1 = require("../resolveModuleName"); | ||
const scriptVersions = new Map(); | ||
@@ -47,2 +48,3 @@ const fsFileSnapshots = new Map(); | ||
const moduleCache = ts.createModuleResolutionCache(languageServiceHost.getCurrentDirectory(), languageServiceHost.useCaseSensitiveFileNames ? s => s : s => s.toLowerCase(), languageServiceHost.getCompilationSettings()); | ||
const resolveModuleName = (0, resolveModuleName_1.createResolveModuleName)(ts, languageServiceHost, languagePlugins, fileName => files.get(fileNameToFileId(fileName))); | ||
let lastSysVersion = 'version' in sys ? sys.version : undefined; | ||
@@ -55,40 +57,14 @@ languageServiceHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, sourceFile) => { | ||
return moduleLiterals.map(moduleLiteral => { | ||
let moduleName = moduleLiteral.text; | ||
let extraFileExtension; | ||
let isPatchResult = false; | ||
for (const language of languagePlugins) { | ||
extraFileExtension = language.typescript?.extraFileExtensions.find(ext => moduleName.endsWith('.' + ext.extension))?.extension; | ||
if (extraFileExtension) { | ||
break; | ||
} | ||
} | ||
const result = ts.resolveModuleName(moduleName, containingFile, options, { | ||
...languageServiceHost, | ||
fileExists(fileName) { | ||
if (extraFileExtension && fileName.endsWith(`.d.${extraFileExtension}.ts`)) { | ||
const patchResult = languageServiceHost.fileExists(fileName.slice(0, -`.d.${extraFileExtension}.ts`.length) | ||
+ `.${extraFileExtension}`); | ||
if (patchResult) { | ||
isPatchResult = true; | ||
return true; | ||
} | ||
} | ||
return sys.fileExists(fileName); | ||
}, | ||
}, moduleCache, redirectedReference, sourceFile.impliedNodeFormat); | ||
if (isPatchResult && result.resolvedModule) { | ||
result.resolvedModule.resolvedFileName = result.resolvedModule.resolvedFileName | ||
.slice(0, -`.d.${extraFileExtension}.ts`.length) | ||
+ `.${extraFileExtension}`; | ||
const sourceFile = files.get(fileNameToFileId(result.resolvedModule.resolvedFileName)); | ||
if (sourceFile?.generated) { | ||
const tsCode = sourceFile.generated.languagePlugin.typescript?.getScript(sourceFile.generated.code); | ||
if (tsCode) { | ||
result.resolvedModule.extension = tsCode.extension; | ||
} | ||
} | ||
} | ||
return result; | ||
return resolveModuleName(moduleLiteral.text, containingFile, options, moduleCache, redirectedReference, sourceFile.impliedNodeFormat); | ||
}); | ||
}; | ||
languageServiceHost.resolveModuleNames = (moduleNames, containingFile, _reusedNames, redirectedReference, options) => { | ||
if ('version' in sys && lastSysVersion !== sys.version) { | ||
lastSysVersion = sys.version; | ||
moduleCache.clear(); | ||
} | ||
return moduleNames.map(moduleName => { | ||
return resolveModuleName(moduleName, containingFile, options, moduleCache, redirectedReference).resolvedModule; | ||
}); | ||
}; | ||
} | ||
@@ -95,0 +71,0 @@ return { |
{ | ||
"name": "@volar/typescript", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "2.0.3", | ||
"@volar/language-core": "2.0.4", | ||
"path-browserify": "^1.0.1" | ||
@@ -22,5 +22,5 @@ }, | ||
"@types/path-browserify": "latest", | ||
"@volar/language-service": "2.0.3" | ||
"@volar/language-service": "2.0.4" | ||
}, | ||
"gitHead": "d8a6dc056d37779ff6486f545f45bc57b22c02e4" | ||
"gitHead": "b3dc544424c95f8b72e832fbaa0f85a34442389b" | ||
} |
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
164650
42
3572
+ Added@volar/language-core@2.0.4(transitive)
+ Added@volar/source-map@2.0.4(transitive)
- Removed@volar/language-core@2.0.3(transitive)
- Removed@volar/source-map@2.0.3(transitive)
Updated@volar/language-core@2.0.4