1
1
import * as vscode from "vscode" ;
2
+ import { CoderApi , VSCodeApi } from "../typings/api" ;
2
3
import { createCSSRule } from "vs/base/browser/dom" ;
3
4
import { Emitter , Event } from "vs/base/common/event" ;
4
5
import { IDisposable } from "vs/base/common/lifecycle" ;
@@ -37,7 +38,7 @@ import { IViewletService } from "vs/workbench/services/viewlet/browser/viewlet";
37
38
* TODO: Implement menu items for views (for item actions).
38
39
* TODO: File system provider doesn't work.
39
40
*/
40
- export const vscodeApi = ( serviceCollection : ServiceCollection ) : Partial < typeof vscode > => {
41
+ export const vscodeApi = ( serviceCollection : ServiceCollection ) : VSCodeApi => {
41
42
const getService = < T > ( id : ServiceIdentifier < T > ) : T => serviceCollection . get < T > ( id ) as T ;
42
43
const commandService = getService ( ICommandService ) ;
43
44
const notificationService = getService ( INotificationService ) ;
@@ -51,24 +52,24 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
51
52
// browser's main thread, but I'm not sure how much jank that would require.
52
53
// We could have a web worker host but we want DOM access.
53
54
return {
54
- EventEmitter : Emitter ,
55
- TreeItemCollapsibleState : extHostTypes . TreeItemCollapsibleState ,
55
+ EventEmitter : < any > Emitter , // It can take T so T | undefined should work.
56
56
FileSystemError : extHostTypes . FileSystemError ,
57
57
FileType,
58
+ StatusBarAlignment : extHostTypes . StatusBarAlignment ,
59
+ ThemeColor : extHostTypes . ThemeColor ,
60
+ TreeItemCollapsibleState : extHostTypes . TreeItemCollapsibleState ,
58
61
Uri : URI ,
59
- StatusBarAlignment,
60
- ThemeColor,
61
62
commands : {
62
63
executeCommand : < T = any > ( commandId : string , ...args : any [ ] ) : Promise < T | undefined > => {
63
64
return commandService . executeCommand ( commandId , ...args ) ;
64
65
} ,
65
66
registerCommand : ( id : string , command : ( ...args : any [ ] ) => any ) : IDisposable => {
66
67
return CommandsRegistry . registerCommand ( id , command ) ;
67
68
} ,
68
- } as Partial < typeof vscode . commands > ,
69
+ } ,
69
70
window : {
70
- createStatusBarItem : ( alignment ?: vscode . StatusBarAlignment , priority ?: number ) : vscode . StatusBarItem => {
71
- return new StatusBarEntry ( statusbarService , alignment , priority ) ;
71
+ createStatusBarItem ( alignmentOrOptions ?: extHostTypes . StatusBarAlignment | vscode . window . StatusBarItemOptions , priority ?: number ) : StatusBarEntry {
72
+ return new StatusBarEntry ( statusbarService , alignmentOrOptions , priority ) ;
72
73
} ,
73
74
registerTreeDataProvider : < T > ( id : string , dataProvider : vscode . TreeDataProvider < T > ) : IDisposable => {
74
75
const tree = new TreeViewDataProvider ( dataProvider ) ;
@@ -82,20 +83,20 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
82
83
notificationService . error ( message ) ;
83
84
return undefined ;
84
85
} ,
85
- } as Partial < typeof vscode . window > ,
86
+ } ,
86
87
workspace : {
87
88
registerFileSystemProvider : ( scheme : string , provider : vscode . FileSystemProvider ) : IDisposable => {
88
89
return fileService . registerProvider ( scheme , new FileSystemProvider ( provider ) ) ;
89
90
} ,
90
- } as Partial < typeof vscode . workspace > ,
91
- } as Partial < typeof vscode > ; // Without this it complains that the type isn't `| undefined`.
91
+ } ,
92
+ } ;
92
93
} ;
93
94
94
95
/**
95
96
* Coder API. This should only provide functionality that can't be made
96
97
* available through the VS Code API.
97
98
*/
98
- export const coderApi = ( serviceCollection : ServiceCollection ) : typeof coder => {
99
+ export const coderApi = ( serviceCollection : ServiceCollection ) : CoderApi => {
99
100
const getService = < T > ( id : ServiceIdentifier < T > ) : T => serviceCollection . get < T > ( id ) as T ;
100
101
return {
101
102
registerView : ( viewId , viewName , containerId , containerName , icon ) : void => {
@@ -275,72 +276,71 @@ class TreeViewDataProvider<T> implements ITreeViewDataProvider {
275
276
}
276
277
}
277
278
278
- class ThemeColor {
279
- public id : string ;
280
- constructor ( id : string ) {
281
- this . id = id ;
282
- }
283
- }
284
-
285
279
interface IStatusBarEntry extends IStatusbarEntry {
286
280
alignment : StatusbarAlignment ;
287
281
priority ?: number ;
288
282
}
289
283
290
- enum StatusBarAlignment {
291
- Left = 1 ,
292
- Right = 2
293
- }
294
-
295
284
class StatusBarEntry implements vscode . StatusBarItem {
296
285
private static ID = 0 ;
297
286
298
287
private _id : number ;
299
288
private entry : IStatusBarEntry ;
300
- private _visible : boolean ;
289
+ private visible : boolean ;
301
290
private disposed : boolean ;
302
291
private statusId : string ;
303
292
private statusName : string ;
304
293
private accessor ?: IStatusbarEntryAccessor ;
305
294
private timeout : any ;
306
295
307
- constructor ( private readonly statusbarService : IStatusbarService , alignment ?: vscode . StatusBarAlignment , priority ?: number ) {
296
+ constructor ( private readonly statusbarService : IStatusbarService , alignmentOrOptions ?: extHostTypes . StatusBarAlignment | vscode . window . StatusBarItemOptions , priority ?: number ) {
308
297
this . _id = StatusBarEntry . ID -- ;
309
- this . statusId = "web-api" ;
310
- this . statusName = "Web API" ;
311
- this . entry = {
312
- alignment : alignment && alignment === StatusBarAlignment . Left
313
- ? StatusbarAlignment . LEFT : StatusbarAlignment . RIGHT ,
314
- text : "" ,
315
- priority,
316
- } ;
298
+ if ( alignmentOrOptions && typeof alignmentOrOptions !== "number" ) {
299
+ this . statusId = alignmentOrOptions . id ;
300
+ this . statusName = alignmentOrOptions . name ;
301
+ this . entry = {
302
+ alignment : alignmentOrOptions . alignment === extHostTypes . StatusBarAlignment . Right
303
+ ? StatusbarAlignment . RIGHT : StatusbarAlignment . LEFT ,
304
+ priority,
305
+ text : "" ,
306
+ } ;
307
+ } else {
308
+ this . statusId = "web-api" ;
309
+ this . statusName = "Web API" ;
310
+ this . entry = {
311
+ alignment : alignmentOrOptions === extHostTypes . StatusBarAlignment . Right
312
+ ? StatusbarAlignment . RIGHT : StatusbarAlignment . LEFT ,
313
+ priority,
314
+ text : "" ,
315
+ } ;
316
+ }
317
317
}
318
318
319
- public get alignment ( ) : vscode . StatusBarAlignment {
320
- return this . entry . alignment === StatusbarAlignment . LEFT
321
- ? StatusBarAlignment . Left : StatusBarAlignment . Right ;
319
+ public get alignment ( ) : extHostTypes . StatusBarAlignment {
320
+ return this . entry . alignment === StatusbarAlignment . RIGHT
321
+ ? extHostTypes . StatusBarAlignment . Right : extHostTypes . StatusBarAlignment . Left ;
322
322
}
323
323
324
324
public get id ( ) : number { return this . _id ; }
325
325
public get priority ( ) : number | undefined { return this . entry . priority ; }
326
326
public get text ( ) : string { return this . entry . text ; }
327
327
public get tooltip ( ) : string | undefined { return this . entry . tooltip ; }
328
- public get color ( ) : string | ThemeColor | undefined { return this . entry . color ; }
328
+ public get color ( ) : string | extHostTypes . ThemeColor | undefined { return this . entry . color ; }
329
329
public get command ( ) : string | undefined { return this . entry . command ; }
330
330
331
331
public set text ( text : string ) { this . update ( { text } ) ; }
332
332
public set tooltip ( tooltip : string | undefined ) { this . update ( { tooltip } ) ; }
333
- public set color ( color : string | ThemeColor | undefined ) { this . update ( { color } ) ; }
333
+ public set color ( color : string | extHostTypes . ThemeColor | undefined ) { this . update ( { color } ) ; }
334
334
public set command ( command : string | undefined ) { this . update ( { command } ) ; }
335
335
336
336
public show ( ) : void {
337
- this . _visible = true ;
337
+ this . visible = true ;
338
338
this . update ( ) ;
339
339
}
340
340
341
341
public hide ( ) : void {
342
342
clearTimeout ( this . timeout ) ;
343
- this . _visible = false ;
343
+ this . visible = false ;
344
344
if ( this . accessor ) {
345
345
this . accessor . dispose ( ) ;
346
346
this . accessor = undefined ;
@@ -349,7 +349,7 @@ class StatusBarEntry implements vscode.StatusBarItem {
349
349
350
350
private update ( values ?: Partial < IStatusBarEntry > ) : void {
351
351
this . entry = { ...this . entry , ...values } ;
352
- if ( this . disposed || ! this . _visible ) {
352
+ if ( this . disposed || ! this . visible ) {
353
353
return ;
354
354
}
355
355
clearTimeout ( this . timeout ) ;
0 commit comments