Skip to content

Fix collapseAll command when no folder is open#180330

Merged
lramos15 merged 3 commits intomicrosoft:mainfrom
tomheaton:fix-collapseAll
Apr 19, 2023
Merged

Fix collapseAll command when no folder is open#180330
lramos15 merged 3 commits intomicrosoft:mainfrom
tomheaton:fix-collapseAll

Conversation

@tomheaton
Copy link
Contributor

Description

This PR adds a null check before casting a view to ExplorerView and running collapseAll, to avoid a potential TypeError when the view is null.

Changes Made

I added a check for null before casting to ExplorerView and running collapseAll, as shown in this code snippet:

if (view !== null) {
  const explorerView = view as ExplorerView;
  explorerView.collapseAll();
}

Testing Done

I tested this change in Code OSS dev, both with and without the changed code, to verify that the view is properly collapsed when it is not null.

Screenshots

Error Message Before Fix

image

Fix in Action

no error message

@lramos15 lramos15 added this to the April 2023 milestone Apr 19, 2023
Copy link
Member

@lramos15 lramos15 left a comment

Choose a reason for hiding this comment

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

Thanks!

const explorerView = viewsService.getViewWithId(VIEW_ID) as ExplorerView;
explorerView.collapseAll();
const view = viewsService.getViewWithId(VIEW_ID);
if (view !== null) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we want if (view) to cover null and undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since the type of view is IView | null I didn't think so

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(normally I would do that but because big codebase I wanted it to be an explicit check to avoid confusion)

@lramos15 lramos15 merged commit 86528d8 into microsoft:main Apr 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants