Skip to content

Fix "View SARIF" context menu race.#598

Merged
aeisenberg merged 2 commits intogithub:mainfrom
jcreedcmu:jcreed/view-sarif-bug
Sep 29, 2020
Merged

Fix "View SARIF" context menu race.#598
aeisenberg merged 2 commits intogithub:mainfrom
jcreedcmu:jcreed/view-sarif-bug

Conversation

@jcreedcmu
Copy link
Copy Markdown
Contributor

@jcreedcmu jcreedcmu commented Sep 29, 2020

Fixes #598.

Copy link
Copy Markdown
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.

constructor(private ctx: ExtensionContext) { }

async getTreeItem(element: CompletedQuery): Promise<vscode.TreeItem> {
if (element.treeItem !== undefined)
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.

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
Copy Markdown
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
Copy Markdown
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.

*/
const FAILED_QUERY_HISTORY_ITEM_ICON = 'media/red-x.svg';

export async function updateTreeItemContextValue(element: CompletedQuery): Promise<void> {
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.

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

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.

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
Copy Markdown
Contributor Author

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

@jcreedcmu
Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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