Skip to content

Feature/csharp model name fixer#2

Open
haiyuazhang wants to merge 3 commits into
mainfrom
feature/csharp-model-name-fixer
Open

Feature/csharp model name fixer#2
haiyuazhang wants to merge 3 commits into
mainfrom
feature/csharp-model-name-fixer

Conversation

@haiyuazhang
Copy link
Copy Markdown
Owner

@haiyuazhang haiyuazhang commented Jun 2, 2026

Adds a TypeSpec linter rule in @typespec/http-client-csharp that flags single-word model names (e.g. model Document) which collide with BCL or third-party types. The fix flow runs in the typespec-vscode extension:

  • Linter: detects single-word model names; also flags @@clientName overrides whose target string is a single word.
  • VS Code extension: adds a code action provider that offers two AI fixes via the lightbulb (Ctrl+.):
    1. Rename model directly (uses the language server rename provider so all references are updated).
    2. Override via @@clientName in client.tsp (creates client.tsp if missing, groups inserts after existing @@clientName lines, and auto-adds imports: - ./client.tsp to tspconfig.yaml so the compiler picks it up as a first-class source).
  • AI suggestions are fetched on demand via vscode.lm (no external SDK).
  • File watcher cleans up the tspconfig.yaml import and nudges open editors to recompile when client.tsp is deleted.
  • Adds a manual test workspace under packages/http-client-csharp/linter-test.

How the Codefix Works

Phase 1: Detection (Compilation)

  1. Linter rule single-word-model-name.rule.ts runs during compilation
  2. Detects models like model Document { ... } — single PascalCase word
  3. Reports warning with no codefixes attached (the fixer lives in the VS Code extension, not the linter)
  4. 🟡 Yellow squiggly appears under the model name

Phase 2: Menu (Ctrl+.)

  1. User presses Ctrl+. on the yellow squiggly
  2. VS Code asks the extension's CodeActionProvider (code-action-provider.ts) — not the language server
  3. Provider returns two static menu items — no AI call yet, so the menu appears instantly:
    • 💡 Rename model (AI-suggested)
    • 💡 Override via @@clientName (AI-suggested)

Phase 3: AI Suggestion (after user clicks)

  1. User clicks one of the menu items → runs SuggestModelName command
  2. Command calls vscode.lm directly (no LSP bridge — already in the extension host)
  3. Tries model families: gpt-4o, gpt-4, gpt-3.5-turbo, copilot-gpt-4.1
  4. AI returns 5 name suggestions
  5. Shows a QuickPick dialog with the suggestions:
    • TableDocument (recommended)
    • StorageDocument
    • TableStorageDocument
    • DocumentEntity
    • TableDocumentEntity
  6. User picks one

Phase 4: Apply

If "Rename model" was chosen:

14a. Calls vscode.executeDocumentRenameProvider → renames the model across all files, updating all references

If "Override via @@clientName" was chosen:

14b. Creates/edits client.tsp via vscode.WorkspaceEdit:

  • Adds import and using lines if missing
  • Appends @@clientName(Document, "TableDocument");
  1. Calls ensureClientTspImport() → adds imports: - ./client.tsp to tspconfig.yaml
  2. Opens client.tsp in the editor
  3. Recompilation triggers → getLibraryName() now returns the multi-word name → ✅ warning disappears

m-nash and others added 3 commits April 23, 2026 13:58
Adds a TypeSpec linter rule in @typespec/http-client-csharp that flags
single-word model names (e.g. `model Document`) which collide with BCL
or third-party types. The fix flow runs in the typespec-vscode extension:

- Linter: detects single-word model names; also flags `@@clientName`
  overrides whose target string is a single word.
- VS Code extension: adds a code action provider that offers two AI fixes
  via the lightbulb (Ctrl+.):
    1. Rename model directly (uses the language server rename provider so
       all references are updated).
    2. Override via `@@clientName` in client.tsp (creates client.tsp if
       missing, groups inserts after existing @@clientName lines, and
       auto-adds `imports: - ./client.tsp` to tspconfig.yaml so the
       compiler picks it up as a first-class source).
- AI suggestions are fetched on demand via vscode.lm (no external SDK).
- File watcher cleans up the tspconfig.yaml import and nudges open
  editors to recompile when client.tsp is deleted.
- Adds a manual test workspace under packages/http-client-csharp/linter-test.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cover LM models

- Added 'updateClientName' to the RenameApproach union type to fix TS2367 build error
- Added fallback model discovery using vscode.lm.selectChatModels({}) when
  known model families are unavailable

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

❌ There is undocummented changes. Run chronus add to add a changeset or click here.

The following packages have changes but are not documented.

  • typespec-vscode
Show changes

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.

2 participants