@@ -6,7 +6,7 @@ import { log } from './log'
66import { LanguageClient } from './lspClient'
77import { download , getReleaseInfo } from './net'
88import { PersistentState } from './persistent_state'
9- import * as path from 'path'
9+ import * as path from 'path'
1010
1111const platforms : { [ key : string ] : string } = {
1212 'x64 win32' : 'x86_64-windows-msvc' ,
@@ -26,21 +26,21 @@ export class Extension {
2626 readonly package : {
2727 version : string
2828 } = vscode . extensions . getExtension ( this . extensionID ) ! . packageJSON ;
29-
29+
3030 public get context ( ) : vscode . ExtensionContext {
3131 return this . extensionContext
3232 }
3333
3434 public get lspClient ( ) : lsp . LanguageClient {
3535 return this . client
3636 }
37-
37+
3838 public activate = async ( context : vscode . ExtensionContext ) => {
3939 this . extensionContext = context
4040 this . state = new PersistentState ( context . globalState )
4141
42- if ( ! process . env [ 'MCSHADER_DEBUG' ] && ! ( vscode . workspace . getConfiguration ( 'mcglsl' ) . get ( 'skipBootstrap' ) as boolean ) ) {
43- await this . bootstrap ( )
42+ if ( ! process . env [ 'MCSHADER_DEBUG' ] && ! ( vscode . workspace . getConfiguration ( 'mcglsl' ) . get ( 'skipBootstrap' ) as boolean ) ) {
43+ await this . bootstrap ( )
4444 } else {
4545 log . info ( 'skipping language server bootstrap' )
4646 }
@@ -52,31 +52,31 @@ export class Extension {
5252
5353 log . info ( 'starting language server...' )
5454
55- const lspBinary = process . env [ 'MCSHADER_DEBUG' ] ?
56- this . context . asAbsolutePath ( path . join ( 'server' , 'target' , 'debug' , 'mcshader-lsp' ) ) +
57- ( process . platform === 'win32' ? '.exe' : '' ) :
58- path . join ( this . context . globalStorageUri . fsPath , 'mcshader-lsp' )
55+ const lspBinary = process . env [ 'MCSHADER_DEBUG' ] ?
56+ this . context . asAbsolutePath ( path . join ( 'server' , 'target' , 'debug' , 'mcshader-lsp' ) ) +
57+ ( process . platform === 'win32' ? '.exe' : '' ) :
58+ path . join ( this . context . globalStorageUri . fsPath , 'mcshader-lsp' )
5959
6060 const filewatcherGlob = this . fileAssociationsToGlob ( this . getGLSLFileAssociations ( ) )
61-
61+
6262 this . client = await new LanguageClient ( this , lspBinary , filewatcherGlob ) . startServer ( )
63-
63+
6464 log . info ( 'language server started!' )
6565 }
6666
6767 fileAssociationsToGlob = ( associations : string [ ] ) : string => {
6868 return '**/*.{' . concat (
6969 associations . map ( s => s . substring ( s . indexOf ( '.' ) ) ) . join ( ',' )
70- ) + '}'
70+ ) + '}'
7171 }
7272
7373 getGLSLFileAssociations = ( ) : string [ ] => {
7474 const exts = [ '.fsh' , '.vsh' , '.gsh' , '.glsl' ]
75- const associations = vscode . workspace . getConfiguration ( 'files' ) . get ( 'associations' ) as { [ key : string ] : string }
76-
75+ const associations = vscode . workspace . getConfiguration ( 'files' ) . get ( 'associations' ) as { [ key : string ] : string }
76+
7777 Object . keys ( associations ) . forEach ( ( key ) => {
78- if ( associations [ key ] === 'glsl' ) {
79- exts . push ( key . substring ( key . indexOf ( '*' ) + 1 ) )
78+ if ( associations [ key ] === 'glsl' ) {
79+ exts . push ( key . substring ( key . indexOf ( '*' ) + 1 ) )
8080 }
8181 } )
8282
@@ -85,31 +85,31 @@ export class Extension {
8585
8686 registerCommand = ( name : string , f : ( e : Extension ) => commands . Command ) => {
8787 const cmd = f ( this )
88- this . context . subscriptions . push ( vscode . commands . registerCommand ( 'mcglsl.' + name , cmd ) )
88+ this . context . subscriptions . push ( vscode . commands . registerCommand ( 'mcglsl.' + name , cmd ) )
8989 }
9090
91- deactivate = async ( ) => {
91+ deactivate = async ( ) => {
9292 await this . lspClient . stop ( )
93- while ( this . context . subscriptions . length > 0 ) {
93+ while ( this . context . subscriptions . length > 0 ) {
9494 this . context . subscriptions . pop ( ) ?. dispose ( )
9595 }
9696 }
97-
97+
9898 public updateStatus = ( icon : string , text : string ) => {
9999 this . statusBarItem ?. dispose ( )
100100 this . statusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left )
101101 this . statusBarItem . text = icon + ' [mc-shader] ' + text
102102 this . statusBarItem . show ( )
103103 this . context . subscriptions . push ( this . statusBarItem )
104104 }
105-
105+
106106 public clearStatus = ( ) => {
107107 this . statusBarItem ?. dispose ( )
108108 }
109109
110110 private bootstrap = async ( ) => {
111111 mkdirSync ( this . extensionContext . globalStoragePath , { recursive : true } )
112-
112+
113113 const dest = path . join ( this . extensionContext . globalStoragePath , 'mcshader-lsp' + ( process . platform === 'win32' ? '.exe' : '' ) )
114114 const exists = await fs . stat ( dest ) . then ( ( ) => true , ( ) => false )
115115 if ( ! exists ) await this . state . updateServerVersion ( undefined )
@@ -123,7 +123,7 @@ export class Extension {
123123 log . warn ( `incompatible architecture/platform:\n\t${ process . arch } ${ process . platform } ` )
124124 return
125125 }
126-
126+
127127 if ( release . tag_name === this . state . serverVersion ) {
128128 log . info ( 'server version is same as extension:\n\t' , this . state . serverVersion )
129129 return
@@ -135,8 +135,8 @@ export class Extension {
135135
136136 const userResponse = await vscode . window . showInformationMessage (
137137 this . state . serverVersion == undefined ?
138- `Language server version ${ this . package . version } is not installed.` :
139- `An update is available. Upgrade from ${ this . state . serverVersion } to ${ release . tag_name } ?` ,
138+ `Language server version ${ this . package . version } is not installed.` :
139+ `An update is available. Upgrade from ${ this . state . serverVersion } to ${ release . tag_name } ?` ,
140140 'Download now'
141141 )
142142 if ( userResponse !== 'Download now' ) {
@@ -145,9 +145,16 @@ export class Extension {
145145 }
146146
147147 await download ( artifact . browser_download_url , dest )
148-
148+
149149 this . state . updateServerVersion ( release . tag_name )
150150 }
151151}
152152
153- export const activate = new Extension ( ) . activate
153+ export const activate = async ( context : vscode . ExtensionContext ) => {
154+ try {
155+ new Extension ( ) . activate ( context )
156+ } catch ( e ) {
157+ log . error ( `failed to activate extension: ${ e } ` )
158+ throw ( e )
159+ }
160+ }
0 commit comments