From 7cc7aa51aa7a74db90869905920fe3ea26ffee55 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 12 Mar 2019 17:43:53 -0400 Subject: [PATCH] Add additional ide-api events --- packages/ide-api/api.d.ts | 13 ++++++++ packages/ide-api/package.json | 2 +- packages/vscode/src/client.ts | 61 +++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/packages/ide-api/api.d.ts b/packages/ide-api/api.d.ts index b9b4e94b..3faeafc8 100644 --- a/packages/ide-api/api.d.ts +++ b/packages/ide-api/api.d.ts @@ -158,6 +158,19 @@ declare namespace ide { readonly notificationService: INotificationService; readonly menuRegistry: IMenuRegistry; readonly commandRegistry: ICommandRegistry; + + onFileCreate(cb: (path: string) => void): void; + onFileMove(cb: (path: string, target: string) => void): void; + onFileDelete(cb: (path: string) => void): void; + onFileSaved(cb: (path: string) => void): void; + onFileCopy(cb: (path: string, target: string) => void): void; + + onModelAdded(cb: (path: string, languageId: string) => void): void; + onModelRemoved(cb: (path: string, languageId: string) => void): void; + onModelLanguageChange(cb: (path: string, languageId: string, oldLanguageId: string) => void): void; + + onTerminalAdded(cb: () => void): void; + onTerminalRemoved(cb: () => void): void; }; export enum Severity { diff --git a/packages/ide-api/package.json b/packages/ide-api/package.json index 69496bab..1435b94e 100644 --- a/packages/ide-api/package.json +++ b/packages/ide-api/package.json @@ -1,6 +1,6 @@ { "name": "@coder/ide-api", - "version": "1.0.2", + "version": "1.0.3", "typings": "api.d.ts", "author": "Coder", "license": "MIT", diff --git a/packages/vscode/src/client.ts b/packages/vscode/src/client.ts index 562ca37c..0c824666 100644 --- a/packages/vscode/src/client.ts +++ b/packages/vscode/src/client.ts @@ -8,6 +8,10 @@ import product from "./fill/product"; import "./vscode.scss"; import { MenuId, MenuRegistry } from "vs/platform/actions/common/actions"; import { CommandsRegistry } from "vs/platform/commands/common/commands"; +import { IFileService, FileOperation } from "vs/platform/files/common/files"; +import { ITextFileService } from "vs/workbench/services/textfile/common/textfiles"; +import { IModelService } from "vs/editor/common/services/modelService"; +import { ITerminalService } from "vs/workbench/contrib/terminal/common/terminal"; // NOTE: shouldn't import anything from VS Code here or anything that will // depend on a synchronous fill like `os`. @@ -34,6 +38,63 @@ class VSClient extends IdeClient { // tslint:disable-next-line:no-any statusbarService: getService(IStatusbarService) as any, notificationService: getService(INotificationService), + + onFileCreate: (cb): void => { + getService(IFileService).onAfterOperation((e) => { + if (e.operation === FileOperation.CREATE) { + cb(e.resource.path); + } + }); + }, + onFileMove: (cb): void => { + getService(IFileService).onAfterOperation((e) => { + if (e.operation === FileOperation.MOVE) { + cb(e.resource.path, e.target ? e.target.resource.path : undefined!); + } + }); + }, + onFileDelete: (cb): void => { + getService(IFileService).onAfterOperation((e) => { + if (e.operation === FileOperation.DELETE) { + cb(e.resource.path); + } + }); + }, + onFileSaved: (cb): void => { + getService(ITextFileService).models.onModelSaved((e) => { + cb(e.resource.path); + }); + }, + onFileCopy: (cb): void => { + getService(IFileService).onAfterOperation((e) => { + if (e.operation === FileOperation.COPY) { + cb(e.resource.path, e.target ? e.target.resource.path : undefined!); + } + }); + }, + + onModelAdded: (cb): void => { + getService(IModelService).onModelAdded((e) => { + cb(e.uri.path, e.getLanguageIdentifier().language); + }); + }, + onModelRemoved: (cb): void => { + getService(IModelService).onModelRemoved((e) => { + cb(e.uri.path, e.getLanguageIdentifier().language); + }); + }, + onModelLanguageChange: (cb): void => { + getService(IModelService).onModelModeChanged((e) => { + cb(e.model.uri.path, e.model.getLanguageIdentifier().language, e.oldModeId); + }); + }, + + onTerminalAdded: (cb): void => { + getService(ITerminalService).onInstanceCreated(() => cb()); + }, + onTerminalRemoved: (cb): void => { + getService(ITerminalService).onInstanceDisposed(() => cb()); + }, }, // @ts-ignore