Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroHryshyn committed Jan 30, 2024
1 parent 288a808 commit 1b6c43d
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 29 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@
"@vscode/extension-telemetry": "^0.7.7",
"@vscode/vsce": "^2.22.0",
"axios": "^1.2.2",
"axios-retry": "^4.0.0",
"diff": "^5.1.0",
"fast-deep-equal": "^3.1.3",
"fast-glob": "^3.3.2",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/axios/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from 'axios';
import axiosRetry from 'axios-retry';

const client = axios.create();
axiosRetry(client);

export const DEFAULT_RETRY_COUNT = 3;
export default client;
26 changes: 20 additions & 6 deletions src/components/bootstrapExecutablesService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FileSystem, Uri } from 'vscode';
import { FileSystem, Uri, window } from 'vscode';
import { DownloadService, ForbiddenRequestError } from './downloadService';
import { MessageBus, MessageKind } from './messageBus';
import { Telemetry } from '../telemetry/telemetry';

// aka bootstrap engines
export class BootstrapExecutablesService {
Expand All @@ -9,6 +10,7 @@ export class BootstrapExecutablesService {
private readonly __globalStorageUri: Uri,
private readonly __fileSystem: FileSystem,
private readonly __messageBus: MessageBus,
private readonly __telemetryService: Telemetry
) {
__messageBus.subscribe(MessageKind.bootstrapEngine, () =>
this.__onBootstrapEngines(),
Expand All @@ -18,19 +20,31 @@ export class BootstrapExecutablesService {
private async __onBootstrapEngines() {
await this.__fileSystem.createDirectory(this.__globalStorageUri);

// Uri.file('/intuita/nora-node-engine/package/intuita-linux')
const codemodEngineNodeExecutableUri =
await this.__bootstrapCodemodEngineNodeExecutableUri();
try {
// Uri.file('/intuita/nora-node-engine/package/intuita-linux')
const codemodEngineNodeExecutableUri =
await this.__bootstrapCodemodEngineNodeExecutableUri();

// Uri.file('/intuita/codemod-engine-rust/target/release/codemod-engine-rust');
// Uri.file('/intuita/codemod-engine-rust/target/release/codemod-engine-rust');
const codemodEngineRustExecutableUri =
await this.__bootstrapCodemodEngineRustExecutableUri();
await this.__bootstrapCodemodEngineRustExecutableUri();

this.__messageBus.publish({
kind: MessageKind.engineBootstrapped,
codemodEngineNodeExecutableUri,
codemodEngineRustExecutableUri,
});

} catch(e) {
const message = e instanceof Error ? e.message : String(e);

window.showErrorMessage(message);

this.__telemetryService.sendError({
kind: 'failedToBootstrapEngines',
message,
});
}
}

private async __bootstrapCodemodEngineNodeExecutableUri(): Promise<Uri> {
Expand Down
21 changes: 16 additions & 5 deletions src/components/downloadService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import { isAxiosError } from 'axios';
import axios, { DEFAULT_RETRY_COUNT } from '../axios';
import { Mode } from 'node:fs';
import { FileSystem, Uri } from 'vscode';
import { FileSystemUtilities } from './fileSystemUtilities';
Expand Down Expand Up @@ -29,13 +30,18 @@ export class DownloadService {
let response;

try {
response = await axios.head(url, { timeout: 5000 });
response = await axios.head(url, {
timeout: 15000,
'axios-retry': {
retries: DEFAULT_RETRY_COUNT
}
});
} catch (error) {
if (localModificationTime > 0) {
return false;
}

if (!axios.isAxiosError(error)) {
if (!isAxiosError(error)) {
throw error;
}

Expand Down Expand Up @@ -69,11 +75,16 @@ export class DownloadService {
uri: Uri,
chmod: Mode | null,
): Promise<void> {
const response = await axios.get(url, { responseType: 'arraybuffer' });
const response = await axios.get(url, {
responseType: 'arraybuffer',
'axios-retry': {
retries: DEFAULT_RETRY_COUNT
}
});
const content = new Uint8Array(response.data);

await this.#fileSystem.writeFile(uri, content);

if (chmod !== null) {
await this.#fileSystemUtilities.setChmod(uri, chmod);
}
Expand Down
44 changes: 32 additions & 12 deletions src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import rootReducer, { actions, getInitialState } from './slice';
import { Memento } from 'vscode';
import { PersistPartial } from 'redux-persist/es/persistReducer';
import { persistedStateCodecNew } from '../persistedState/codecs';
import { window } from 'vscode';

const PERSISTANCE_PREFIX = 'persist';
const PERSISTANCE_KEY = 'compressedRoot';
Expand All @@ -18,7 +19,7 @@ const deserializeState = (serializedState: string) => {
const rawState = JSON.parse(serializedState);

if (typeof rawState !== 'object' || rawState === null) {
return;
return null;
}

Object.entries(rawState).forEach(([key, value]) => {
Expand All @@ -30,11 +31,36 @@ const deserializeState = (serializedState: string) => {
});
} catch (e) {
console.error(e);

return null;
}

return parsedState;
};

const getPreloadedState = async (storage: MementoStorage) => {
const initialState =
(await storage.getItem(`${PERSISTANCE_PREFIX}:${PERSISTANCE_KEY}`));

if(initialState === null) {
return null;
}

const deserializedState = deserializeState(initialState);

if(deserializeState === null) {
return null;
}

const decodedState = persistedStateCodecNew.decode(deserializedState);

// should never happen because of codec fallback
if (decodedState._tag !== 'Right') {
throw new Error('Invalid state');
}

return decodedState.right;
}
const buildStore = async (workspaceState: Memento) => {
const storage = new MementoStorage(workspaceState);

Expand Down Expand Up @@ -65,21 +91,15 @@ const buildStore = async (workspaceState: Memento) => {
return persistedReducer(state, action);
};

const initialState =
(await storage.getItem(`${PERSISTANCE_PREFIX}:${PERSISTANCE_KEY}`)) ??
'';
const deserializedState = deserializeState(initialState);
const preloadedState = await getPreloadedState(storage);

const decodedState = persistedStateCodecNew.decode(deserializedState);

// should never happen because of codec fallback
if (decodedState._tag !== 'Right') {
throw new Error('Invalid state');
if(preloadedState === null) {
window.showWarningMessage('Unable to get preloaded state');
}

const store = configureStore({
reducer: validatedReducer,
preloadedState: decodedState.right,
...(preloadedState !== null && { preloadedState }),
});

const persistor = persistStore(store);
Expand Down
13 changes: 8 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ export async function activate(context: vscode.ExtensionContext) {
}),
);

const telemetryKey = 'd9f8ad27-50df-46e3-8acf-81ea279c8444';
const vscodeTelemetry = new VscodeTelemetry(
new TelemetryReporter(telemetryKey),
messageBus,
);

const fileService = new FileService(messageBus);

const jobManager = new JobManager(fileService, messageBus, store);
Expand All @@ -134,16 +140,13 @@ export async function activate(context: vscode.ExtensionContext) {
context.globalStorageUri,
vscode.workspace.fs,
messageBus,
vscodeTelemetry
);

const intuitaTextDocumentContentProvider =
new IntuitaTextDocumentContentProvider();

const telemetryKey = 'd9f8ad27-50df-46e3-8acf-81ea279c8444';
const vscodeTelemetry = new VscodeTelemetry(
new TelemetryReporter(telemetryKey),
messageBus,
);


const mainViewProvider = new MainViewProvider(
context,
Expand Down
6 changes: 5 additions & 1 deletion src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import type { CaseHash } from '../cases/types';
export type ErrorEvent = Readonly<{
kind: 'failedToExecuteCommand';
commandName: string;
}>;
}> |
Readonly<{
kind: 'failedToBootstrapEngines',
message: string;
}>

export type Event =
| Readonly<{
Expand Down

0 comments on commit 1b6c43d

Please sign in to comment.