Skip to content

Fix error messages for ast viewers and update caching#753

Merged
aeisenberg merged 1 commit intogithub:mainfrom
aeisenberg:aeisenberg/ast-viewer-caching
Feb 11, 2021
Merged

Fix error messages for ast viewers and update caching#753
aeisenberg merged 1 commit intogithub:mainfrom
aeisenberg:aeisenberg/ast-viewer-caching

Conversation

@aeisenberg
Copy link
Copy Markdown
Contributor

@aeisenberg aeisenberg commented Feb 11, 2021

This commit does two things:

  1. Add more appropriate error messages when asts can't be viewed.
  2. Make better use of cached operations for asts. In the past, we were
    not actually using cached operations. Each time an ast view request
    occurred, we created a new TemplatePrintAstProvider instance. With this
    change, we reuse the TemplatePrintAstProvider between calls and ensure
    that an AST that is called once is reused on subsequent calls.

I received complaints from users such as @sj that AST viewing was erroring out and it wasn't clear why it was happening.

And the second part of this change will make subsequent calls to view an AST of a file extremely fast.

Checklist

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • [n/a] Issues have been created for any UI or other user-facing changes made by this pull request.
  • [n/a] @github/docs-content-dsp has been cc'd in all issues for UI or other user-facing changes made by this pull request.

This commit does two things:

1. Add more appropriate error messages when asts can't be viewed.
2. Make better use of cached operations for asts. In the past, we were
not actually using cached operations. Each time an ast view request
occurred, we created a new TemplatePrintAstProvider instance. With this
change, we reuse the TemplatePrintAstProvider between calls and ensure
that an AST that is called once is reused on subsequent calls.
@aeisenberg aeisenberg force-pushed the aeisenberg/ast-viewer-caching branch from 5af9c2a to 514d8a8 Compare February 11, 2021 22:37
}
const queryResults = await this.cache.get(document.uri.toString(), progress, token);

return new AstBuilder(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like we now unconditionally return an AstBuilder. Do you still need to return undefined if we didn't find any results?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The cached operation always returns QueryWithResults or it throws. Since the call to get the cached item always has the same type as the operation itself, we are guaranteed that the value will never be undefined.

@aeisenberg aeisenberg merged commit be9084e into github:main Feb 11, 2021
@aeisenberg aeisenberg deleted the aeisenberg/ast-viewer-caching branch February 11, 2021 23:34
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.

2 participants