Skip to content

Commit

Permalink
Fix isl not detecting workspace folder changes without reloading
Browse files Browse the repository at this point in the history
Summary: It seems we were not properly subscribing to changes in the vscode workspace folders. We used `onConnectOrReconnect` inside the lazyAtom, which means it was not triggered on first connect. Since reconnects don't happen in most cases (maybe never for vscode connection...?), it would never actually subscribe. Instead, we could either move this to a not lazy atom, or make it just call the subscribe directly. I opt to make the atom not lazy, since we use this in the cwdSelector immediately on startup, there's no real use having it be lazy. Maybe that made sense when the cwd dropdown didn't use this state.

Reviewed By: quark-zju

Differential Revision: D57136047

fbshipit-source-id: 8298b8b94b06e109f78240d20cb42014f3d18e00
  • Loading branch information
evangrayk authored and facebook-github-bot committed May 9, 2024
1 parent 79ae03b commit 2d28ee9
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions addons/isl/src/CwdSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {lazyAtom, writeAtom} from './jotaiUtils';
import {serverCwd} from './repositoryData';
import {repositoryInfo} from './serverAPIState';
import {registerCleanup, registerDisposable} from './utils';
import {useAtomValue} from 'jotai';
import {atom, useAtomValue} from 'jotai';
import {Icon} from 'shared/Icon';
import {KeyCode, Modifier} from 'shared/KeyboardShortcuts';
import {basename} from 'shared/utils';
Expand Down Expand Up @@ -60,19 +60,16 @@ function getRepoLabel(repoRoot: AbsolutePath, cwd: string) {
return repoBasename + repoRelativeCwd;
}

export const availableCwds = lazyAtom<Array<CwdInfo>>(() => {
// Only request `subscribeToAvailableCwds` when first read the atom.
registerCleanup(
availableCwds,
serverAPI.onConnectOrReconnect(() => {
serverAPI.postMessage({
type: 'platform/subscribeToAvailableCwds',
});
}),
import.meta.hot,
);
return [];
}, []);
export const availableCwds = atom<Array<CwdInfo>>([]);
registerCleanup(
availableCwds,
serverAPI.onConnectOrReconnect(() => {
serverAPI.postMessage({
type: 'platform/subscribeToAvailableCwds',
});
}),
import.meta.hot,
);

registerDisposable(
availableCwds,
Expand Down

0 comments on commit 2d28ee9

Please sign in to comment.