11import * as vscode from "vscode" ;
2+ import { CoderApi , VSCodeApi } from "../typings/api" ;
23import { createCSSRule } from "vs/base/browser/dom" ;
34import { Emitter , Event } from "vs/base/common/event" ;
45import { IDisposable } from "vs/base/common/lifecycle" ;
@@ -37,7 +38,7 @@ import { IViewletService } from "vs/workbench/services/viewlet/browser/viewlet";
3738 * TODO: Implement menu items for views (for item actions).
3839 * TODO: File system provider doesn't work.
3940 */
40- export const vscodeApi = ( serviceCollection : ServiceCollection ) : Partial < typeof vscode > => {
41+ export const vscodeApi = ( serviceCollection : ServiceCollection ) : VSCodeApi => {
4142 const getService = < T > ( id : ServiceIdentifier < T > ) : T => serviceCollection . get < T > ( id ) as T ;
4243 const commandService = getService ( ICommandService ) ;
4344 const notificationService = getService ( INotificationService ) ;
@@ -51,24 +52,24 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
5152 // browser's main thread, but I'm not sure how much jank that would require.
5253 // We could have a web worker host but we want DOM access.
5354 return {
54- EventEmitter : Emitter ,
55- TreeItemCollapsibleState : extHostTypes . TreeItemCollapsibleState ,
55+ EventEmitter : < any > Emitter , // It can take T so T | undefined should work.
5656 FileSystemError : extHostTypes . FileSystemError ,
5757 FileType,
58+ StatusBarAlignment : extHostTypes . StatusBarAlignment ,
59+ ThemeColor : extHostTypes . ThemeColor ,
60+ TreeItemCollapsibleState : extHostTypes . TreeItemCollapsibleState ,
5861 Uri : URI ,
59- StatusBarAlignment,
60- ThemeColor,
6162 commands : {
6263 executeCommand : < T = any > ( commandId : string , ...args : any [ ] ) : Promise < T | undefined > => {
6364 return commandService . executeCommand ( commandId , ...args ) ;
6465 } ,
6566 registerCommand : ( id : string , command : ( ...args : any [ ] ) => any ) : IDisposable => {
6667 return CommandsRegistry . registerCommand ( id , command ) ;
6768 } ,
68- } as Partial < typeof vscode . commands > ,
69+ } ,
6970 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 ) ;
7273 } ,
7374 registerTreeDataProvider : < T > ( id : string , dataProvider : vscode . TreeDataProvider < T > ) : IDisposable => {
7475 const tree = new TreeViewDataProvider ( dataProvider ) ;
@@ -82,20 +83,20 @@ export const vscodeApi = (serviceCollection: ServiceCollection): Partial<typeof
8283 notificationService . error ( message ) ;
8384 return undefined ;
8485 } ,
85- } as Partial < typeof vscode . window > ,
86+ } ,
8687 workspace : {
8788 registerFileSystemProvider : ( scheme : string , provider : vscode . FileSystemProvider ) : IDisposable => {
8889 return fileService . registerProvider ( scheme , new FileSystemProvider ( provider ) ) ;
8990 } ,
90- } as Partial < typeof vscode . workspace > ,
91- } as Partial < typeof vscode > ; // Without this it complains that the type isn't `| undefined`.
91+ } ,
92+ } ;
9293} ;
9394
9495/**
9596 * Coder API. This should only provide functionality that can't be made
9697 * available through the VS Code API.
9798 */
98- export const coderApi = ( serviceCollection : ServiceCollection ) : typeof coder => {
99+ export const coderApi = ( serviceCollection : ServiceCollection ) : CoderApi => {
99100 const getService = < T > ( id : ServiceIdentifier < T > ) : T => serviceCollection . get < T > ( id ) as T ;
100101 return {
101102 registerView : ( viewId , viewName , containerId , containerName , icon ) : void => {
@@ -275,72 +276,71 @@ class TreeViewDataProvider<T> implements ITreeViewDataProvider {
275276 }
276277}
277278
278- class ThemeColor {
279- public id : string ;
280- constructor ( id : string ) {
281- this . id = id ;
282- }
283- }
284-
285279interface IStatusBarEntry extends IStatusbarEntry {
286280 alignment : StatusbarAlignment ;
287281 priority ?: number ;
288282}
289283
290- enum StatusBarAlignment {
291- Left = 1 ,
292- Right = 2
293- }
294-
295284class StatusBarEntry implements vscode . StatusBarItem {
296285 private static ID = 0 ;
297286
298287 private _id : number ;
299288 private entry : IStatusBarEntry ;
300- private _visible : boolean ;
289+ private visible : boolean ;
301290 private disposed : boolean ;
302291 private statusId : string ;
303292 private statusName : string ;
304293 private accessor ?: IStatusbarEntryAccessor ;
305294 private timeout : any ;
306295
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 ) {
308297 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+ }
317317 }
318318
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 ;
322322 }
323323
324324 public get id ( ) : number { return this . _id ; }
325325 public get priority ( ) : number | undefined { return this . entry . priority ; }
326326 public get text ( ) : string { return this . entry . text ; }
327327 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 ; }
329329 public get command ( ) : string | undefined { return this . entry . command ; }
330330
331331 public set text ( text : string ) { this . update ( { text } ) ; }
332332 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 } ) ; }
334334 public set command ( command : string | undefined ) { this . update ( { command } ) ; }
335335
336336 public show ( ) : void {
337- this . _visible = true ;
337+ this . visible = true ;
338338 this . update ( ) ;
339339 }
340340
341341 public hide ( ) : void {
342342 clearTimeout ( this . timeout ) ;
343- this . _visible = false ;
343+ this . visible = false ;
344344 if ( this . accessor ) {
345345 this . accessor . dispose ( ) ;
346346 this . accessor = undefined ;
@@ -349,7 +349,7 @@ class StatusBarEntry implements vscode.StatusBarItem {
349349
350350 private update ( values ?: Partial < IStatusBarEntry > ) : void {
351351 this . entry = { ...this . entry , ...values } ;
352- if ( this . disposed || ! this . _visible ) {
352+ if ( this . disposed || ! this . visible ) {
353353 return ;
354354 }
355355 clearTimeout ( this . timeout ) ;
0 commit comments