Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notification on Mops / Vessel package configuration error #240

Merged
merged 3 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/common/connectionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ export const DEPLOY_PLAYGROUND_MESSAGE =
export interface NotifyDeployParams {
message: string;
}

export const ERROR_MESSAGE = new NotificationType<NotifyErrorParams>(
'vscode-motoko/notify-error',
);

export interface NotifyErrorParams {
message: string;
detail?: string | undefined;
}
10 changes: 10 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import * as which from 'which';
import {
DEPLOY_PLAYGROUND,
DEPLOY_PLAYGROUND_MESSAGE,
ERROR_MESSAGE,
TEST_FILE_REQUEST,
TestParams,
TestResult,
Expand Down Expand Up @@ -326,6 +327,15 @@ function restartLanguageServer(
serverOptions,
clientOptions,
);
client.onNotification(ERROR_MESSAGE, async ({ message, detail }) => {
const item = await window.showErrorMessage(
detail ? `${message}\n${detail}` : message,
'View logs',
);
if (item === 'View logs') {
client.outputChannel.show();
}
});
client.start().catch((err) => console.error(err.stack || err));
context.subscriptions.push(client);
}
Expand Down
23 changes: 15 additions & 8 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { URI } from 'vscode-uri';
import {
DEPLOY_PLAYGROUND,
DEPLOY_PLAYGROUND_MESSAGE,
ERROR_MESSAGE,
TEST_FILE_REQUEST,
TestResult,
} from '../common/connectionTypes';
Expand Down Expand Up @@ -209,7 +210,6 @@ async function getPackageSources(
}

let loadingPackages = false;
let packageConfigError = false;
let packageConfigChangeTimeout: ReturnType<typeof setTimeout>;
function notifyPackageConfigChange(reuseCached = false) {
if (!reuseCached) {
Expand All @@ -218,7 +218,6 @@ function notifyPackageConfigChange(reuseCached = false) {
loadingPackages = true;
clearTimeout(packageConfigChangeTimeout);
packageConfigChangeTimeout = setTimeout(async () => {
packageConfigError = false;
try {
resetContexts();

Expand Down Expand Up @@ -278,16 +277,23 @@ function notifyPackageConfigChange(reuseCached = false) {
context.motoko.usePackage(name, path);
});
} catch (err) {
packageConfigError = true;
connection.sendNotification(ERROR_MESSAGE, {
message: `Error while resolving Motoko packages:`,
detail: String(err).replace(/^Error: /, ''),
});
context.error = String(err);
console.warn(err);
return;
}
} catch (err) {
packageConfigError = true;
} catch (err: any) {
connection.sendNotification(ERROR_MESSAGE, {
message: `Error while loading Motoko packages:`,
detail: String(err).replace(/^Error: /, ''),
});
console.error(
`Error while reading packages for directory (${dir}): ${err}`,
);
return;
}
}),
);
Expand All @@ -303,10 +309,11 @@ function notifyPackageConfigChange(reuseCached = false) {
loadingPackages = false;
notifyWorkspace(); // Update virtual file system
notifyDfxChange(); // Reload dfx.json
} catch (err) {
} catch (err: any) {
loadingPackages = false;
packageConfigError = true;
console.error(`Error while loading packages: ${err}`);
console.error(
`Error while loading packages: ${err?.message || err}`,
);
}
}, 1000);
}
Expand Down