- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathcore-service.ts
246 lines (236 loc) · 8.43 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import{ApplicationError}from'@theia/core/lib/common/application-error';
importtype{CancellationToken}from'@theia/core/lib/common/cancellation';
import{nls}from'@theia/core/lib/common/nls';
importtype{
Location,
Position,
Range,
}from'@theia/core/shared/vscode-languageserver-protocol';
importtype{CompileSummaryasApiCompileSummary}from'vscode-arduino-api';
importtype{BoardUserField,Installable}from'../../common/protocol/';
import{PortIdentifier,Programmer,isPortIdentifier}from'./boards-service';
importtype{IndexUpdateSummary}from'./notification-service';
importtype{Sketch}from'./sketches-service';
exportconstCompilerWarningLiterals=[
'None',
'Default',
'More',
'All',
]asconst;
exporttypeCompilerWarnings=(typeofCompilerWarningLiterals)[number];
exportnamespaceCompilerWarnings{
exportfunctionlabelOf(warning: CompilerWarnings): string{
returnCompilerWarningLabels[warning];
}
constCompilerWarningLabels: 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'),
};
}
exportnamespaceCoreError{
exportinterfaceErrorLocationRef{
readonlymessage: string;
readonlylocation: Location;
readonlydetails?: string;
}
exportnamespaceErrorLocationRef{
exportfunctionequals(
left: ErrorLocationRef,
right: ErrorLocationRef
): boolean{
return(
left.message===right.message&&
left.details===right.details&&
equalsLocation(left.location,right.location)
);
}
functionequalsLocation(left: Location,right: Location): boolean{
returnleft.uri===right.uri&&equalsRange(left.range,right.range);
}
functionequalsRange(left: Range,right: Range): boolean{
return(
equalsPosition(left.start,right.start)&&
equalsPosition(left.end,right.end)
);
}
functionequalsPosition(left: Position,right: Position): boolean{
returnleft.character===right.character&&left.line===right.line;
}
}
exportinterfaceErrorLocationextendsErrorLocationRef{
/**
* The range of the error location source from the CLI output.
*/
readonlyrangesInOutput: Range[];// The same error might show up multiple times in the CLI output: https://github.com/arduino/arduino-cli/issues/1761
}
exportconstCodes={
Verify: 4001,
Upload: 4002,
UploadUsingProgrammer: 4003,
BurnBootloader: 4004,
UploadRequiresProgrammer: 4005,
};
exportconstVerifyFailed=declareCoreError(Codes.Verify);
exportconstUploadFailed=declareCoreError(Codes.Upload);
exportconstUploadUsingProgrammerFailed=declareCoreError(
Codes.UploadUsingProgrammer
);
exportconstBurnBootloaderFailed=declareCoreError(Codes.BurnBootloader);
exportconstUploadRequiresProgrammer=declareCoreError(
Codes.UploadRequiresProgrammer
);
exportfunctionis(
error: unknown
): error is ApplicationError<number,ErrorLocation[]>{
return(
errorinstanceofError&&
ApplicationError.is(error)&&
Object.values(Codes).includes(error.code)
);
}
functiondeclareCoreError(
code: number
): ApplicationError.Constructor<number,ErrorLocation[]>{
returnApplicationError.declare(
code,
(message: string,data: ErrorLocation[])=>{
return{
data,
message,
};
}
);
}
}
exportinterfaceInstalledPlatformReference{
readonlyid: string;
readonlyversion: Installable.Version;
/**
* Absolute filesystem path.
*/
readonlyinstallDir: string;
readonlypackageUrl: string;
}
exportinterfaceExecutableSectionSize{
readonlyname: string;
readonlysize: number;
readonlymaxSize: number;
}
exportinterfaceCompileSummary{
readonlybuildPath: string;
/**
* To be compatible with the `vscode-arduino-tools` API.
* @deprecated Use `buildPath` instead. Use Theia or VS Code URI to convert to an URI string on the client side.
*/
readonlybuildOutputUri: string;
readonlyusedLibraries: ApiCompileSummary['usedLibraries'];
readonlyexecutableSectionsSize: ExecutableSectionSize[];
readonlyboardPlatform?: InstalledPlatformReference|undefined;
readonlybuildPlatform?: InstalledPlatformReference|undefined;
readonlybuildProperties: string[];
}
exportfunctionisCompileSummary(arg: unknown): arg is CompileSummary{
return(
Boolean(arg)&&
typeofarg==='object'&&
(<CompileSummary>arg).buildPath!==undefined&&
typeof(<CompileSummary>arg).buildPath==='string'&&
(<CompileSummary>arg).buildOutputUri!==undefined&&
typeof(<CompileSummary>arg).buildOutputUri==='string'&&
(<CompileSummary>arg).executableSectionsSize!==undefined&&
Array.isArray((<CompileSummary>arg).executableSectionsSize)&&
(<CompileSummary>arg).usedLibraries!==undefined&&
Array.isArray((<CompileSummary>arg).usedLibraries)&&
(<CompileSummary>arg).buildProperties!==undefined&&
Array.isArray((<CompileSummary>arg).buildProperties)
);
}
exportinterfaceUploadResponse{
readonlyportAfterUpload: PortIdentifier;
}
exportfunctionisUploadResponse(arg: unknown): arg is UploadResponse{
return(
Boolean(arg)&&
typeofarg==='object'&&
isPortIdentifier((<UploadResponse>arg).portAfterUpload)
);
}
exportconstCoreServicePath='/services/core-service';
exportconstCoreService=Symbol('CoreService');
exportinterfaceCoreService{
compile(
options: CoreService.Options.Compile,
cancellationToken?: CancellationToken
): Promise<CompileSummary|undefined>;
upload(
options: CoreService.Options.Upload,
cancellationToken?: CancellationToken
): Promise<UploadResponse>;
burnBootloader(
options: CoreService.Options.Bootloader,
cancellationToken?: CancellationToken
): Promise<void>;
/**
* Refreshes the underling core gRPC client for the Arduino CLI.
*/
refresh(): Promise<void>;
/**
* Updates the index of the given index types and refreshes (`init`) the underlying core gRPC client.
* If `types` is empty, only the refresh part will be executed.
*/
updateIndex({ types }: {types: IndexType[]}): Promise<void>;
/**
* If the IDE2 detects invalid or missing indexes on core client init,
* IDE2 tries to update the indexes before the first frontend connects.
* Use this method to determine whether the backend has already updated
* the indexes before updating them.
*
* If yes, the connected frontend can update the local storage with the most
* recent index update date-time for a particular index type,
* and IDE2 can avoid the double indexes update.
*/
indexUpdateSummaryBeforeInit(): Promise<Readonly<IndexUpdateSummary>>;
}
exportconstIndexTypeLiterals=['platform','library']asconst;
exporttypeIndexType=(typeofIndexTypeLiterals)[number];
exportnamespaceIndexType{
exportfunctionis(arg: unknown): arg is IndexType{
return(
typeofarg==='string'&&IndexTypeLiterals.includes(argasIndexType)
);
}
exportconstAll: IndexType[]=IndexTypeLiterals.filter(is);
}
exportnamespaceCoreService{
exportnamespaceOptions{
exportinterfaceBase{
readonlyfqbn?: string|undefined;
readonlyverbose: boolean;// TODO: (API) why not optional with a default false?
readonlyprogressId?: string;
}
exportinterfaceSketchBased{
readonlysketch: Sketch;
}
exportinterfaceBoardBased{
readonlyport?: PortIdentifier;
readonlyprogrammer?: Programmer|undefined;
/**
* For the _Verify after upload_ setting.
*/
readonlyverify: boolean;// TODO: (API) why not optional with false as the default value?
}
exportinterfaceCompileextendsBase,SketchBased{
readonlyoptimizeForDebug: boolean;// TODO: (API) make this optional
readonlysourceOverride: Record<string,string>;// TODO: (API) make this optional
readonlyexportBinaries?: boolean;
readonlycompilerWarnings?: CompilerWarnings;
}
exportinterfaceUploadextendsBase,SketchBased,BoardBased{
readonlyuserFields: BoardUserField[];
readonlyusingProgrammer?: boolean;
}
exportinterfaceBootloaderextendsBase,BoardBased{}
}
}