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

Fix "View SARIF" context menu race. #598

Merged
merged 2 commits into from
Sep 29, 2020

Conversation

jcreedcmu
Copy link
Contributor

@jcreedcmu jcreedcmu commented Sep 29, 2020

Fixes #598.

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

I think your implementation is fine, though I think it can be cleaned up somewhat.

@@ -77,6 +86,9 @@ class HistoryTreeDataProvider
constructor(private ctx: ExtensionContext) { }

async getTreeItem(element: CompletedQuery): Promise<vscode.TreeItem> {
if (element.treeItem !== undefined)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nicer to convert treeItem to a getter on CompletedQuery. And move all this code into the getter. It avoids a type assertion on updateTreeItemContextValue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, no, this function needs to have the context of the treeview. The CompletedQuery doesn't have that information, or at least doesn't plausibly have it until the treeitem is created.

@@ -50,6 +50,15 @@ const SHOW_QUERY_TEXT_QUICK_EVAL_MSG = `\
*/
const FAILED_QUERY_HISTORY_ITEM_ICON = 'media/red-x.svg';

export async function updateTreeItemContextValue(element: CompletedQuery): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this make more sense as a member function on CompletedQuery?

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 think it makes sense as a member function on QueryHistoryManager, because of my attempting to decouple CompletedQuery from having to know too much about the whole QueryHistoryManager and the associated tree data provider. Already I don't love having to put the tree item itself as a field in CompletedQuery, but this is the simplest thing that I can see works.

@jcreedcmu
Copy link
Contributor Author

I tried testing this and it isn't working yet for me.

@jcreedcmu
Copy link
Contributor Author

I had forgotten to actually .refresh() the tree data provider. This now seems to fix the observed bug correctly.

Copy link
Contributor

@aeisenberg aeisenberg left a comment

Choose a reason for hiding this comment

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

Code is good. OK to merge if it is working.

@aeisenberg aeisenberg merged commit 5244a1c into github:main Sep 29, 2020
aeisenberg added a commit to aeisenberg/vscode-codeql that referenced this pull request Dec 15, 2020
This removes the cached treeItem that is a property of the
completedQuery. We should not be caching them since they are cached by
the vscode api itself. Instead, we should recreate whenever requested.

Also, this change fixes github#598 in a new way. Instead of adding the
context to the cached treeItem, we simply refresh only the item that has
changed. This is a fast operation.
aeisenberg added a commit to aeisenberg/vscode-codeql that referenced this pull request Dec 15, 2020
This removes the cached treeItem that is a property of the
completedQuery. We should not be caching them since they are cached by
the vscode api itself. Instead, we should recreate whenever requested.

Also, this change fixes github#598 in a new way. Instead of adding the
context to the cached treeItem, we simply refresh only the item that has
changed. This is a fast operation.
aeisenberg added a commit to aeisenberg/vscode-codeql that referenced this pull request Dec 16, 2020
This removes the cached treeItem that is a property of the
completedQuery. We should not be caching them since they are cached by
the vscode api itself. Instead, we should recreate whenever requested.

Also, this change fixes github#598 in a new way. Instead of adding the
context to the cached treeItem, we simply refresh only the item that has
changed. This is a fast operation.
aeisenberg added a commit that referenced this pull request Dec 16, 2020
This removes the cached treeItem that is a property of the
completedQuery. We should not be caching them since they are cached by
the vscode api itself. Instead, we should recreate whenever requested.

Also, this change fixes #598 in a new way. Instead of adding the
context to the cached treeItem, we simply refresh only the item that has
changed. This is a fast operation.
aofaof0907 pushed a commit to aofaof0907/vscode-codeql that referenced this pull request Jul 27, 2021
This removes the cached treeItem that is a property of the
completedQuery. We should not be caching them since they are cached by
the vscode api itself. Instead, we should recreate whenever requested.

Also, this change fixes github#598 in a new way. Instead of adding the
context to the cached treeItem, we simply refresh only the item that has
changed. This is a fast operation.
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