6
6
import * as path from "path" ;
7
7
import * as Uuid from "uuid/v4" ;
8
8
import * as vscode from "vscode" ;
9
+ import ArduinoActivator from "../arduinoActivator" ;
10
+ import ArduinoContext from "../arduinoContext" ;
9
11
import * as Constants from "../common/constants" ;
10
12
import * as JSONHelper from "../common/cycle" ;
11
13
import * as Logger from "../logger/logger" ;
12
- import { ArduinoApp } from "./arduino" ;
13
14
import LocalWebServer from "./localWebServer" ;
14
15
import { VscodeSettings } from "./vscodeSettings" ;
15
16
@@ -18,7 +19,6 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
18
19
private _onDidChange = new vscode . EventEmitter < vscode . Uri > ( ) ;
19
20
20
21
constructor (
21
- private _arduinoApp : ArduinoApp ,
22
22
private _extensionPath : string ) {
23
23
this . initialize ( ) ;
24
24
}
@@ -53,7 +53,10 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
53
53
this . _webserver . start ( ) ;
54
54
}
55
55
56
- public provideTextDocumentContent ( uri : vscode . Uri ) : string {
56
+ public async provideTextDocumentContent ( uri : vscode . Uri ) : Promise < string > {
57
+ if ( ! ArduinoContext . initialized ) {
58
+ await ArduinoActivator . activate ( ) ;
59
+ }
57
60
let type = "" ;
58
61
if ( uri . toString ( ) === Constants . BOARD_MANAGER_URI . toString ( ) ) {
59
62
type = "boardmanager" ;
@@ -105,9 +108,9 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
105
108
106
109
public async getBoardPackages ( req , res ) {
107
110
const update = ( VscodeSettings . getInstance ( ) . autoUpdateIndexFiles && req . query . update === "true" ) ;
108
- await this . _arduinoApp . boardManager . loadPackages ( update ) ;
111
+ await ArduinoContext . boardManager . loadPackages ( update ) ;
109
112
return res . json ( {
110
- platforms : JSONHelper . decycle ( this . _arduinoApp . boardManager . platforms , undefined ) ,
113
+ platforms : JSONHelper . decycle ( ArduinoContext . boardManager . platforms , undefined ) ,
111
114
} ) ;
112
115
}
113
116
@@ -116,7 +119,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
116
119
return res . status ( 400 ) . send ( "BAD Request! Missing { packageName, arch } parameters!" ) ;
117
120
} else {
118
121
try {
119
- await this . _arduinoApp . installBoard ( req . body . packageName , req . body . arch , req . body . version ) ;
122
+ await ArduinoContext . arduinoApp . installBoard ( req . body . packageName , req . body . arch , req . body . version ) ;
120
123
return res . json ( {
121
124
status : "OK" ,
122
125
} ) ;
@@ -131,7 +134,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
131
134
return res . status ( 400 ) . send ( "BAD Request! Missing { packagePath } parameter!" ) ;
132
135
} else {
133
136
try {
134
- await this . _arduinoApp . uninstallBoard ( req . body . boardName , req . body . packagePath ) ;
137
+ await ArduinoContext . arduinoApp . uninstallBoard ( req . body . boardName , req . body . packagePath ) ;
135
138
return res . json ( {
136
139
status : "OK" ,
137
140
} ) ;
@@ -165,9 +168,9 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
165
168
166
169
public async getLibraries ( req , res ) {
167
170
const update = ( VscodeSettings . getInstance ( ) . autoUpdateIndexFiles && req . query . update === "true" ) ;
168
- await this . _arduinoApp . libraryManager . loadLibraries ( update ) ;
171
+ await ArduinoContext . arduinoApp . libraryManager . loadLibraries ( update ) ;
169
172
return res . json ( {
170
- libraries : this . _arduinoApp . libraryManager . libraries ,
173
+ libraries : ArduinoContext . arduinoApp . libraryManager . libraries ,
171
174
} ) ;
172
175
}
173
176
@@ -176,7 +179,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
176
179
return res . status ( 400 ) . send ( "BAD Request! Missing { libraryName } parameters!" ) ;
177
180
} else {
178
181
try {
179
- await this . _arduinoApp . installLibrary ( req . body . libraryName , req . body . version ) ;
182
+ await ArduinoContext . arduinoApp . installLibrary ( req . body . libraryName , req . body . version ) ;
180
183
return res . json ( {
181
184
status : "OK" ,
182
185
} ) ;
@@ -191,7 +194,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
191
194
return res . status ( 400 ) . send ( "BAD Request! Missing { libraryPath } parameters!" ) ;
192
195
} else {
193
196
try {
194
- await this . _arduinoApp . uninstallLibrary ( req . body . libraryName , req . body . libraryPath ) ;
197
+ await ArduinoContext . arduinoApp . uninstallLibrary ( req . body . libraryName , req . body . libraryPath ) ;
195
198
return res . json ( {
196
199
status : "OK" ,
197
200
} ) ;
@@ -206,8 +209,8 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
206
209
return res . status ( 400 ) . send ( "BAD Request! Missing { libraryPath } parameters!" ) ;
207
210
} else {
208
211
try {
209
- await this . _arduinoApp . addLibPath ( req . body . libraryPath ) ;
210
- await this . _arduinoApp . includeLibrary ( req . body . libraryPath ) ;
212
+ await ArduinoContext . arduinoApp . addLibPath ( req . body . libraryPath ) ;
213
+ await ArduinoContext . arduinoApp . includeLibrary ( req . body . libraryPath ) ;
211
214
return res . json ( {
212
215
status : "OK" ,
213
216
} ) ;
@@ -219,7 +222,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
219
222
220
223
public async getBoardConfig ( req , res ) {
221
224
return res . json ( {
222
- configitems : this . _arduinoApp . boardManager . currentBoard . configItems ,
225
+ configitems : ArduinoContext . boardManager . currentBoard . configItems ,
223
226
} ) ;
224
227
}
225
228
@@ -228,7 +231,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
228
231
return res . status ( 400 ) . send ( "BAD Request! Missing parameters!" ) ;
229
232
} else {
230
233
try {
231
- this . _arduinoApp . boardManager . currentBoard . updateConfig ( req . body . configId , req . body . optionId ) ;
234
+ ArduinoContext . boardManager . currentBoard . updateConfig ( req . body . configId , req . body . optionId ) ;
232
235
return res . json ( {
233
236
status : "OK" ,
234
237
} ) ;
@@ -239,7 +242,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
239
242
}
240
243
241
244
public async getExamples ( req , res ) {
242
- const examples = await this . _arduinoApp . exampleManager . loadExamples ( ) ;
245
+ const examples = await ArduinoContext . arduinoApp . exampleManager . loadExamples ( ) ;
243
246
return res . json ( {
244
247
examples,
245
248
} ) ;
@@ -250,7 +253,7 @@ export class ArduinoContentProvider implements vscode.TextDocumentContentProvide
250
253
return res . status ( 400 ) . send ( "BAD Request! Missing { examplePath } parameter!" ) ;
251
254
} else {
252
255
try {
253
- this . _arduinoApp . openExample ( req . body . examplePath ) ;
256
+ ArduinoContext . arduinoApp . openExample ( req . body . examplePath ) ;
254
257
return res . json ( {
255
258
status : "OK" ,
256
259
} ) ;
0 commit comments