Skip to content

Commit 1c3b33b

Browse files
authored
Load model directly from vscode (codesandbox#3416)
* Don't apply nametag updates if model is disposed * Directly load model instead of fetching it from the editor
1 parent 9ef60c1 commit 1c3b33b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { actions, dispatch } from 'codesandbox-api';
1010
import { css } from 'glamor';
1111
import { TextOperation } from 'ot';
1212

13-
import { getCurrentModel, getCurrentModelPath } from './utils';
13+
import { getCurrentModelPath } from './utils';
1414

1515
// @ts-ignore
1616
const fadeIn = css.keyframes('fadeIn', {
@@ -110,17 +110,15 @@ export class ModelsHandler {
110110
const moduleModel = this.getModuleModel(module);
111111

112112
if (getCurrentModelPath(this.editorApi) !== module.path) {
113-
const file = await this.editorApi.openFile(module.path);
114-
const model = file.getModel();
115-
116-
moduleModel.model = Promise.resolve(model);
113+
await this.editorApi.openFile(module.path);
114+
}
117115

118-
this.updateUserSelections(module, moduleModel.selections);
119-
} else {
120-
const model = getCurrentModel(this.editorApi);
116+
moduleModel.model = await this.editorApi.textFileService.models
117+
.loadOrCreate(this.monaco.Uri.file('/sandbox' + module.path))
118+
.then(textFileEditorModel => textFileEditorModel.load())
119+
.then(textFileEditorModel => textFileEditorModel.textEditorModel);
121120

122-
moduleModel.model = Promise.resolve(model);
123-
}
121+
this.updateUserSelections(module, moduleModel.selections);
124122

125123
return moduleModel.model;
126124
};

0 commit comments

Comments
 (0)