Skip to content

Commit 32d1b6f

Browse files
Fix feature flag for container lsp (codesandbox#3577)
* Fix feature flag for container lsp * Revert 6e8d7e6 Co-authored-by: Michaël De Boey <[email protected]>
1 parent c2968ba commit 32d1b6f

File tree

6 files changed

+50
-27
lines changed

6 files changed

+50
-27
lines changed

packages/app/src/app/overmind/effects/vscode/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
SandboxFs,
1212
Settings,
1313
} from '@codesandbox/common/lib/types';
14-
import { CONTAINER_LSP } from '@codesandbox/common/lib/utils/feature-flags';
1514
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
1615
import {
1716
NotificationMessage,
@@ -343,7 +342,7 @@ export class VSCodeEffect {
343342
//
344343
}
345344

346-
if (isServer && CONTAINER_LSP === 'true') {
345+
if (isServer && this.options.getCurrentUser()?.experiments.containerLsp) {
347346
childProcess.addDefaultForkHandler(this.createContainerForkHandler());
348347
const socket = this.createWebsocketFSRequest();
349348
const cache = await this.createFileSystem('WebsocketFS', {

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
WindowOrientation,
99
} from '@codesandbox/common/lib/types';
1010
import { getTextOperation } from '@codesandbox/common/lib/utils/diff';
11-
import { CONTAINER_LSP } from '@codesandbox/common/lib/utils/feature-flags';
1211
import { convertTypeToStatus } from '@codesandbox/common/lib/utils/notifications';
1312
import { Action, AsyncAction } from 'app/overmind';
1413
import { withLoadApp, withOwnedSandbox } from 'app/overmind/factories';
@@ -121,7 +120,7 @@ export const sandboxChanged: AsyncAction<{ id: string }> = withLoadApp<{
121120
state.editor.modulesByPath = fs;
122121
});
123122

124-
if (CONTAINER_LSP === 'true' && !sandbox.owned) {
123+
if (sandbox.featureFlags?.containerLsp && !sandbox.owned) {
125124
effects.vscode.setReadOnly(true);
126125
effects.notificationToast.add({
127126
message:

packages/app/src/app/overmind/namespaces/preferences/actions.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,30 @@ export const zenModeToggled: Action = ({ state }) => {
131131
export const codeMirrorForced: Action = ({ state }) => {
132132
state.preferences.settings.codeMirror = true;
133133
};
134+
135+
export const toggleContainerLspExperiment: AsyncAction = async ({
136+
effects,
137+
state,
138+
}) => {
139+
if (!state.user) {
140+
return;
141+
}
142+
try {
143+
await effects.api.updateExperiments({
144+
container_lsp: !state.user.experiments.containerLsp,
145+
});
146+
state.user.experiments.containerLsp = !state.user.experiments.containerLsp;
147+
// Allow the flush to go through and flip button
148+
requestAnimationFrame(() => {
149+
if (
150+
effects.browser.confirm(
151+
'We need to refresh for this to take effect, or you can refresh later'
152+
)
153+
) {
154+
effects.browser.reload();
155+
}
156+
});
157+
} catch (error) {
158+
effects.notificationToast.error('Unable to toggl LSP experiment');
159+
}
160+
};
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
1-
import { CONTAINER_LSP } from '@codesandbox/common/lib/utils/feature-flags';
2-
import React, { useState, useEffect } from 'react';
1+
import React, { FunctionComponent } from 'react';
32
import { useOvermind } from 'app/overmind';
43
import { SubDescription, PaddedPreference } from '../elements';
54

6-
export const ContainerLSP: React.FunctionComponent = () => {
7-
const { state } = useOvermind();
8-
const [containerLSP, setContainerLSP] = useState(false);
9-
useEffect(() => {
10-
if (CONTAINER_LSP === 'true') {
11-
return setContainerLSP(true);
12-
}
13-
return setContainerLSP(false);
14-
}, []);
5+
export const ContainerLSP: FunctionComponent = () => {
6+
const {
7+
actions: {
8+
preferences: { toggleContainerLspExperiment },
9+
},
10+
state: {
11+
user: {
12+
experiments: { containerLsp },
13+
},
14+
},
15+
} = useOvermind();
1516

16-
const setValue = (val: boolean) => {
17-
setContainerLSP(val);
18-
window.localStorage.setItem('CONTAINER_LSP', val.toString());
19-
location.reload();
20-
};
21-
22-
return state.user ? (
17+
return (
2318
<>
2419
<PaddedPreference
20+
setValue={() => toggleContainerLspExperiment()}
2521
title="Use container language server"
26-
type="boolean"
27-
value={containerLSP}
28-
setValue={val => setValue(val)}
2922
tooltip="Language server"
23+
type="boolean"
24+
value={containerLsp}
3025
/>
26+
3127
<SubDescription>
3228
As part of making containers more powerful we now allow the language
3329
server to run there. Please help us test it :-)
3430
</SubDescription>
3531
</>
36-
) : null;
32+
);
3733
};

packages/common/src/types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ export type Sandbox = {
319319
userLiked: boolean;
320320
modules: Module[];
321321
directories: Directory[];
322+
featureFlags: {
323+
[key: string]: boolean;
324+
};
322325
collection?: {
323326
path: string;
324327
};

packages/common/src/utils/feature-flags.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
it's a TS file, so you can add whatever logic you want as long as it's static
77
*/
88

9-
export const CONTAINER_LSP = localStorage.getItem('CONTAINER_LSP') || false;
109
export const REDESIGNED_SIDEBAR =
1110
localStorage.getItem('REDESIGNED_SIDEBAR') || false;

0 commit comments

Comments
 (0)