-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathonErrorsAction.ts
More file actions
49 lines (41 loc) · 1.57 KB
/
onErrorsAction.ts
File metadata and controls
49 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { DiagnosticSeverity, l10n, languages, MessageOptions, window } from 'vscode';
import { getConfiguration } from './vscodeapi';
export async function resolveOnErrorsAction(): Promise<OnErrorsActions> {
const onErrors = getConfiguration('debugpy').get<string>('onErrors', OnErrorsActions.debugAnyway);
if (onErrors === OnErrorsActions.debugAnyway) {
return OnErrorsActions.debugAnyway;
}
const hasErrors = languages
.getDiagnostics()
.map((d) => {
return d[1];
})
.flat()
.some((d) => {
return d.severity === DiagnosticSeverity.Error;
});
if (!hasErrors) {
return OnErrorsActions.debugAnyway;
}
if (onErrors === OnErrorsActions.prompt) {
const message = l10n.t('Error exists before debugging.');
const options: MessageOptions = { modal: true };
const actions = [
{ title: 'Debug Anyway', id: OnErrorsActions.debugAnyway },
{ title: 'Show Errors', id: OnErrorsActions.showErrors },
{ title: 'Abort', id: OnErrorsActions.abort, isCloseAffordance: true },
];
const result = await window.showWarningMessage(message, options, ...actions);
return (result?.id as OnErrorsActions) ?? OnErrorsActions.abort;
}
return onErrors as OnErrorsActions;
}
export enum OnErrorsActions {
debugAnyway = 'debugAnyway',
showErrors = 'showErrors',
abort = 'abort',
prompt = 'prompt',
}