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

Utility class to detect Typescript functions that can possibly be used as Lambda Function Handlers. #142

Merged
merged 8 commits into from
Oct 29, 2018

Conversation

awschristou
Copy link
Contributor

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Infrastructure (change which improves the lifecycle management (CI/CD, build, package, deploy, lint, etc) of the application, but does not change functionality.)
  • Technical debt (change which improves the maintainability of the codebase, but does not change functionality)
  • Testing (change which modifies or adds test coverage, but does not change functionality)
  • Documentation (change which modifies or adds documentation, but does not change functionality)

Description

This code provides a way of locating Typescript functions that can be used as Lambda Function Handlers. This uses the Typescript engine instead of Symbol Information that can be surfaced by VS Code, since VS Code doesn't seem to provide parameter information for functions and methods.

Motivation and Context

Related Issue(s)

#140 - while this is not surfaced presently, it will be used in #135 and #136 when CodeLens looks to determine which functions can be invoked/debugged.

Testing

Screenshots (if appropriate)

Checklist

  • I have read the README document
  • I have read the CONTRIBUTING document
  • My code follows the code style of this project
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@awschristou awschristou requested a review from mpiroc October 23, 2018 22:26
package.json Outdated Show resolved Hide resolved
src/shared/typescriptLambdaHandlerSearch.ts Outdated Show resolved Hide resolved
src/shared/typescriptLambdaHandlerSearch.ts Outdated Show resolved Hide resolved
src/shared/typescriptLambdaHandlerSearch.ts Outdated Show resolved Hide resolved
src/shared/typescriptLambdaHandlerSearch.ts Outdated Show resolved Hide resolved
* @description Looks for functions that appear to be valid Lambda Function Handlers.
* @returns A collection of information for each detected candidate.
*/
public async findCandidateLambdaHandlers(): Promise<LambdaHandlerCandidate[]> {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • What's the performance on very large (i.e. 10,000+ lines, many functions) files?
  • Will this be called from the UI thread?
  • Is it feasible to only parse code that's currently in the user's viewport (i.e., not scrolled out of sight)?
  • Is it feasible to return a Promise<LambdaHandlerCandidate | undefined>[] (or a Promise<Promise<LambdaHandlerCandidate | undefined>[]>) instead? It would be awesome if we could update the view for each function independently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I've seen of CodeLens, extensions are given the file as a whole, not for a viewport.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've put the performance investigation into #145

src/shared/typescriptLambdaHandlerSearch.ts Outdated Show resolved Hide resolved
src/shared/typescriptLambdaHandlerSearch.ts Show resolved Hide resolved
src/test/samples/javascript/sampleClasses.js Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Oct 24, 2018

Codecov Report

Merging #142 into develop will increase coverage by 4.74%.
The diff coverage is 99.08%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #142      +/-   ##
===========================================
+ Coverage    39.92%   44.66%   +4.74%     
===========================================
  Files           48       49       +1     
  Lines         1250     1359     +109     
  Branches       155      189      +34     
===========================================
+ Hits           499      607     +108     
- Misses         751      752       +1
Impacted Files Coverage Δ
src/shared/typescriptLambdaHandlerSearch.ts 99.08% <99.08%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f695ade...75eddd3. Read the comment docs.

src/shared/typescriptLambdaHandlerSearch.ts Show resolved Hide resolved
* @param targetFunctionNames Names of functions of interest
*/
private static isValidFunctionAssignment(expression: ts.Expression): boolean {
if (ts.isFunctionLike(expression)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, does isFunctionLike support cases like = function() { /* ... */ }? The whole API is undocumented, which makes it hard to review 😢

Copy link
Contributor

@mpiroc mpiroc left a comment

Choose a reason for hiding this comment

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

Approved pending validation of performance on large files.

@awschristou awschristou merged commit ce746c6 into develop Oct 29, 2018
@awschristou awschristou deleted the awschristou/get-symbols-from-file branch October 29, 2018 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants