Skip to content

Commit

Permalink
feat: cancelable verify+upload
Browse files Browse the repository at this point in the history
Closes #1199

Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Feb 8, 2024
1 parent cc644a2 commit 4810de9
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 175 deletions.
124 changes: 72 additions & 52 deletions arduino-ide-extension/src/browser/contributions/contribution.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,89 @@
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import {
inject,
injectable,
interfaces,
postConstruct,
} from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri';
import { ILogger } from '@theia/core/lib/common/logger';
import {
Disposable,
DisposableCollection,
} from '@theia/core/lib/common/disposable';
import { Saveable } from '@theia/core/lib/browser/saveable';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { MaybePromise } from '@theia/core/lib/common/types';
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
import { MessageService } from '@theia/core/lib/common/message-service';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { open, OpenerService } from '@theia/core/lib/browser/opener-service';
import {
MenuModelRegistry,
MenuContribution,
} from '@theia/core/lib/common/menu';
FrontendApplication,
FrontendApplicationContribution,
} from '@theia/core/lib/browser/frontend-application';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
import {
KeybindingRegistry,
KeybindingContribution,
KeybindingRegistry,
} from '@theia/core/lib/browser/keybinding';
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
import { OpenerService, open } from '@theia/core/lib/browser/opener-service';
import { Saveable } from '@theia/core/lib/browser/saveable';
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
import {
TabBarToolbarContribution,
TabBarToolbarRegistry,
} from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import {
FrontendApplicationContribution,
FrontendApplication,
} from '@theia/core/lib/browser/frontend-application';
import { CancellationToken } from '@theia/core/lib/common/cancellation';
import {
Command,
CommandRegistry,
CommandContribution,
CommandRegistry,
CommandService,
} from '@theia/core/lib/common/command';
import { SettingsService } from '../dialogs/settings/settings';
import {
CurrentSketch,
SketchesServiceClientImpl,
} from '../sketches-service-client-impl';
Disposable,
DisposableCollection,
} from '@theia/core/lib/common/disposable';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { ILogger } from '@theia/core/lib/common/logger';
import {
MenuContribution,
MenuModelRegistry,
} from '@theia/core/lib/common/menu';
import { MessageService } from '@theia/core/lib/common/message-service';
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
import { nls } from '@theia/core/lib/common/nls';
import { MaybePromise, isObject } from '@theia/core/lib/common/types';
import URI from '@theia/core/lib/common/uri';
import {
inject,
injectable,
interfaces,
postConstruct,
} from '@theia/core/shared/inversify';
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { NotificationManager } from '@theia/messages/lib/browser/notifications-manager';
import { OutputChannelSeverity } from '@theia/output/lib/browser/output-channel';
import { MainMenuManager } from '../../common/main-menu-manager';
import { userAbort } from '../../common/nls';
import {
SketchesService,
FileSystemExt,
Sketch,
CoreService,
CoreError,
CoreService,
FileSystemExt,
ResponseServiceClient,
Sketch,
SketchesService,
} from '../../common/protocol';
import {
ExecuteWithProgress,
UserAbortApplicationError,
} from '../../common/protocol/progressible';
import { ArduinoPreferences } from '../arduino-preferences';
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
import { nls } from '@theia/core';
import { OutputChannelManager } from '../theia/output/output-channel';
import { ClipboardService } from '@theia/core/lib/browser/clipboard-service';
import { ExecuteWithProgress } from '../../common/protocol/progressible';
import { BoardsServiceProvider } from '../boards/boards-service-provider';
import { BoardsDataStore } from '../boards/boards-data-store';
import { NotificationManager } from '@theia/messages/lib/browser/notifications-manager';
import { MessageType } from '@theia/core/lib/common/message-service-protocol';
import { WorkspaceService } from '../theia/workspace/workspace-service';
import { MainMenuManager } from '../../common/main-menu-manager';
import { BoardsServiceProvider } from '../boards/boards-service-provider';
import { ConfigServiceClient } from '../config/config-service-client';
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
import { DialogService } from '../dialog-service';
import { SettingsService } from '../dialogs/settings/settings';
import {
CurrentSketch,
SketchesServiceClientImpl,
} from '../sketches-service-client-impl';
import { ApplicationConnectionStatusContribution } from '../theia/core/connection-status-service';
import { OutputChannelManager } from '../theia/output/output-channel';
import { WorkspaceService } from '../theia/workspace/workspace-service';

export {
Command,
CommandRegistry,
MenuModelRegistry,
KeybindingRegistry,
MenuModelRegistry,
Sketch,
TabBarToolbarRegistry,
URI,
Sketch,
open,
};

Expand Down Expand Up @@ -247,6 +253,12 @@ export abstract class CoreServiceContribution extends SketchContribution {
}

protected handleError(error: unknown): void {
if (isObject(error) && UserAbortApplicationError.is(error)) {
this.outputChannelManager
.getChannel('Arduino')
.appendLine(userAbort, OutputChannelSeverity.Warning);
return;
}
this.tryToastErrorMessage(error);
}

Expand Down Expand Up @@ -293,7 +305,13 @@ export abstract class CoreServiceContribution extends SketchContribution {
protected async doWithProgress<T>(options: {
progressText: string;
keepOutput?: boolean;
task: (progressId: string, coreService: CoreService) => Promise<T>;
task: (
progressId: string,
coreService: CoreService,
cancellationToken?: CancellationToken
) => Promise<T>;
// false by default
cancelable?: boolean;
}): Promise<T> {
const toDisposeOnComplete = new DisposableCollection(
this.maybeActivateMonitorWidget()
Expand All @@ -306,8 +324,10 @@ export abstract class CoreServiceContribution extends SketchContribution {
messageService: this.messageService,
responseService: this.responseService,
progressText,
run: ({ progressId }) => task(progressId, this.coreService),
run: ({ progressId, cancellationToken }) =>
task(progressId, this.coreService, cancellationToken),
keepOutput,
cancelable: options.cancelable,
});
toDisposeOnComplete.dispose();
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ export class UploadSketch extends CoreServiceContribution {

const uploadResponse = await this.doWithProgress({
progressText: nls.localize('arduino/sketch/uploading', 'Uploading...'),
task: (progressId, coreService) =>
coreService.upload({ ...uploadOptions, progressId }),
task: (progressId, coreService, token) =>
coreService.upload({ ...uploadOptions, progressId }, token),
keepOutput: true,
cancelable: true,
});
// the port update is NOOP if nothing has changed
this.boardsServiceProvider.updateConfig(uploadResponse.portAfterUpload);
Expand Down
26 changes: 15 additions & 11 deletions arduino-ide-extension/src/browser/contributions/verify-sketch.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { inject, injectable } from '@theia/core/shared/inversify';
import { Emitter } from '@theia/core/lib/common/event';
import { nls } from '@theia/core/lib/common/nls';
import { inject, injectable } from '@theia/core/shared/inversify';
import type { CoreService } from '../../common/protocol';
import { ArduinoMenus } from '../menu/arduino-menus';
import { CurrentSketch } from '../sketches-service-client-impl';
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
import {
CoreServiceContribution,
Command,
CommandRegistry,
MenuModelRegistry,
CoreServiceContribution,
KeybindingRegistry,
MenuModelRegistry,
TabBarToolbarRegistry,
} from './contribution';
import { nls } from '@theia/core/lib/common';
import { CurrentSketch } from '../sketches-service-client-impl';
import { CoreService } from '../../common/protocol';
import { CoreErrorHandler } from './core-error-handler';

export interface VerifySketchParams {
Expand Down Expand Up @@ -131,11 +131,15 @@ export class VerifySketch extends CoreServiceContribution {
'arduino/sketch/compile',
'Compiling sketch...'
),
task: (progressId, coreService) =>
coreService.compile({
...options,
progressId,
}),
task: (progressId, coreService, token) =>
coreService.compile(
{
...options,
progressId,
},
token
),
cancelable: true,
});
this.messageService.info(
nls.localize('arduino/sketch/doneCompiling', 'Done compiling.'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import {
LibrarySearch,
LibraryService,
} from '../../common/protocol/library-service';
import {
ListWidget,
UserAbortError,
} from '../widgets/component-list/list-widget';
import { ListWidget } from '../widgets/component-list/list-widget';
import { Installable } from '../../common/protocol';
import { ListItemRenderer } from '../widgets/component-list/list-item-renderer';
import { nls } from '@theia/core/lib/common';
import { LibraryFilterRenderer } from '../widgets/component-list/filter-renderer';
import { findChildTheiaButton, splitByBoldTag } from '../utils/dom';
import { UserAbortError } from '../../common/protocol/progressible';

@injectable()
export class LibraryListWidget extends ListWidget<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from '@theia/core/shared/react';
import type { ArduinoComponent } from '../../../common/protocol/arduino-component';
import { Installable } from '../../../common/protocol/installable';
import type { ListItemRenderer } from './list-item-renderer';
import { UserAbortError } from './list-widget';
import { UserAbortError } from '../../../common/protocol/progressible';

export class ComponentListItem<
T extends ArduinoComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { CommandService } from '@theia/core/lib/common/command';
import { MessageService } from '@theia/core/lib/common/message-service';
import { ConfirmDialog } from '@theia/core/lib/browser/dialogs';
import { Searchable } from '../../../common/protocol/searchable';
import { ExecuteWithProgress } from '../../../common/protocol/progressible';
import {
ExecuteWithProgress,
UserAbortError,
} from '../../../common/protocol/progressible';
import {
Installable,
libraryInstallFailed,
platformInstallFailed,
} from '../../../common/protocol/installable';
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
import { SearchBar } from './search-bar';
import { ListWidget, UserAbortError } from './list-widget';
import { ListWidget } from './list-widget';
import { ComponentList } from './component-list';
import { ListItemRenderer } from './list-item-renderer';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,3 @@ export namespace ListWidget {
readonly defaultSearchOptions: S;
}
}

export class UserAbortError extends Error {
constructor(message = 'User abort') {
super(message);
Object.setPrototypeOf(this, UserAbortError.prototype);
}
}
2 changes: 2 additions & 0 deletions arduino-ide-extension/src/common/nls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export const noSketchOpened = nls.localize(
'arduino/common/noSketchOpened',
'No sketch opened'
);

export const userAbort = nls.localize('arduino/common/userAbort', 'User abort');
18 changes: 14 additions & 4 deletions arduino-ide-extension/src/common/protocol/core-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApplicationError } from '@theia/core/lib/common/application-error';
import type { CancellationToken } from '@theia/core/lib/common/cancellation';
import { nls } from '@theia/core/lib/common/nls';
import type {
Location,
Expand All @@ -7,7 +8,7 @@ import type {
} from '@theia/core/shared/vscode-languageserver-protocol';
import type { CompileSummary as ApiCompileSummary } from 'vscode-arduino-api';
import type { BoardUserField, Installable } from '../../common/protocol/';
import { isPortIdentifier, PortIdentifier, Programmer } from './boards-service';
import { PortIdentifier, Programmer, isPortIdentifier } from './boards-service';
import type { IndexUpdateSummary } from './notification-service';
import type { Sketch } from './sketches-service';

Expand Down Expand Up @@ -162,9 +163,18 @@ export function isUploadResponse(arg: unknown): arg is UploadResponse {
export const CoreServicePath = '/services/core-service';
export const CoreService = Symbol('CoreService');
export interface CoreService {
compile(options: CoreService.Options.Compile): Promise<void>;
upload(options: CoreService.Options.Upload): Promise<UploadResponse>;
burnBootloader(options: CoreService.Options.Bootloader): Promise<void>;
compile(
options: CoreService.Options.Compile,
cancellationToken?: CancellationToken
): Promise<void>;
upload(
options: CoreService.Options.Upload,
cancellationToken?: CancellationToken
): Promise<UploadResponse>;
burnBootloader(
options: CoreService.Options.Bootloader,
cancellationToken?: CancellationToken
): Promise<void>;
/**
* Refreshes the underling core gRPC client for the Arduino CLI.
*/
Expand Down
Loading

0 comments on commit 4810de9

Please sign in to comment.