Skip to content

Commit

Permalink
Merge pull request #2525 from posit-dev/sagerb-support-dismissed-depl…
Browse files Browse the repository at this point in the history
…oyment-follow-on-2

Follow-on #2 for dismissed deployment support PR
  • Loading branch information
sagerb authored Jan 14, 2025
2 parents f26aa71 + 4e66302 commit ba59b43
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
14 changes: 10 additions & 4 deletions extensions/vscode/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,21 @@ export class EventStream extends Readable implements Disposable {
}

private processMessage(msg: EventStreamMessage) {
const localId = msg.data.localId;
// Some log messages passed on from Connect include
// the localId using snake_case, rather than pascalCase.
// To filter correctly, we need to check for both.

const localId = msg.data.localId || msg.data.local_id;
if (localId && this.canceledLocalIDs.includes(localId)) {
// suppress and ignore
return;
}

// Trace message
// console.debug(
// `eventSource trace: ${event.type}: ${JSON.stringify(event)}`,
// );
// Uncomment the following code if you want to dump every message to the
// console as it is received.
// console.debug(`eventSource trace: ${msg.type}: ${JSON.stringify(msg)}`);

// Add the message to the messages array
this.messages.push(msg);
// Emit a 'message' event with the message as the payload
Expand Down
20 changes: 20 additions & 0 deletions extensions/vscode/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ export class PublisherState implements Disposable {
}
}

updateContentRecord(
newValue: ContentRecord | PreContentRecord | PreContentRecordWithConfig,
) {
const existingContentRecord = this.findContentRecord(
newValue.saveName,
newValue.projectDir,
);
if (existingContentRecord) {
const crIndex = this.contentRecords.findIndex(
(contentRecord) =>
contentRecord.deploymentPath === existingContentRecord.deploymentPath,
);
if (crIndex !== -1) {
this.contentRecords[crIndex] = newValue;
} else {
this.contentRecords.push(newValue);
}
}
}

async getSelectedConfiguration() {
const contentRecord = await this.getSelectedContentRecord();
if (!contentRecord) {
Expand Down
20 changes: 18 additions & 2 deletions extensions/vscode/src/views/deployProgress.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
// Copyright (C) 2024 by Posit Software, PBC.

import { ProgressLocation, Uri, env, window } from "vscode";
import { EventStreamMessage, eventMsgToString, useApi } from "src/api";
import {
EventStreamMessage,
eventMsgToString,
useApi,
ContentRecord,
PreContentRecord,
PreContentRecordWithConfig,
} from "src/api";
import { EventStream, UnregisterCallback } from "src/events";
import { getSummaryStringFromError } from "src/utils/errors";

type UpdateActiveContentRecordCB = (
contentRecord: ContentRecord | PreContentRecord | PreContentRecordWithConfig,
) => void;

export function deployProject(
deploymentName: string,
dir: string,
localID: string,
stream: EventStream,
updateActiveContentRecordCB: UpdateActiveContentRecordCB,
) {
window.withProgress(
{
Expand Down Expand Up @@ -38,11 +50,15 @@ export function deployProject(
streamID = "NEVER_A_VALID_STREAM";
unregisterAll();
try {
await api.contentRecords.cancelDeployment(
const response = await api.contentRecords.cancelDeployment(
deploymentName,
dir,
localID,
);

// update the UX locally
updateActiveContentRecordCB(response.data);

// we must have been successful...
// inject a psuedo end of publishing event
stream.injectMessage({
Expand Down
15 changes: 15 additions & 0 deletions extensions/vscode/src/views/homeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
useApi,
AllContentRecordTypes,
EnvironmentConfig,
PreContentRecordWithConfig,
} from "src/api";
import { EventStream } from "src/events";
import { getPythonInterpreterPath, getRInterpreterPath } from "../utils/vscode";
Expand Down Expand Up @@ -213,6 +214,7 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
projectDir,
response.data.localId,
this.stream,
this.updateActiveContentRecordLocally.bind(this),
);
} catch (error: unknown) {
// Most failures will occur on the event stream. These are the ones which
Expand Down Expand Up @@ -315,6 +317,19 @@ export class HomeViewProvider implements WebviewViewProvider, Disposable {
}
}

private updateActiveContentRecordLocally(
activeContentRecord:
| ContentRecord
| PreContentRecord
| PreContentRecordWithConfig,
) {
// update our local state, so we don't wait on file refreshes
this.state.updateContentRecord(activeContentRecord);

// refresh the webview
this.updateWebViewViewContentRecords();
}

private onPublishStart() {
this.webviewConduit.sendMsg({
kind: HostToWebviewMessageType.PUBLISH_START,
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/webviews/homeView/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export default defineConfig({
enabled: true,
thresholds: {
functions: 30.13,
lines: 17.48,
lines: 17.38,
branches: 44.82,
statements: 17.48,
statements: 17.38,
autoUpdate: true,
},
},
Expand Down

0 comments on commit ba59b43

Please sign in to comment.