From a4d82d01d330ca56934060e2bef47cea9b17b7ab Mon Sep 17 00:00:00 2001 From: Josue Barros Date: Mon, 16 Nov 2026 14:49:18 -0300 Subject: [PATCH 1/2] Return null from the remaining content-mapper fallbacks When a content mapper is unregistered but the client still has the file open, some requests return a null result and others fail with 'no project for unknown script kind'. contentMapperFallbackResponse only covered hover, signature help, definition, type definition, implementation, references, document highlight, completion and rename. Cover inlay hint, code lens, formatting, range formatting, on-type formatting, linked editing range, prepare call hierarchy, prepare rename, and incoming/outgoing call hierarchy. Extend the content-mapper lifecycle test to send each one after unregistration and assert a null result instead of an error. Fixes #65525 --- tsc/internal/lsp/server.go | 12 ++- tsc/internal/lsp/server_contentmapper_test.go | 77 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/tsc/internal/lsp/server.go b/tsc/internal/lsp/server.go index d115114dc3683..78486d8a6420b 100644 --- a/tsc/internal/lsp/server.go +++ b/tsc/internal/lsp/server.go @@ -1268,7 +1268,17 @@ func contentMapperFallbackResponse(method lsproto.Method, err error) (any, bool) lsproto.MethodTextDocumentReferences, lsproto.MethodTextDocumentDocumentHighlight, lsproto.MethodTextDocumentCompletion, - lsproto.MethodTextDocumentRename: + lsproto.MethodTextDocumentRename, + lsproto.MethodTextDocumentInlayHint, + lsproto.MethodTextDocumentCodeLens, + lsproto.MethodTextDocumentFormatting, + lsproto.MethodTextDocumentRangeFormatting, + lsproto.MethodTextDocumentOnTypeFormatting, + lsproto.MethodTextDocumentLinkedEditingRange, + lsproto.MethodTextDocumentPrepareCallHierarchy, + lsproto.MethodTextDocumentPrepareRename, + lsproto.MethodCallHierarchyIncomingCalls, + lsproto.MethodCallHierarchyOutgoingCalls: return lsproto.Null{}, true default: return nil, false diff --git a/tsc/internal/lsp/server_contentmapper_test.go b/tsc/internal/lsp/server_contentmapper_test.go index eb43bb2fbe594..b19424fec21fb 100644 --- a/tsc/internal/lsp/server_contentmapper_test.go +++ b/tsc/internal/lsp/server_contentmapper_test.go @@ -259,6 +259,83 @@ export const title = "Profile"; assert.Assert(t, found, "expected %s unregistration", id) } + position := lsproto.Position{Line: 3, Character: 15} + rangeValue := lsproto.Range{Start: position, End: position} + formattingOptions := &lsproto.FormattingOptions{TabSize: 4, InsertSpaces: true} + textDocument := lsproto.TextDocumentIdentifier{Uri: uri} + callHierarchyItem := &lsproto.CallHierarchyItem{ + Name: "stale", + Kind: lsproto.SymbolKind(12), + Uri: uri, + Range: rangeValue, + SelectionRange: rangeValue, + } + + assertFallback := func(msg *lsproto.Message, ok bool, method string) { + t.Helper() + assert.Assert(t, ok && msg.AsResponse().Error == nil, "%s should return a null fallback", method) + } + + inlayHintMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentInlayHintInfo, &lsproto.InlayHintParams{ + TextDocument: textDocument, + Range: rangeValue, + }) + assertFallback(inlayHintMsg, ok, "textDocument/inlayHint") + + codeLensMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentCodeLensInfo, &lsproto.CodeLensParams{ + TextDocument: textDocument, + }) + assertFallback(codeLensMsg, ok, "textDocument/codeLens") + + formattingMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentFormattingInfo, &lsproto.DocumentFormattingParams{ + TextDocument: textDocument, + Options: formattingOptions, + }) + assertFallback(formattingMsg, ok, "textDocument/formatting") + + rangeFormattingMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentRangeFormattingInfo, &lsproto.DocumentRangeFormattingParams{ + TextDocument: textDocument, + Range: rangeValue, + Options: formattingOptions, + }) + assertFallback(rangeFormattingMsg, ok, "textDocument/rangeFormatting") + + onTypeFormattingMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentOnTypeFormattingInfo, &lsproto.DocumentOnTypeFormattingParams{ + TextDocument: textDocument, + Position: position, + Ch: ";", + Options: formattingOptions, + }) + assertFallback(onTypeFormattingMsg, ok, "textDocument/onTypeFormatting") + + linkedEditingMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentLinkedEditingRangeInfo, &lsproto.LinkedEditingRangeParams{ + TextDocument: textDocument, + Position: position, + }) + assertFallback(linkedEditingMsg, ok, "textDocument/linkedEditingRange") + + prepareCallHierarchyMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentPrepareCallHierarchyInfo, &lsproto.CallHierarchyPrepareParams{ + TextDocument: textDocument, + Position: position, + }) + assertFallback(prepareCallHierarchyMsg, ok, "textDocument/prepareCallHierarchy") + + prepareRenameMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentPrepareRenameInfo, &lsproto.PrepareRenameParams{ + TextDocument: textDocument, + Position: position, + }) + assertFallback(prepareRenameMsg, ok, "textDocument/prepareRename") + + incomingCallsMsg, _, ok := client.SendRequest(t, lsproto.CallHierarchyIncomingCallsInfo, &lsproto.CallHierarchyIncomingCallsParams{ + Item: callHierarchyItem, + }) + assertFallback(incomingCallsMsg, ok, "callHierarchy/incomingCalls") + + outgoingCallsMsg, _, ok := client.SendRequest(t, lsproto.CallHierarchyOutgoingCallsInfo, &lsproto.CallHierarchyOutgoingCallsParams{ + Item: callHierarchyItem, + }) + assertFallback(outgoingCallsMsg, ok, "callHierarchy/outgoingCalls") + client.SendNotification(t, lsproto.TextDocumentDidCloseInfo, &lsproto.DidCloseTextDocumentParams{ TextDocument: lsproto.TextDocumentIdentifier{Uri: uri}, }) From bb16c174096e69e46c9709bec3d68b4b02b6a3e6 Mon Sep 17 00:00:00 2001 From: Josue Barros Date: Mon, 16 Nov 2026 15:35:44 -0300 Subject: [PATCH 2/2] Assert the content-mapper fallbacks return JSON null The shared test helper only checked for a successful decode, so a non-null result such as an empty array would still pass. Assert the raw JSON-RPC result is null for every fallback request. --- tsc/internal/lsp/server_contentmapper_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tsc/internal/lsp/server_contentmapper_test.go b/tsc/internal/lsp/server_contentmapper_test.go index b19424fec21fb..e18a3d40c87ea 100644 --- a/tsc/internal/lsp/server_contentmapper_test.go +++ b/tsc/internal/lsp/server_contentmapper_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/microsoft/TypeScript/tsc/internal/bundled" + "github.com/microsoft/TypeScript/tsc/internal/json" "github.com/microsoft/TypeScript/tsc/internal/lsp" "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" "github.com/microsoft/TypeScript/tsc/internal/testutil/contentmappertest" @@ -274,6 +275,8 @@ export const title = "Profile"; assertFallback := func(msg *lsproto.Message, ok bool, method string) { t.Helper() assert.Assert(t, ok && msg.AsResponse().Error == nil, "%s should return a null fallback", method) + result, isValue := msg.AsResponse().Result.(json.Value) + assert.Assert(t, isValue && string(result) == "null", "%s should return JSON null, got %#v", method, msg.AsResponse().Result) } inlayHintMsg, _, ok := client.SendRequest(t, lsproto.TextDocumentInlayHintInfo, &lsproto.InlayHintParams{