Skip to content

Commit 7cc7aa5

Browse files
committed
Add additional ide-api events
1 parent 6c8e513 commit 7cc7aa5

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

packages/ide-api/api.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ declare namespace ide {
158158
readonly notificationService: INotificationService;
159159
readonly menuRegistry: IMenuRegistry;
160160
readonly commandRegistry: ICommandRegistry;
161+
162+
onFileCreate(cb: (path: string) => void): void;
163+
onFileMove(cb: (path: string, target: string) => void): void;
164+
onFileDelete(cb: (path: string) => void): void;
165+
onFileSaved(cb: (path: string) => void): void;
166+
onFileCopy(cb: (path: string, target: string) => void): void;
167+
168+
onModelAdded(cb: (path: string, languageId: string) => void): void;
169+
onModelRemoved(cb: (path: string, languageId: string) => void): void;
170+
onModelLanguageChange(cb: (path: string, languageId: string, oldLanguageId: string) => void): void;
171+
172+
onTerminalAdded(cb: () => void): void;
173+
onTerminalRemoved(cb: () => void): void;
161174
};
162175

163176
export enum Severity {

packages/ide-api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coder/ide-api",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"typings": "api.d.ts",
55
"author": "Coder",
66
"license": "MIT",

packages/vscode/src/client.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import product from "./fill/product";
88
import "./vscode.scss";
99
import { MenuId, MenuRegistry } from "vs/platform/actions/common/actions";
1010
import { CommandsRegistry } from "vs/platform/commands/common/commands";
11+
import { IFileService, FileOperation } from "vs/platform/files/common/files";
12+
import { ITextFileService } from "vs/workbench/services/textfile/common/textfiles";
13+
import { IModelService } from "vs/editor/common/services/modelService";
14+
import { ITerminalService } from "vs/workbench/contrib/terminal/common/terminal";
1115
// NOTE: shouldn't import anything from VS Code here or anything that will
1216
// depend on a synchronous fill like `os`.
1317

@@ -34,6 +38,63 @@ class VSClient extends IdeClient {
3438
// tslint:disable-next-line:no-any
3539
statusbarService: getService<IStatusbarService>(IStatusbarService) as any,
3640
notificationService: getService<INotificationService>(INotificationService),
41+
42+
onFileCreate: (cb): void => {
43+
getService<IFileService>(IFileService).onAfterOperation((e) => {
44+
if (e.operation === FileOperation.CREATE) {
45+
cb(e.resource.path);
46+
}
47+
});
48+
},
49+
onFileMove: (cb): void => {
50+
getService<IFileService>(IFileService).onAfterOperation((e) => {
51+
if (e.operation === FileOperation.MOVE) {
52+
cb(e.resource.path, e.target ? e.target.resource.path : undefined!);
53+
}
54+
});
55+
},
56+
onFileDelete: (cb): void => {
57+
getService<IFileService>(IFileService).onAfterOperation((e) => {
58+
if (e.operation === FileOperation.DELETE) {
59+
cb(e.resource.path);
60+
}
61+
});
62+
},
63+
onFileSaved: (cb): void => {
64+
getService<ITextFileService>(ITextFileService).models.onModelSaved((e) => {
65+
cb(e.resource.path);
66+
});
67+
},
68+
onFileCopy: (cb): void => {
69+
getService<IFileService>(IFileService).onAfterOperation((e) => {
70+
if (e.operation === FileOperation.COPY) {
71+
cb(e.resource.path, e.target ? e.target.resource.path : undefined!);
72+
}
73+
});
74+
},
75+
76+
onModelAdded: (cb): void => {
77+
getService<IModelService>(IModelService).onModelAdded((e) => {
78+
cb(e.uri.path, e.getLanguageIdentifier().language);
79+
});
80+
},
81+
onModelRemoved: (cb): void => {
82+
getService<IModelService>(IModelService).onModelRemoved((e) => {
83+
cb(e.uri.path, e.getLanguageIdentifier().language);
84+
});
85+
},
86+
onModelLanguageChange: (cb): void => {
87+
getService<IModelService>(IModelService).onModelModeChanged((e) => {
88+
cb(e.model.uri.path, e.model.getLanguageIdentifier().language, e.oldModeId);
89+
});
90+
},
91+
92+
onTerminalAdded: (cb): void => {
93+
getService<ITerminalService>(ITerminalService).onInstanceCreated(() => cb());
94+
},
95+
onTerminalRemoved: (cb): void => {
96+
getService<ITerminalService>(ITerminalService).onInstanceDisposed(() => cb());
97+
},
3798
},
3899

39100
// @ts-ignore

0 commit comments

Comments
 (0)