Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vscode api enum #333

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions client/src/vscode-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import * as vscode from "vscode";
import type * as vscode from "vscode";
import { URI } from "vscode-uri"
import { Disposable } from "./disposable";
import {
Expand Down Expand Up @@ -119,6 +119,14 @@ export function createVSCodeApi(servicesProvider: Services.Provider): typeof vsc
}
}

enum TextDocumentChangeReason {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question for my understanding: We have to redefine the enum because otherwise vscode api is exposed in the listener?

Copy link
Collaborator Author

@CGNonofr CGNonofr Mar 21, 2022

Choose a reason for hiding this comment

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

The error was at line reason: isUndoing ? vscode.TextDocumentChangeReason.Undo : isRedoing ? vscode.TextDocumentChangeReason.Redo : undefined

vscode.TextDocumentChangeReason wasn't defined so it was crashing

I hope I understood your question

Copy link
Collaborator

@kaisalmen kaisalmen Mar 21, 2022

Choose a reason for hiding this comment

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

Yes, you understood me. Thanks. 👍🙂 Just by looking at the PR without having deep knowledge of the project yet doesn't make the problem directly clear. That's why import type (did not know it and looked it up) is very helpful here as it immediately makes the issue obvious.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 The same way we need to re-implement all vscode.* interfaces, enums in typescript are transpiled into objects, and we need those at runtime

/** The text change is caused by an undo operation. */
Undo = 1,

/** The text change is caused by an redo operation. */
Redo = 2,
}

const workspace: typeof vscode.workspace = {
fs: new EmptyFileSystem(),
workspaceFile: undefined,
Expand Down Expand Up @@ -218,7 +226,7 @@ export function createVSCodeApi(servicesProvider: Services.Provider): typeof vsc
l({
document: <any>textDocument,
contentChanges: <any>contentChanges,
reason: isUndoing ? vscode.TextDocumentChangeReason.Undo : isRedoing ? vscode.TextDocumentChangeReason.Redo : undefined
reason: isUndoing ? TextDocumentChangeReason.Undo : isRedoing ? TextDocumentChangeReason.Redo : undefined
});
}, undefined, disposables);
}
Expand Down Expand Up @@ -968,7 +976,8 @@ export function createVSCodeApi(servicesProvider: Services.Provider): typeof vsc
DiagnosticSeverity: ServicesModule.DiagnosticSeverity,
EventEmitter: ServicesModule.Emitter,
CancellationTokenSource,
ProgressLocation: ServicesModule.ProgressLocation
ProgressLocation: ServicesModule.ProgressLocation,
TextDocumentChangeReason
};

return partialApi as any;
Expand Down