microsoft/typescript-go · error

completion item data is nil

Error message

completion item data is nil

What it means

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.

Source

Thrown at internal/lsp/server.go:1686

}

func (s *Server) handleTypeDefinition(ctx context.Context, ls *ls.LanguageService, params *lsproto.TypeDefinitionParams) (lsproto.TypeDefinitionResponse, error) {
	return ls.ProvideTypeDefinition(ctx, params.TextDocument.Uri, params.Position)
}

func (s *Server) handleCompletion(ctx context.Context, languageService *ls.LanguageService, params *lsproto.CompletionParams) (lsproto.CompletionResponse, error) {
	return languageService.ProvideCompletion(
		ctx,
		params.TextDocument.Uri,
		params.Position,
		params.Context,
	)
}

func (s *Server) handleCompletionItemResolve(ctx context.Context, params *lsproto.CompletionItem, reqMsg *lsproto.RequestMessage) (lsproto.CompletionResolveResponse, error) {
	data := params.Data
	if data == nil {
		return nil, errors.New("completion item data is nil")
	}
	languageService, err := s.session.GetLanguageService(ctx, lsconv.FileNameToDocumentURI(data.FileName))
	if err != nil {
		return nil, err
	}
	defer s.recover(reqMsg)
	return languageService.ResolveCompletionItem(ctx, params, data)
}

func (s *Server) handleDocumentFormat(ctx context.Context, ls *ls.LanguageService, params *lsproto.DocumentFormattingParams) (lsproto.DocumentFormattingResponse, error) {
	return ls.ProvideFormatDocument(
		ctx,
		params.TextDocument.Uri,
		params.Options,
	)
}

func (s *Server) handleDocumentRangeFormat(ctx context.Context, ls *ls.LanguageService, params *lsproto.DocumentRangeFormattingParams) (lsproto.DocumentRangeFormattingResponse, error) {

View on GitHub (pinned to 1bcfa18d79)

Solutions

  1. Only call completionItem/resolve with the exact item object previously returned by this server's completion response
  2. Disable caching/serialization of completion items in the client middleware, or include the data field in the cache key + payload
  3. If mixing providers, tag your items and skip resolve for foreign ones
  4. Handle this as a non-fatal error in the client: drop the enhanced-resolve path and show the base label

Example fix

// before
const item = cache.getStoredItem(label); // data field lost
const resolved = await client.sendRequest('completionItem/resolve', item);

// after
const item = cache.getStoredItem(label);
if (!item?.data) return item; // nothing to resolve
const resolved = await client.sendRequest('completionItem/resolve', item);
Defensive patterns

Strategy: type-guard

Type guard

function hasCompletionData(item: CompletionItem): boolean {
	return item != null && typeof item === 'object' && item.data != null
		&& typeof item.data.fileName === 'string';
}

Try / catch

try {
	resolved = await client.sendRequest('completionItem/resolve', item);
} catch (e: any) {
	if (e?.message?.includes('completion item data is nil')) {
		return item; // show base item without enhanced details
	}
	throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16). Data as JSON: /api/errors/11046846433f7bdc. Report an issue: GitHub.