-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathcore-service.ts
143 lines (140 loc) · 4.68 KB
/
core-service.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { nls } from '@theia/core/lib/common/nls';
import { ApplicationError } from '@theia/core/lib/common/application-error';
import type {
Location,
Range,
Position,
} from '@theia/core/shared/vscode-languageserver-protocol';
import type {
BoardUserField,
Port,
} from '../../common/protocol/boards-service';
import type { Programmer } from './boards-service';
import type { Sketch } from './sketches-service';
export const CompilerWarningLiterals = [
'None',
'Default',
'More',
'All',
] as const;
export type CompilerWarnings = typeof CompilerWarningLiterals[number];
export namespace CompilerWarnings {
export function labelOf(warning: CompilerWarnings): string {
return CompilerWarningLabels[warning];
}
const CompilerWarningLabels: Record<CompilerWarnings, string> = {
None: nls.localize('arduino/core/compilerWarnings/none', 'None'),
Default: nls.localize('arduino/core/compilerWarnings/default', 'Default'),
More: nls.localize('arduino/core/compilerWarnings/more', 'More'),
All: nls.localize('arduino/core/compilerWarnings/all', 'All'),
};
}
export namespace CoreError {
export interface ErrorLocationRef {
readonly message: string;
readonly location: Location;
readonly details?: string;
}
export namespace ErrorLocationRef {
export function equals(
left: ErrorLocationRef,
right: ErrorLocationRef
): boolean {
return (
left.message === right.message &&
left.details === right.details &&
equalsLocation(left.location, right.location)
);
}
function equalsLocation(left: Location, right: Location): boolean {
return left.uri === right.uri && equalsRange(left.range, right.range);
}
function equalsRange(left: Range, right: Range): boolean {
return (
equalsPosition(left.start, right.start) &&
equalsPosition(left.end, right.end)
);
}
function equalsPosition(left: Position, right: Position): boolean {
return left.character === right.character && left.line === right.line;
}
}
export interface ErrorLocation extends ErrorLocationRef {
/**
* The range of the error location source from the CLI output.
*/
readonly rangesInOutput: Range[]; // The same error might show up multiple times in the CLI output: https://github.com/arduino/arduino-cli/issues/1761
}
export const Codes = {
Verify: 4001,
Upload: 4002,
UploadUsingProgrammer: 4003,
BurnBootloader: 4004,
};
export const VerifyFailed = create(Codes.Verify);
export const UploadFailed = create(Codes.Upload);
export const UploadUsingProgrammerFailed = create(
Codes.UploadUsingProgrammer
);
export const BurnBootloaderFailed = create(Codes.BurnBootloader);
export function is(
error: unknown
): error is ApplicationError<number, ErrorLocation[]> {
return (
error instanceof Error &&
ApplicationError.is(error) &&
Object.values(Codes).includes(error.code)
);
}
function create(
code: number
): ApplicationError.Constructor<number, ErrorLocation[]> {
return ApplicationError.declare(
code,
(message: string, data: ErrorLocation[]) => {
return {
data,
message,
};
}
);
}
}
export const CoreServicePath = '/services/core-service';
export const CoreService = Symbol('CoreService');
export interface CoreService {
compile(options: CoreService.Options.Compile): Promise<void>;
upload(options: CoreService.Options.Upload): Promise<void>;
burnBootloader(options: CoreService.Options.Bootloader): Promise<void>;
}
export namespace CoreService {
export namespace Options {
export interface Base {
readonly fqbn?: string | undefined;
readonly verbose: boolean; // TODO: (API) why not optional with a default false?
readonly progressId?: string;
}
export interface SketchBased {
readonly sketch: Sketch;
}
export interface BoardBased {
readonly port?: Port;
readonly programmer?: Programmer | undefined;
/**
* For the _Verify after upload_ setting.
*/
readonly verify: boolean; // TODO: (API) why not optional with false as the default value?
}
export interface Compile extends Base, SketchBased {
readonly optimizeForDebug: boolean; // TODO: (API) make this optional
readonly sourceOverride: Record<string, string>; // TODO: (API) make this optional
readonly exportBinaries?: boolean;
readonly compilerWarnings?: CompilerWarnings;
}
export interface Upload extends Base, SketchBased, BoardBased {
readonly userFields: BoardUserField[];
readonly usingProgrammer?: boolean;
}
export interface Bootloader extends Base, BoardBased {}
}
}