-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve how we handle Static Helpers #2716
Conversation
@@ -52,64 +53,4 @@ export interface CoreDependencies extends Record<string, ReferenceableSymbol> { | |||
}; | |||
} | |||
|
|||
const _CoreDependencies: CoreDependencies = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving these to modular/external-dependencies.ts
@@ -39,15 +45,18 @@ export interface Binder { | |||
|
|||
class BinderImp implements Binder { | |||
private declarations = new Map<unknown, DeclarationInfo>(); | |||
private references = new Map<unknown, Set<SourceFile>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this map to track things that are used, this is helpful to cleanup unused static-helpers
@@ -146,7 +155,7 @@ class BinderImp implements Binder { | |||
* @returns The serialized placeholder string. | |||
*/ | |||
private serializePlaceholder(refkey: unknown): string { | |||
return `"<PLACEHOLDER:${String(refkey)}>"`; | |||
return `_PLACEHOLDER_${String(refkey)}_`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This format is safer with ts-morph. Sometimes the double quotes and < may cause unexpected ts-morph behavior. This makes the placeholder a valid identifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -394,6 +397,12 @@ function getLroOnlyOperationFunction(operation: Operation, clientType: string) { | |||
getOperationSignatureParameters(operation, clientType); | |||
const returnType = buildLroReturnType(operation); | |||
const { name, fixme = [] } = getOperationName(operation); | |||
const pollerLikeReference = resolveReference( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to see this change! :)And we don't need to care the importing path stuff.
Objective:
Enhance the handling of static-helpers by transitioning from string injection into a
ts-morph
file to utilizing actual TypeScript files, which are copied to the output directory. This change aims to streamline the process and improve maintainability.Key Changes:
resolveReference(PagingHelpers.buildPagedAsyncIterator)
, automatically adding the correct import.Future Work:
I created 2 additional PRs that will merge into this one to make review a bit easier. This PR contains the changes to the code-gen.
PR with changes to generated CADL ranch tests: joheredi#8
PR with changes to generated smoke tests: joheredi#10