@@ -6,7 +6,7 @@ import { log } from './log'
6
6
import { LanguageClient } from './lspClient'
7
7
import { download , getReleaseInfo } from './net'
8
8
import { PersistentState } from './persistent_state'
9
- import * as path from 'path'
9
+ import * as path from 'path'
10
10
11
11
const platforms : { [ key : string ] : string } = {
12
12
'x64 win32' : 'x86_64-windows-msvc' ,
@@ -26,21 +26,21 @@ export class Extension {
26
26
readonly package : {
27
27
version : string
28
28
} = vscode . extensions . getExtension ( this . extensionID ) ! . packageJSON ;
29
-
29
+
30
30
public get context ( ) : vscode . ExtensionContext {
31
31
return this . extensionContext
32
32
}
33
33
34
34
public get lspClient ( ) : lsp . LanguageClient {
35
35
return this . client
36
36
}
37
-
37
+
38
38
public activate = async ( context : vscode . ExtensionContext ) => {
39
39
this . extensionContext = context
40
40
this . state = new PersistentState ( context . globalState )
41
41
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 ( )
44
44
} else {
45
45
log . info ( 'skipping language server bootstrap' )
46
46
}
@@ -52,31 +52,31 @@ export class Extension {
52
52
53
53
log . info ( 'starting language server...' )
54
54
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' )
59
59
60
60
const filewatcherGlob = this . fileAssociationsToGlob ( this . getGLSLFileAssociations ( ) )
61
-
61
+
62
62
this . client = await new LanguageClient ( this , lspBinary , filewatcherGlob ) . startServer ( )
63
-
63
+
64
64
log . info ( 'language server started!' )
65
65
}
66
66
67
67
fileAssociationsToGlob = ( associations : string [ ] ) : string => {
68
68
return '**/*.{' . concat (
69
69
associations . map ( s => s . substring ( s . indexOf ( '.' ) ) ) . join ( ',' )
70
- ) + '}'
70
+ ) + '}'
71
71
}
72
72
73
73
getGLSLFileAssociations = ( ) : string [ ] => {
74
74
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
+
77
77
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 ) )
80
80
}
81
81
} )
82
82
@@ -85,31 +85,31 @@ export class Extension {
85
85
86
86
registerCommand = ( name : string , f : ( e : Extension ) => commands . Command ) => {
87
87
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 ) )
89
89
}
90
90
91
- deactivate = async ( ) => {
91
+ deactivate = async ( ) => {
92
92
await this . lspClient . stop ( )
93
- while ( this . context . subscriptions . length > 0 ) {
93
+ while ( this . context . subscriptions . length > 0 ) {
94
94
this . context . subscriptions . pop ( ) ?. dispose ( )
95
95
}
96
96
}
97
-
97
+
98
98
public updateStatus = ( icon : string , text : string ) => {
99
99
this . statusBarItem ?. dispose ( )
100
100
this . statusBarItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left )
101
101
this . statusBarItem . text = icon + ' [mc-shader] ' + text
102
102
this . statusBarItem . show ( )
103
103
this . context . subscriptions . push ( this . statusBarItem )
104
104
}
105
-
105
+
106
106
public clearStatus = ( ) => {
107
107
this . statusBarItem ?. dispose ( )
108
108
}
109
109
110
110
private bootstrap = async ( ) => {
111
111
mkdirSync ( this . extensionContext . globalStoragePath , { recursive : true } )
112
-
112
+
113
113
const dest = path . join ( this . extensionContext . globalStoragePath , 'mcshader-lsp' + ( process . platform === 'win32' ? '.exe' : '' ) )
114
114
const exists = await fs . stat ( dest ) . then ( ( ) => true , ( ) => false )
115
115
if ( ! exists ) await this . state . updateServerVersion ( undefined )
@@ -123,7 +123,7 @@ export class Extension {
123
123
log . warn ( `incompatible architecture/platform:\n\t${ process . arch } ${ process . platform } ` )
124
124
return
125
125
}
126
-
126
+
127
127
if ( release . tag_name === this . state . serverVersion ) {
128
128
log . info ( 'server version is same as extension:\n\t' , this . state . serverVersion )
129
129
return
@@ -135,8 +135,8 @@ export class Extension {
135
135
136
136
const userResponse = await vscode . window . showInformationMessage (
137
137
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 } ?` ,
140
140
'Download now'
141
141
)
142
142
if ( userResponse !== 'Download now' ) {
@@ -145,9 +145,16 @@ export class Extension {
145
145
}
146
146
147
147
await download ( artifact . browser_download_url , dest )
148
-
148
+
149
149
this . state . updateServerVersion ( release . tag_name )
150
150
}
151
151
}
152
152
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