{"record":{"id":"11046846433f7bdc","repo":"microsoft/typescript-go","slug":"completion-item-data-is-nil-110468","errorCode":null,"errorMessage":"completion item data is nil","messagePattern":"completion item data is nil","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lsp/server.go","lineNumber":1686,"sourceCode":"}\n\nfunc (s *Server) handleTypeDefinition(ctx context.Context, ls *ls.LanguageService, params *lsproto.TypeDefinitionParams) (lsproto.TypeDefinitionResponse, error) {\n\treturn ls.ProvideTypeDefinition(ctx, params.TextDocument.Uri, params.Position)\n}\n\nfunc (s *Server) handleCompletion(ctx context.Context, languageService *ls.LanguageService, params *lsproto.CompletionParams) (lsproto.CompletionResponse, error) {\n\treturn languageService.ProvideCompletion(\n\t\tctx,\n\t\tparams.TextDocument.Uri,\n\t\tparams.Position,\n\t\tparams.Context,\n\t)\n}\n\nfunc (s *Server) handleCompletionItemResolve(ctx context.Context, params *lsproto.CompletionItem, reqMsg *lsproto.RequestMessage) (lsproto.CompletionResolveResponse, error) {\n\tdata := params.Data\n\tif data == nil {\n\t\treturn nil, errors.New(\"completion item data is nil\")\n\t}\n\tlanguageService, err := s.session.GetLanguageService(ctx, lsconv.FileNameToDocumentURI(data.FileName))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer s.recover(reqMsg)\n\treturn languageService.ResolveCompletionItem(ctx, params, data)\n}\n\nfunc (s *Server) handleDocumentFormat(ctx context.Context, ls *ls.LanguageService, params *lsproto.DocumentFormattingParams) (lsproto.DocumentFormattingResponse, error) {\n\treturn ls.ProvideFormatDocument(\n\t\tctx,\n\t\tparams.TextDocument.Uri,\n\t\tparams.Options,\n\t)\n}\n\nfunc (s *Server) handleDocumentRangeFormat(ctx context.Context, ls *ls.LanguageService, params *lsproto.DocumentRangeFormattingParams) (lsproto.DocumentRangeFormattingResponse, error) {","sourceCodeStart":1668,"sourceCodeEnd":1704,"githubUrl":"https://github.com/microsoft/typescript-go/blob/1bcfa18d79a3be41772223d5c05dfe4480e614ff/internal/lsp/server.go#L1668-L1704","documentation":"Thrown by the completionItem/resolve handler when the client resolves a completion item whose Data field is nil. The Data payload carries the server's own routing info (FileName, etc.) used to find the right language service and re-resolve the item; without it there is nothing to resolve. Items originally returned by this server always carry Data, so a nil Data almost always means the item did not round-trip intact.","triggerScenarios":"Client serializes completion items to disk/cache and rehydrates them dropping the data field; item came from another provider merged into the same list; resolveCapability enabled but the client sends a freshly constructed item; JSON unmarshal dropped data because the item was stringified through a lossy channel.","commonSituations":"Editor extensions that cache completions across sessions; middleware transforming items and stripping unknown fields; snippet providers mixing foreign items into the returned list; client resolving an item after the server restarted (data schema changed).","solutions":["Only call completionItem/resolve with the exact item object previously returned by this server's completion response","Disable caching/serialization of completion items in the client middleware, or include the data field in the cache key + payload","If mixing providers, tag your items and skip resolve for foreign ones","Handle this as a non-fatal error in the client: drop the enhanced-resolve path and show the base label"],"exampleFix":"// before\nconst item = cache.getStoredItem(label); // data field lost\nconst resolved = await client.sendRequest('completionItem/resolve', item);\n\n// after\nconst item = cache.getStoredItem(label);\nif (!item?.data) return item; // nothing to resolve\nconst resolved = await client.sendRequest('completionItem/resolve', item);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function hasCompletionData(item: CompletionItem): boolean {\n\treturn item != null && typeof item === 'object' && item.data != null\n\t\t&& typeof item.data.fileName === 'string';\n}","tryCatchPattern":"try {\n\tresolved = await client.sendRequest('completionItem/resolve', item);\n} catch (e: any) {\n\tif (e?.message?.includes('completion item data is nil')) {\n\t\treturn item; // show base item without enhanced details\n\t}\n\tthrow e;\n}","preventionTips":["Pass the exact item object from the completion response back to resolve","When caching completion items, persist the data field with them","Skip resolve for items merged in from other providers"],"tags":["lsp","completion","resolve","client-state"],"backgroundTag":null,"analyzedSha":"1bcfa18d79a3be41772223d5c05dfe4480e614ff","analyzedAt":"2026-08-16T02:12:00.115Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}