From 725359dbd6e5fb68800c6b78cd8f9c64e26985ca Mon Sep 17 00:00:00 2001 From: Johnson Chu Date: Tue, 4 Jun 2024 11:59:07 +0800 Subject: [PATCH 1/5] Revert "refactor: no longer support mapping to different source files" This reverts commit c4b297b2426ec8b032eec16c5396263bc03e2163. --- .../lib/register/registerEditorFeatures.ts | 5 +- packages/language-server/protocol.ts | 1 - .../lib/features/provideCallHierarchyItems.ts | 27 +-- .../lib/features/provideCompletionItems.ts | 65 +++---- .../lib/features/provideDefinition.ts | 52 +++--- .../lib/features/provideDiagnostics.ts | 21 +-- .../provideDocumentFormattingEdits.ts | 47 +++-- .../lib/features/provideFileReferences.ts | 13 +- .../lib/features/provideReferences.ts | 15 +- .../lib/features/provideWorkspaceSymbols.ts | 9 +- .../lib/features/resolveCompletionItem.ts | 19 +- .../language-service/lib/languageService.ts | 22 +-- packages/language-service/lib/types.ts | 2 +- .../lib/utils/featureWorkers.ts | 10 +- .../language-service/lib/utils/transform.ts | 168 ++++++++++-------- packages/typescript/lib/node/utils.ts | 2 +- .../typescript/lib/protocol/createProject.ts | 12 +- 17 files changed, 263 insertions(+), 227 deletions(-) diff --git a/packages/language-server/lib/register/registerEditorFeatures.ts b/packages/language-server/lib/register/registerEditorFeatures.ts index 76a3521c..8e155e55 100644 --- a/packages/language-server/lib/register/registerEditorFeatures.ts +++ b/packages/language-server/lib/register/registerEditorFeatures.ts @@ -92,8 +92,9 @@ export function registerEditorFeatures(server: LanguageServer) { const virtualCode = sourceScript?.generated?.embeddedCodes.get(params.virtualCodeId); if (virtualCode) { const mappings: Record = {}; - const map = languageService.context.documents.getSourceMap(virtualCode); - mappings[map.sourceDocument.uri] = map.map.mappings; + for (const map of languageService.context.documents.getMaps(virtualCode)) { + mappings[map.sourceDocument.uri] = map.map.mappings; + } return { content: virtualCode.snapshot.getText(0, virtualCode.snapshot.getLength()), mappings, diff --git a/packages/language-server/protocol.ts b/packages/language-server/protocol.ts index 3143f464..8c650cf5 100644 --- a/packages/language-server/protocol.ts +++ b/packages/language-server/protocol.ts @@ -155,7 +155,6 @@ export namespace GetVirtualCodeRequest { }; export type ResponseType = { content: string; - // TODO: Simplify this, no map required mappings: Record; }; export type ErrorType = never; diff --git a/packages/language-service/lib/features/provideCallHierarchyItems.ts b/packages/language-service/lib/features/provideCallHierarchyItems.ts index c3f5087c..eda7b6d6 100644 --- a/packages/language-service/lib/features/provideCallHierarchyItems.ts +++ b/packages/language-service/lib/features/provideCallHierarchyItems.ts @@ -186,19 +186,22 @@ export function register(context: LanguageServiceContext) { return [tsItem, tsRanges]; } - const map = context.documents.getSourceMap(virtualCode); - - let range = map.getSourceRange(tsItem.range); - if (!range) { - // TODO: