Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

The emitter was directly reporting diagnostics to the program, preventing downstream emitters from collecting and handling diagnostics according to TypeSpec best practices ([Result, readonly Diagnostic[]] pattern).

Changes

  • createModel() - Now returns [CodeModel, readonly Diagnostic[]] instead of CodeModel
  • createCodeModel() - New exported function wrapping emission logic, returns [void, readonly Diagnostic[]]
  • Logger - Added diagnostic collection mode via constructor parameter and getDiagnostics() method
  • $onEmit() - Refactored to call createCodeModel() and report collected diagnostics

Usage

import { createCodeModel } from "@typespec/http-client-csharp";

export async function $onEmit(context: EmitContext<MyOptions>) {
  const [, diagnostics] = await createCodeModel(context);
  // Handle diagnostics as needed
  context.program.reportDiagnostics(diagnostics);
}

The Logger class now stores diagnostics when instantiated with collectDiagnostics: true, enabling the pattern above while maintaining backward compatibility for normal emission.

Original prompt

This section details on the original issue you should resolve

<issue_title>[http-client-csharp] export an API for downstream emitter to call</issue_title>
<issue_description>Originally posted: Azure/azure-sdk-for-net#54788

Per best practice of writing an emitter or typespec library, we should have signatures like this:

getStuff(): [Stuff, readonly Diagnostic[]]

Therefore here, we are making the following changes:

  1. in emitter.ts file, wrap everything inside the if (!program.compilerOptions.noEmit && !program.hasError()) into a new function, which returns [void, readonly Diagnostic[]].
  2. refactor the createCodeModel method to make it return [CodeModel, readonly Diagnostic[]] instead. Inside the createCodeModel method, see if there are code snippets calling the reportDiagnostic method, we need to change them to append the diagnostic into the array and return it.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits January 20, 2026 07:05
Co-authored-by: ArcturusZhang <10554446+ArcturusZhang@users.noreply.github.com>
Co-authored-by: ArcturusZhang <10554446+ArcturusZhang@users.noreply.github.com>
Co-authored-by: ArcturusZhang <10554446+ArcturusZhang@users.noreply.github.com>
Copilot AI changed the title [WIP] Export an API for downstream emitter to call Export diagnostic-collecting API for downstream emitter composition Jan 20, 2026
Copilot AI requested a review from ArcturusZhang January 20, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-csharp] export an API for downstream emitter to call

2 participants