@volar/typescript
Advanced tools
Comparing version 2.2.0-alpha.9 to 2.2.0-alpha.10
@@ -32,3 +32,3 @@ "use strict"; | ||
// methods | ||
const { findReferences, findRenameLocations, getCompletionEntryDetails, getCompletionsAtPosition, getDefinitionAndBoundSpan, getDefinitionAtPosition, getFileReferences, getFormattingEditsForDocument, getFormattingEditsForRange, getFormattingEditsAfterKeystroke, getImplementationAtPosition, getLinkedEditingRangeAtPosition, getQuickInfoAtPosition, getReferencesAtPosition, getSemanticDiagnostics, getSyntacticDiagnostics, getSuggestionDiagnostics, getTypeDefinitionAtPosition, getEncodedSemanticClassifications, getDocumentHighlights, getApplicableRefactors, getEditsForFileRename, getEditsForRefactor, getRenameInfo, getCodeFixesAtPosition, prepareCallHierarchy, provideCallHierarchyIncomingCalls, provideCallHierarchyOutgoingCalls, provideInlayHints, organizeImports, } = languageService; | ||
const { findReferences, findRenameLocations, getCompletionEntryDetails, getCompletionsAtPosition, getDefinitionAndBoundSpan, getDefinitionAtPosition, getFileReferences, getFormattingEditsForDocument, getFormattingEditsForRange, getFormattingEditsAfterKeystroke, getImplementationAtPosition, getLinkedEditingRangeAtPosition, getQuickInfoAtPosition, getSignatureHelpItems, getReferencesAtPosition, getSemanticDiagnostics, getSyntacticDiagnostics, getSuggestionDiagnostics, getTypeDefinitionAtPosition, getEncodedSemanticClassifications, getDocumentHighlights, getApplicableRefactors, getEditsForFileRename, getEditsForRefactor, getRenameInfo, getCodeFixesAtPosition, prepareCallHierarchy, provideCallHierarchyIncomingCalls, provideCallHierarchyOutgoingCalls, provideInlayHints, organizeImports, } = languageService; | ||
languageService.getFormattingEditsForDocument = (fileName, options) => { | ||
@@ -204,2 +204,23 @@ const [serviceScript, sourceScript, map] = (0, utils_1.getServiceScript)(language, fileName); | ||
}; | ||
languageService.getSignatureHelpItems = (fileName, position, options) => { | ||
const [serviceScript, sourceScript, map] = (0, utils_1.getServiceScript)(language, fileName); | ||
if (serviceScript) { | ||
const generatePosition = (0, transform_1.toGeneratedOffset)(sourceScript, map, position, language_core_1.isSignatureHelpEnabled); | ||
if (generatePosition !== undefined) { | ||
const result = getSignatureHelpItems(fileName, generatePosition, options); | ||
if (result) { | ||
const applicableSpan = (0, transform_1.transformTextSpan)(sourceScript, map, result.applicableSpan, language_core_1.isSignatureHelpEnabled); | ||
if (applicableSpan) { | ||
return { | ||
...result, | ||
applicableSpan, | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
else { | ||
return getSignatureHelpItems(fileName, position, options); | ||
} | ||
}; | ||
languageService.getDocumentHighlights = (fileName, position, filesToSearch) => { | ||
@@ -361,3 +382,3 @@ const unresolved = linkedCodeFeatureWorker(fileName, position, language_core_1.isHighlightEnabled, position => getDocumentHighlights(fileName, position, filesToSearch), function* (result) { | ||
return getSyntacticDiagnostics(fileName) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, false)) | ||
.filter(utils_1.notEmpty); | ||
@@ -367,3 +388,3 @@ }; | ||
return getSemanticDiagnostics(fileName) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, false)) | ||
.filter(utils_1.notEmpty); | ||
@@ -373,3 +394,3 @@ }; | ||
return getSuggestionDiagnostics(fileName) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, false)) | ||
.filter(utils_1.notEmpty); | ||
@@ -411,14 +432,11 @@ }; | ||
.map(symbol => { | ||
const definition = (0, transform_1.transformDocumentSpan)(language, symbol.definition, language_core_1.isDefinitionEnabled); | ||
if (definition) { | ||
return { | ||
definition, | ||
references: symbol.references | ||
.map(r => (0, transform_1.transformDocumentSpan)(language, r, language_core_1.isReferencesEnabled)) | ||
.filter(utils_1.notEmpty), | ||
}; | ||
} | ||
}) | ||
.filter(utils_1.notEmpty); | ||
return (0, dedupe_1.dedupeReferencedSymbols)(resolved); | ||
const definition = (0, transform_1.transformDocumentSpan)(language, symbol.definition, language_core_1.isDefinitionEnabled, true); | ||
return { | ||
definition, | ||
references: symbol.references | ||
.map(r => (0, transform_1.transformDocumentSpan)(language, r, language_core_1.isReferencesEnabled)) | ||
.filter(utils_1.notEmpty), | ||
}; | ||
}); | ||
return resolved; | ||
}; | ||
@@ -596,3 +614,3 @@ languageService.getDefinitionAtPosition = (fileName, position) => { | ||
function linkedCodeFeatureWorker(fileName, position, filter, worker, getLinkedCodes) { | ||
let results = []; | ||
const results = []; | ||
const processedFilePositions = new Set(); | ||
@@ -620,3 +638,3 @@ const [serviceScript, sourceScript, map] = (0, utils_1.getServiceScript)(language, fileName); | ||
} | ||
results = results.concat(result); | ||
results.push(result); | ||
for (const ref of getLinkedCodes(result)) { | ||
@@ -623,0 +641,0 @@ processedFilePositions.add(ref[0] + ':' + ref[1]); |
@@ -10,2 +10,3 @@ "use strict"; | ||
const scripts = new Map(); | ||
const crashFileNames = new Set(); | ||
const readDirectory = languageServiceHost.readDirectory?.bind(languageServiceHost); | ||
@@ -73,4 +74,15 @@ const resolveModuleNameLiterals = languageServiceHost.resolveModuleNameLiterals?.bind(languageServiceHost); | ||
function updateVirtualScript(fileName) { | ||
const version = languageServiceHost.getScriptVersion(fileName); | ||
if (crashFileNames.has(fileName)) { | ||
return; | ||
} | ||
let version; | ||
try { | ||
version = languageServiceHost.getScriptVersion(fileName); | ||
} | ||
catch { | ||
// fix https://github.com/vuejs/language-tools/issues/4278 | ||
crashFileNames.add(fileName); | ||
} | ||
if (version === undefined) { | ||
// somehow getScriptVersion returns undefined | ||
return; | ||
@@ -77,0 +89,0 @@ } |
@@ -21,3 +21,3 @@ "use strict"; | ||
diagnostics: result.diagnostics | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, true)) | ||
.filter(utils_1.notEmpty), | ||
@@ -28,3 +28,3 @@ }; | ||
return getSyntacticDiagnostics(sourceFile, cancellationToken) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, true)) | ||
.filter(utils_1.notEmpty); | ||
@@ -34,3 +34,3 @@ }; | ||
return getSemanticDiagnostics(sourceFile, cancellationToken) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, true)) | ||
.filter(utils_1.notEmpty); | ||
@@ -40,3 +40,3 @@ }; | ||
return getGlobalDiagnostics(cancellationToken) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, true)) | ||
.filter(utils_1.notEmpty); | ||
@@ -47,3 +47,3 @@ }; | ||
return getBindAndCheckDiagnostics(sourceFile, cancellationToken) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d)) | ||
.map(d => (0, transform_1.transformDiagnostic)(language, d, true)) | ||
.filter(utils_1.notEmpty); | ||
@@ -50,0 +50,0 @@ }; |
import type * as ts from 'typescript'; | ||
export declare function dedupeReferencedSymbols<T extends ts.ReferencedSymbol>(items: T[]): T[]; | ||
export declare function dedupeDocumentSpans<T extends ts.DocumentSpan>(items: T[]): T[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dedupeDocumentSpans = exports.dedupeReferencedSymbols = void 0; | ||
function dedupeReferencedSymbols(items) { | ||
return dedupe(items, item => [ | ||
item.definition.fileName, | ||
item.definition.textSpan.start, | ||
item.definition.textSpan.length, | ||
].join(':')); | ||
} | ||
exports.dedupeReferencedSymbols = dedupeReferencedSymbols; | ||
exports.dedupeDocumentSpans = void 0; | ||
function dedupeDocumentSpans(items) { | ||
@@ -13,0 +5,0 @@ return dedupe(items, item => [ |
import { Language, CodeInformation, SourceMap, SourceScript } from '@volar/language-core'; | ||
import type * as ts from 'typescript'; | ||
export declare function transformCallHierarchyItem(language: Language, item: ts.CallHierarchyItem, filter: (data: CodeInformation) => boolean): ts.CallHierarchyItem; | ||
export declare function transformDiagnostic<T extends ts.Diagnostic>(language: Language, diagnostic: T): T | undefined; | ||
export declare function transformDiagnostic<T extends ts.Diagnostic>(language: Language, diagnostic: T, isTsc: boolean): T | undefined; | ||
export declare function fillSourceFileText(language: Language, sourceFile: ts.SourceFile): void; | ||
@@ -6,0 +6,0 @@ export declare function transformFileTextChanges(language: Language, changes: ts.FileTextChanges, filter: (data: CodeInformation) => boolean): ts.FileTextChanges | undefined; |
@@ -18,3 +18,3 @@ "use strict"; | ||
exports.transformCallHierarchyItem = transformCallHierarchyItem; | ||
function transformDiagnostic(language, diagnostic) { | ||
function transformDiagnostic(language, diagnostic, isTsc) { | ||
if (!transformedDiagnostics.has(diagnostic)) { | ||
@@ -25,3 +25,3 @@ transformedDiagnostics.set(diagnostic, undefined); | ||
diagnostic.relatedInformation = relatedInformation | ||
.map(d => transformDiagnostic(language, d)) | ||
.map(d => transformDiagnostic(language, d, isTsc)) | ||
.filter(utils_1.notEmpty); | ||
@@ -36,3 +36,5 @@ } | ||
if (sourceSpan) { | ||
fillSourceFileText(language, diagnostic.file); | ||
if (isTsc) { | ||
fillSourceFileText(language, diagnostic.file); | ||
} | ||
transformedDiagnostics.set(diagnostic, { | ||
@@ -67,3 +69,2 @@ ...diagnostic, | ||
} | ||
return; | ||
} | ||
@@ -95,9 +96,6 @@ exports.fillSourceFileText = fillSourceFileText; | ||
if (!textSpan && shouldFallback) { | ||
const [serviceScript] = (0, utils_1.getServiceScript)(language, documentSpan.fileName); | ||
if (serviceScript) { | ||
textSpan = { | ||
fileName: documentSpan.fileName, | ||
textSpan: { start: 0, length: 0 }, | ||
}; | ||
} | ||
textSpan = { | ||
fileName: documentSpan.fileName, | ||
textSpan: { start: 0, length: 0 }, | ||
}; | ||
} | ||
@@ -104,0 +102,0 @@ if (!textSpan) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
function createResolveModuleName(ts, host, languagePlugins, getSourceScript) { | ||
const toPatchResults = new Map(); | ||
const toSourceFileInfo = new Map(); | ||
const moduleResolutionHost = { | ||
@@ -23,6 +23,24 @@ readFile: host.readFile.bind(host), | ||
if (fileName.endsWith(`.d.${extension}.ts`)) { | ||
const patchFileName = fileName.slice(0, -`.d.${extension}.ts`.length) + `.${extension}`; | ||
if (fileExists(patchFileName)) { | ||
toPatchResults.set(fileName, patchFileName); | ||
return true; | ||
const sourceFileName = fileName.slice(0, -`.d.${extension}.ts`.length) + `.${extension}`; | ||
if (fileExists(sourceFileName)) { | ||
const sourceScript = getSourceScript(sourceFileName); | ||
if (sourceScript?.generated) { | ||
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root); | ||
if (serviceScript) { | ||
const dtsPath = sourceFileName + '.d.ts'; | ||
if ((serviceScript.extension === '.js' || serviceScript.extension === '.jsx') && fileExists(dtsPath)) { | ||
toSourceFileInfo.set(fileName, { | ||
sourceFileName: dtsPath, | ||
extension: '.ts', | ||
}); | ||
} | ||
else { | ||
toSourceFileInfo.set(fileName, { | ||
sourceFileName, | ||
extension: serviceScript.extension, | ||
}); | ||
} | ||
return true; | ||
} | ||
} | ||
} | ||
@@ -37,13 +55,10 @@ } | ||
const result = ts.resolveModuleName(moduleName, containingFile, compilerOptions, moduleResolutionHost, cache, redirectedReference, resolutionMode); | ||
if (result.resolvedModule && toPatchResults.has(result.resolvedModule.resolvedFileName)) { | ||
result.resolvedModule.resolvedFileName = toPatchResults.get(result.resolvedModule.resolvedFileName); | ||
const sourceScript = getSourceScript(result.resolvedModule.resolvedFileName); | ||
if (sourceScript?.generated) { | ||
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root); | ||
if (serviceScript) { | ||
result.resolvedModule.extension = serviceScript.extension; | ||
} | ||
if (result.resolvedModule) { | ||
const sourceFileInfo = toSourceFileInfo.get(result.resolvedModule.resolvedFileName); | ||
if (sourceFileInfo) { | ||
result.resolvedModule.resolvedFileName = sourceFileInfo.sourceFileName; | ||
result.resolvedModule.extension = sourceFileInfo.extension; | ||
} | ||
} | ||
toPatchResults.clear(); | ||
toSourceFileInfo.clear(); | ||
return result; | ||
@@ -50,0 +65,0 @@ }; |
{ | ||
"name": "@volar/typescript", | ||
"version": "2.2.0-alpha.9", | ||
"version": "2.2.0-alpha.10", | ||
"license": "MIT", | ||
@@ -15,3 +15,3 @@ "files": [ | ||
"dependencies": { | ||
"@volar/language-core": "2.2.0-alpha.9", | ||
"@volar/language-core": "2.2.0-alpha.10", | ||
"path-browserify": "^1.0.1" | ||
@@ -22,5 +22,5 @@ }, | ||
"@types/path-browserify": "latest", | ||
"@volar/language-service": "2.2.0-alpha.9" | ||
"@volar/language-service": "2.2.0-alpha.10" | ||
}, | ||
"gitHead": "7373fb794012e219aae3948c730c004827b03021" | ||
"gitHead": "aedd2230883c457f703be93ed150917a3efde75c" | ||
} |
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
175761
3772
+ Added@volar/language-core@2.2.0-alpha.10(transitive)
+ Added@volar/source-map@2.2.0-alpha.10(transitive)
- Removed@volar/language-core@2.2.0-alpha.9(transitive)
- Removed@volar/source-map@2.2.0-alpha.9(transitive)