Conversation
- Add `file.meta["ResolvedNamespace"] = namespace` to `#createEnumContext` to match `#createModelContext` behavior. This allows `resolveReferenceFromScopes` to find the enum's namespace and add the appropriate `using` import. - Fix `checkOrAddNamespaceToScope` to support multiple dynamic namespace additions per source file (removes single-namespace `AddedScope` limitation). - Add test: MergePatchUpdate with enum type in different namespace Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
commit: |
|
You can try these changes here
|
|
@copilot analyze how the logic for including a namespace in a sourceFile and suggest some more comprehensive tests to find any other places where a namespace might be needed and is not included. |
|
@copilot Also, pull in the latest from the main branch |
…pe references Tests added: - MergePatchUpdate with 2 enum properties from 2 different sub-namespaces (validates the multi-import fix) - Regular model with enum from sub-namespace (validates createEnumContext fix for non-MergePatch case) - MergePatchUpdate with optional enum from different namespace - MergePatchUpdate with string-enum union property from different namespace - MergePatchUpdate with array of models from different namespace Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Here's the analysis and the tests I added (commit 8eef0c4): Namespace inclusion logic — there are two mechanisms:
Scenarios tested in 8eef0c4:
|
…ilot/fix-missing-namespace-imports
|
@copilot You removed an update to |
|
@copilot and as always, pull the latest from main whenever you add commits to this branch |
…edup) Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
How
Potential problems from removing it The only caller that handles a if (checkOrAddNamespaceToScope(declNs, ref.scope)) {
return targetDeclaration.name; // short name — using was added
}
return declNs ? `${declNs}.${targetDeclaration.name} ` : undefined; // fully qualifiedWith Two theoretical problems:
New regression tests added in 82add0a
|
…ilot/fix-missing-namespace-imports
#createEnumContextdoesn't setfile.meta["ResolvedNamespace"], causingresolveReferenceFromScopesto getundefinednamespace for enums and fall back to unqualified name without adding the importMergePatchUpdate(verifiesusing Microsoft.Contoso;appears)file.meta[this.#nsKey] = namespaceto#createEnumContextinservice.tsAddedScopesingle-namespace limitation incheckOrAddNamespaceToScopeininterfaces.tsusingdirectives emittedusingemitted (deduplication)@typespec/http-server-csharpOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.