Skip to content
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

feat: function signature detection #1699

Merged
merged 7 commits into from
May 10, 2023

Conversation

lkingland
Copy link
Member

  • 🎁 function signatures with detector

Adds an enumeration of base accepted method signatures, and implements a detector for go functions.
Introduces the concept of "Instanced" functions.
Mocks up where additional detectors would be added using a stubbed Python detector.

/kind enhancement

Adds an enumeration of base accepted method signatures, and implements a
detector for go functions.
@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/enhancement labels Apr 25, 2023
@knative-prow
Copy link

knative-prow bot commented Apr 25, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lkingland

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 25, 2023
@knative-prow knative-prow bot requested review from dsimansk and jrangelramos April 25, 2023 04:37
@knative-prow knative-prow bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 25, 2023
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Patch coverage: 64.55% and project coverage change: +0.02 🎉

Comparison is base (506cb71) 62.84% compared to head (3f49a30) 62.87%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1699      +/-   ##
==========================================
+ Coverage   62.84%   62.87%   +0.02%     
==========================================
  Files          93       94       +1     
  Lines       11967    12298     +331     
==========================================
+ Hits         7521     7732     +211     
- Misses       3757     3865     +108     
- Partials      689      701      +12     
Flag Coverage Δ
e2e-test 38.73% <0.00%> (-0.13%) ⬇️
e2e-test-oncluster 34.19% <0.00%> (-0.45%) ⬇️
e2e-test-oncluster-runtime 29.31% <0.00%> (?)
e2e-test-runtime-go 27.87% <0.00%> (?)
e2e-test-runtime-node 29.00% <0.00%> (?)
e2e-test-runtime-python 29.00% <0.00%> (?)
e2e-test-runtime-quarkus 29.13% <0.00%> (?)
e2e-test-runtime-springboot 28.05% <0.00%> (?)
e2e-test-runtime-typescript 29.10% <0.00%> (?)
integration-tests 50.28% <64.55%> (+0.28%) ⬆️
unit-tests-macos-latest 48.76% <64.55%> (-0.08%) ⬇️
unit-tests-ubuntu-latest 49.66% <64.55%> (-0.08%) ⬇️
unit-tests-windows-latest 48.81% <64.55%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/functions/signatures.go 64.55% <64.55%> (ø)

... and 21 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lkingland lkingland mentioned this pull request Apr 25, 2023
14 tasks
@lkingland lkingland marked this pull request as ready for review April 25, 2023 15:22
@knative-prow knative-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 25, 2023
@knative-prow knative-prow bot requested review from dsimansk and navidshaikh April 25, 2023 15:22
Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. Just a few small nits to address for consistency across the codebase. Currently, none of the other runtimes has instanced based functions, but I suppose that shouldn't really matter and may come over time.

return
}
for _, file := range files {
filename := filepath.Join(dir, file.Name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it could be a condition that the filename be handle.go

Copy link
Member Author

@lkingland lkingland May 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since most languages don't have any file name requirements, I didn't want us to impose anything.
Scanning each file in the directory looking for the expected signature should be trivially fast.
Also, I personally think that, now that we support "instanced" function signatures, the filename for those should be "function.go". So this is compatible with both templates: static handle.go and an instanced function.go. Or, if a user is creating an HTTP Rest API at api.example.com, perhapse they want their code in api.go 🤷🏻

}

func (d goDetector) hasFunctionDeclaration(filename, function string) bool {
astFile, err := parser.ParseFile(token.NewFileSet(), filename, nil, parser.SkipObjectResolution)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a golang parser for all of our runtimes! :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that be helpful! I wouldn't be suprised if there were a parser for all of them already out there.

Fortunately, we don't need a full parser; we just need to be able to split on tokens and have enough of a state machine to know if it's inside of a block comment or not. So even if we need to write a small parser for each language ourselves; it should be fairly straightforward. But let's hope they already exist! 🤞🏻

lkingland and others added 5 commits May 10, 2023 11:32
Co-authored-by: Lance Ball <lball@redhat.com>
Co-authored-by: Lance Ball <lball@redhat.com>
Co-authored-by: Lance Ball <lball@redhat.com>
Co-authored-by: Lance Ball <lball@redhat.com>
Co-authored-by: Lance Ball <lball@redhat.com>
@lkingland lkingland requested a review from lance May 10, 2023 05:48
@lance
Copy link
Member

lance commented May 10, 2023

/lgtm

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 10, 2023
@knative-prow knative-prow bot merged commit f58770d into knative:main May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/enhancement lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants