Skip to content

Commit 128252c

Browse files
committed
Merge branch 'dev' into feat/warn-all-schema-problems
2 parents 9620627 + 5e3b838 commit 128252c

8 files changed

Lines changed: 215 additions & 147 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ Changes between each version before then will not be listed.
88

99
## 2.2.2
1010

11+
### Added features
12+
13+
- If an exception was thrown while executing an action, it will be caught and you will be notified about it.
14+
- Neuro will also receive an action result telling her that an error occured.
15+
- Obviously under normal circumstances, this shouldn't be useful. If it does occur, please report it! There is a button to open to our GitHub issues page to report it.
16+
- There are also buttons to disable the attempted action and to view logs.
17+
1118
### Changes
1219

1320
- Neuro can now get cookies by herself, if `neuropilot.permission.requestCookies` is set to `Autopilot`.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@
161161
"title": "Open a specific page in the docs",
162162
"category": "NeuroPilot"
163163
},
164+
{
165+
"command": "neuropilot.resetTemporarilyDisabledActions",
166+
"title": "Reset temporarily disabled actions",
167+
"category": "NeuroPilot"
168+
},
164169
{
165170
"command": "neuropilot.sendSelectionToNeuro",
166171
"title": "Send selection to Neuro",

src/config.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ function getActions<T>(key: string): T | undefined {
225225
}
226226

227227
export function isActionEnabled(action: string | Action): boolean {
228-
if (typeof action === 'string')
229-
return !ACTIONS.disabledActions.includes(action);
230-
return !ACTIONS.disabledActions.includes(action.name);
228+
const name = typeof action === 'string' ? action : action.name;
229+
return !ACTIONS.disabledActions.includes(name) && !NEURO.tempDisabledActions.includes(name);
231230
}
232231

233232
//#endregion

src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ interface Neuro {
7878
killSwitch: boolean;
7979
/** The last known user selection, or null if there is none or it is in a non-Neuro-safe file. */
8080
lastKnownUserSelection: vscode.Selection | null;
81+
/** Any temporarily disabled actions for this session. */
82+
tempDisabledActions: string[]
8183
}
8284

8385

@@ -111,6 +113,7 @@ export const NEURO: Neuro = {
111113
currentController: null,
112114
killSwitch: false,
113115
lastKnownUserSelection: null,
116+
tempDisabledActions: [],
114117
};
115118

116119
// this will likely be transformed for a different use later when the API rolls around

src/context.ts

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from 'vscode';
22

3-
import { getFence, logOutput, simpleFileName } from '@/utils';
3+
import { getFence, logOutput, notifyOnCaughtException, simpleFileName } from '@/utils';
44
import { NEURO } from '@/constants';
55
import { PERMISSIONS, PermissionLevel, getPermissionLevel, isActionEnabled } from '@/config';
66

@@ -53,43 +53,50 @@ export function registerRequestCookieHandler() {
5353
if (actionData.name === 'request_cookie') {
5454
NEURO.actionHandled = true;
5555

56-
if (NEURO.waitingForCookie) {
57-
logOutput('INFO', 'Already waiting for a cookie');
58-
NEURO.client?.sendActionResult(actionData.id, true, 'You already asked for a cookie.');
59-
return;
60-
}
56+
try {
57+
if (NEURO.waitingForCookie) {
58+
logOutput('INFO', 'Already waiting for a cookie');
59+
NEURO.client?.sendActionResult(actionData.id, true, 'You already asked for a cookie.');
60+
return;
61+
}
6162

62-
const permission = getPermissionLevel(PERMISSIONS.requestCookies);
63+
const permission = getPermissionLevel(PERMISSIONS.requestCookies);
6364

64-
switch (permission) {
65-
case PermissionLevel.OFF:
66-
logOutput('WARNING', 'Neuro attempted to request a cookie, but permission is disabled');
67-
NEURO.client?.sendActionResult(actionData.id, true, 'Permission to request cookies is disabled.');
68-
break;
69-
case PermissionLevel.COPILOT:
70-
NEURO.waitingForCookie = true;
71-
vscode.window.showInformationMessage(
72-
`${NEURO.currentController} is asking for a${actionData.params?.flavor ? ' ' + actionData.params.flavor : ''} cookie.`,
73-
'Give',
74-
'Deny',
75-
).then((value) => {
76-
if (value === 'Give') {
77-
giveCookie(true, actionData.params?.flavor);
78-
} else if (value === 'Deny' || value === undefined) {
79-
denyCookie();
65+
switch (permission) {
66+
case PermissionLevel.OFF:
67+
logOutput('WARNING', 'Neuro attempted to request a cookie, but permission is disabled');
68+
NEURO.client?.sendActionResult(actionData.id, true, 'Permission to request cookies is disabled.');
69+
break;
70+
case PermissionLevel.COPILOT:
71+
NEURO.waitingForCookie = true;
72+
vscode.window.showInformationMessage(
73+
`${NEURO.currentController} is asking for a${actionData.params?.flavor ? ' ' + actionData.params.flavor : ''} cookie.`,
74+
'Give',
75+
'Deny',
76+
).then((value) => {
77+
if (value === 'Give') {
78+
giveCookie(true, actionData.params?.flavor);
79+
} else if (value === 'Deny' || value === undefined) {
80+
denyCookie();
81+
}
82+
NEURO.waitingForCookie = false;
83+
});
84+
NEURO.client?.sendActionResult(actionData.id, true, 'Vedal has been asked for a cookie.');
85+
break;
86+
case PermissionLevel.AUTOPILOT:
87+
if (!actionData.params?.flavor) {
88+
NEURO.client?.sendActionResult(actionData.id, false, 'You need to specify a flavor!');
89+
break;
8090
}
81-
NEURO.waitingForCookie = false;
82-
});
83-
NEURO.client?.sendActionResult(actionData.id, true, 'Vedal has been asked for a cookie.');
84-
break;
85-
case PermissionLevel.AUTOPILOT:
86-
if (!actionData.params?.flavor) {
87-
NEURO.client?.sendActionResult(actionData.id, false, 'You need to specify a flavor!');
91+
logOutput('INFO', `Neuro grabbed a ${actionData.params?.flavor} cookie.`);
92+
NEURO.client?.sendActionResult(actionData.id, true, `You grabbed a ${actionData.params?.flavor} cookie!`);
8893
break;
89-
}
90-
logOutput('INFO', `Neuro grabbed a ${actionData.params?.flavor} cookie.`);
91-
NEURO.client?.sendActionResult(actionData.id, true, `You grabbed a ${actionData.params?.flavor} cookie!`);
92-
break;
94+
}
95+
} catch (erm) {
96+
const actionName = actionData.name;
97+
notifyOnCaughtException(actionName, erm);
98+
NEURO.client?.sendActionResult(actionData.id, true, `An error occured while executing the action "${actionName}". You may retry if you like, but it may be better to ask Vedal to check what's up.`);
99+
return;
93100
}
94101
}
95102
});

0 commit comments

Comments
 (0)