Feature/csharp model name fixer#2
Open
haiyuazhang wants to merge 3 commits into
Open
Conversation
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>
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
Show changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a TypeSpec linter rule in
@typespec/http-client-csharpthat 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:@@clientNameoverrides whose target string is a single word.@@clientNamein client.tsp (creates client.tsp if missing, groups inserts after existing @@clientName lines, and auto-addsimports: - ./client.tspto tspconfig.yaml so the compiler picks it up as a first-class source).How the Codefix Works
Phase 1: Detection (Compilation)
single-word-model-name.rule.tsruns during compilationmodel Document { ... }— single PascalCase wordPhase 2: Menu (Ctrl+.)
code-action-provider.ts) — not the language serverPhase 3: AI Suggestion (after user clicks)
SuggestModelNamecommandgpt-4o,gpt-4,gpt-3.5-turbo,copilot-gpt-4.1TableDocument(recommended)StorageDocumentTableStorageDocumentDocumentEntityTableDocumentEntityPhase 4: Apply
If "Rename model" was chosen:
14a. Calls
vscode.executeDocumentRenameProvider→ renames the model across all files, updating all referencesIf "Override via @@clientName" was chosen:
14b. Creates/edits
client.tspviavscode.WorkspaceEdit:importandusinglines if missing@@clientName(Document, "TableDocument");ensureClientTspImport()→ addsimports: - ./client.tsptotspconfig.yamlclient.tspin the editorgetLibraryName()now returns the multi-word name → ✅ warning disappears