From 83aa3f8cd5d83c147e6e9097241e0365c6b14ec2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 20:25:21 +0000 Subject: [PATCH 1/2] Initial plan From a67ce0b664adc08d9ca68d190dc219122390a502 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 20:34:29 +0000 Subject: [PATCH 2/2] Add first-open pull diagnostics regression test Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- tsc/internal/lsp/server_diagnostics_test.go | 74 +++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tsc/internal/lsp/server_diagnostics_test.go diff --git a/tsc/internal/lsp/server_diagnostics_test.go b/tsc/internal/lsp/server_diagnostics_test.go new file mode 100644 index 0000000000000..9e59b3c2da409 --- /dev/null +++ b/tsc/internal/lsp/server_diagnostics_test.go @@ -0,0 +1,74 @@ +package lsp_test + +import ( + "context" + "io" + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/bundled" + "github.com/microsoft/TypeScript/tsc/internal/lsp" + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" + "github.com/microsoft/TypeScript/tsc/internal/testutil/lsptestutil" + "github.com/microsoft/TypeScript/tsc/internal/vfs/vfstest" + "gotest.tools/v3/assert" +) + +func TestDiagnosticsForFirstOpenedFile(t *testing.T) { + t.Parallel() + if !bundled.Embedded { + t.Skip("bundled files are not embedded") + } + + const broken = `import { greet } from "./helper"; +export const message = greet("world"); +const bad: string = 123;` + fs := bundled.WrapFS(vfstest.FromMap(map[string]string{ + "/home/project/tsconfig.json": `{"compilerOptions":{"target":"es2020","module":"esnext","moduleResolution":"bundler","strict":true,"noEmit":true},"include":["*.ts"]}`, + "/home/project/helper.ts": "export function greet(name: string): string { return `Hello, ${name}`; }", + "/home/project/broken.ts": broken, + }, false)) + onServerRequest := func(_ context.Context, req *lsproto.RequestMessage) *lsproto.ResponseMessage { + switch req.Method { + case lsproto.MethodWorkspaceConfiguration: + return &lsproto.ResponseMessage{ID: req.ID, JSONRPC: req.JSONRPC, Result: []any{nil, nil, nil, nil}} + case lsproto.MethodClientRegisterCapability, lsproto.MethodClientUnregisterCapability: + return &lsproto.ResponseMessage{ID: req.ID, JSONRPC: req.JSONRPC, Result: lsproto.Null{}} + default: + return nil + } + } + client, closeClient := lsptestutil.NewLSPClient(t, lsp.ServerOptions{ + Err: io.Discard, + Cwd: "/home/project", + FS: fs, + DefaultLibraryPath: bundled.LibPath(), + }, onServerRequest) + t.Cleanup(func() { _ = closeClient() }) + + initMsg, _, ok := lsptestutil.SendRequest(t, client, lsproto.InitializeInfo, &lsproto.InitializeParams{ + Capabilities: &lsproto.ClientCapabilities{ + TextDocument: &lsproto.TextDocumentClientCapabilities{ + Diagnostic: &lsproto.DiagnosticClientCapabilities{}, + }, + }, + }) + assert.Assert(t, ok && initMsg.AsResponse().Error == nil, "initialize failed") + lsptestutil.SendNotification(t, client, lsproto.InitializedInfo, &lsproto.InitializedParams{}) + <-client.Server.InitComplete() + + uri := lsproto.DocumentUri("file:///home/project/broken.ts") + lsptestutil.SendNotification(t, client, lsproto.TextDocumentDidOpenInfo, &lsproto.DidOpenTextDocumentParams{ + TextDocument: &lsproto.TextDocumentItem{Uri: uri, LanguageId: "typescript", Version: 1, Text: broken}, + }) + diagnosticMsg, diagnostics, ok := lsptestutil.SendRequest(t, client, lsproto.TextDocumentDiagnosticInfo, &lsproto.DocumentDiagnosticParams{ + TextDocument: lsproto.TextDocumentIdentifier{Uri: uri}, + }) + assert.Assert(t, ok && diagnosticMsg.AsResponse().Error == nil) + assert.Assert(t, diagnostics.FullDocumentDiagnosticReport != nil) + for _, diagnostic := range diagnostics.FullDocumentDiagnosticReport.Items { + if diagnostic.Code != nil && diagnostic.Code.Integer != nil && *diagnostic.Code.Integer == 2322 { + return + } + } + t.Fatalf("diagnostics did not contain TS2322: %v", diagnostics.FullDocumentDiagnosticReport.Items) +}