summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNate Sesti <33237525+sestinj@users.noreply.github.com>2023-06-02 23:08:14 +0000
committerNate Sesti <33237525+sestinj@users.noreply.github.com>2023-06-02 23:08:14 +0000
commitae4a5860518eb18e9350c9532995b673c8a421ae (patch)
tree5b5289ce239da9d6505c9bbc654516b924ad4fea
parent23f7462073b78fb5f87d370b050fab9a9def5119 (diff)
downloadsncontinue-ae4a5860518eb18e9350c9532995b673c8a421ae.tar.gz
sncontinue-ae4a5860518eb18e9350c9532995b673c8a421ae.tar.bz2
sncontinue-ae4a5860518eb18e9350c9532995b673c8a421ae.zip
Fixed codespaces showTextDocument error
-rw-r--r--extension/src/util/vscode.ts46
1 files changed, 29 insertions, 17 deletions
diff --git a/extension/src/util/vscode.ts b/extension/src/util/vscode.ts
index 59e1ae8e..a76b53c7 100644
--- a/extension/src/util/vscode.ts
+++ b/extension/src/util/vscode.ts
@@ -128,28 +128,40 @@ export async function readFileAtRange(
});
}
+let showTextDocumentInProcess = false;
+
export function openEditorAndRevealRange(
editorFilename: string,
range?: vscode.Range,
viewColumn?: vscode.ViewColumn
): Promise<vscode.TextEditor> {
return new Promise((resolve, _) => {
- // Check if the editor is already open
- if (editorFilename.startsWith("file://")) {
- editorFilename = editorFilename.slice(7);
- }
- vscode.workspace.openTextDocument(editorFilename).then((doc) => {
- vscode.window
- .showTextDocument(
- doc,
- getViewColumnOfFile(editorFilename) || viewColumn
- )
- .then((editor) => {
- if (range) {
- editor.revealRange(range);
- }
- resolve(editor);
- });
- });
+ vscode.workspace.openTextDocument(editorFilename).then(async (doc) => {
+ try {
+ // An error is thrown mysteriously if you open two documents in parallel, hence this
+ while (showTextDocumentInProcess) {
+ await new Promise((resolve) => {
+ setInterval(() => {
+ resolve(null);
+ }, 200);
+ })
+ }
+ showTextDocumentInProcess = true;
+ vscode.window
+ .showTextDocument(
+ doc,
+ getViewColumnOfFile(editorFilename) || viewColumn
+ )
+ .then((editor) => {
+ if (range) {
+ editor.revealRange(range);
+ }
+ resolve(editor);
+ showTextDocumentInProcess = false;
+ })
+ } catch (err) {
+ console.log(err);
+ }
+ });
});
}