-
Notifications
You must be signed in to change notification settings - Fork 243
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
[Bug] Fix semantic walker not firing exitOperation or exitModelProperty #4381
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/almend-SemanticWalkerExit-2024-8-9-17-49-42.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: fix | ||
packages: | ||
- "@typespec/compiler" | ||
--- | ||
|
||
Fix Semantic walker doesn't fire exitOperation or exitModelProperty |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,9 +29,12 @@ describe("compiler: semantic walker", () => { | |
function createCollector(customListener?: SemanticNodeListener) { | ||
const result = { | ||
models: [] as Model[], | ||
exitModels: [] as Model[], | ||
modelProperties: [] as ModelProperty[], | ||
exitModelProperties: [] as ModelProperty[], | ||
namespaces: [] as Namespace[], | ||
operations: [] as Operation[], | ||
exitOperations: [] as Operation[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason not to extend the post-order callbacks to every type? Looks like we might still be missing some like |
||
interfaces: [] as Interface[], | ||
unions: [] as Union[], | ||
unionVariants: [] as UnionVariant[], | ||
|
@@ -46,14 +49,26 @@ describe("compiler: semantic walker", () => { | |
result.operations.push(x); | ||
return customListener?.operation?.(x); | ||
}, | ||
exitOperation: (x) => { | ||
result.exitOperations.push(x); | ||
return customListener?.exitOperation?.(x); | ||
}, | ||
model: (x) => { | ||
result.models.push(x); | ||
return customListener?.model?.(x); | ||
}, | ||
exitModel: (x) => { | ||
result.exitModels.push(x); | ||
return customListener?.exitModel?.(x); | ||
}, | ||
modelProperty: (x) => { | ||
result.modelProperties.push(x); | ||
return customListener?.modelProperty?.(x); | ||
}, | ||
exitModelProperty: (x) => { | ||
result.exitModelProperties.push(x); | ||
return customListener?.exitModelProperty?.(x); | ||
}, | ||
union: (x) => { | ||
result.unions.push(x); | ||
return customListener?.union?.(x); | ||
|
@@ -100,6 +115,25 @@ describe("compiler: semantic walker", () => { | |
strictEqual(result.models[2].name, "Bar"); | ||
}); | ||
|
||
it("finds exit models", async () => { | ||
const result = await runNavigator(` | ||
model Foo { | ||
nested: { | ||
inline: true | ||
} | ||
} | ||
|
||
model Bar { | ||
name: Foo; | ||
} | ||
`); | ||
|
||
strictEqual(result.exitModels.length, 3); | ||
strictEqual(result.exitModels[0].name, "", "Inline models don't have name"); | ||
strictEqual(result.exitModels[1].name, "Foo"); | ||
strictEqual(result.exitModels[2].name, "Bar"); | ||
}); | ||
|
||
it("finds operations", async () => { | ||
const result = await runNavigator(` | ||
op foo(): true; | ||
|
@@ -114,6 +148,20 @@ describe("compiler: semantic walker", () => { | |
strictEqual(result.operations[1].name, "bar"); | ||
}); | ||
|
||
it("finds exit operations", async () => { | ||
const result = await runNavigator(` | ||
op foo(): true; | ||
|
||
namespace Nested { | ||
op bar(): true; | ||
} | ||
`); | ||
|
||
strictEqual(result.exitOperations.length, 2); | ||
strictEqual(result.exitOperations[0].name, "foo"); | ||
strictEqual(result.exitOperations[1].name, "bar"); | ||
}); | ||
|
||
it("finds namespaces", async () => { | ||
const result = await runNavigator(` | ||
namespace Global.My; | ||
|
@@ -158,6 +206,25 @@ describe("compiler: semantic walker", () => { | |
strictEqual(result.modelProperties[2].name, "name"); | ||
}); | ||
|
||
it("finds exit model properties", async () => { | ||
const result = await runNavigator(` | ||
model Foo { | ||
nested: { | ||
inline: true | ||
} | ||
} | ||
|
||
model Bar { | ||
name: Foo; | ||
} | ||
`); | ||
|
||
strictEqual(result.exitModelProperties.length, 3); | ||
strictEqual(result.exitModelProperties[0].name, "inline"); | ||
strictEqual(result.exitModelProperties[1].name, "nested"); | ||
strictEqual(result.exitModelProperties[2].name, "name"); | ||
}); | ||
|
||
it("finds unions", async () => { | ||
const result = await runNavigator(` | ||
union A { | ||
|
Oops, something went wrong.
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.
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.
Sorry for the late comment - but I think the
exit
methods still won't be executed if the pre-order callback sets no recursion. Maybe not a real issue if it's unlikely someone would use both pre and post-order callbacks.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.
oh I thought that was the expected behavior, but makes sense, I will follow up on this