@@ -2,22 +2,34 @@ import { LanguageClient, ServerOptions, LanguageClientOptions, StreamInfo } from
2
2
3
3
import * as vscode from 'vscode'
4
4
import { spawn } from 'child_process'
5
- import { existsSync , mkdir , mkdirSync } from 'fs'
6
- import { basename , dirname } from 'path'
5
+ import { existsSync , mkdirSync } from 'fs'
6
+ import { dirname } from 'path'
7
7
import * as net from 'net'
8
8
9
9
const LanguageID = 'php'
10
10
11
11
let languageClient : LanguageClient
12
12
13
+ interface PhpactorConfig {
14
+ path ?: string
15
+ enable : boolean
16
+ config : any
17
+ remote : {
18
+ enabled : boolean
19
+ host : string
20
+ port : number
21
+ }
22
+ launchServerArgs : string [ ]
23
+ }
24
+
13
25
export async function activate ( context : vscode . ExtensionContext ) : Promise < void > {
14
26
if ( process . platform === 'win32' ) {
15
- vscode . window . showWarningMessage ( 'Phpactor is not supported on Windows.' )
27
+ void vscode . window . showWarningMessage ( 'Phpactor is not supported on Windows.' )
16
28
return
17
29
}
18
30
19
- let workspaceConfig = vscode . workspace . getConfiguration ( )
20
- const config = workspaceConfig . get ( 'phpactor' ) as any
31
+ const workspaceConfig = vscode . workspace . getConfiguration ( )
32
+ const config = workspaceConfig . get < PhpactorConfig > ( 'phpactor' ) !
21
33
const enable = config . enable
22
34
23
35
if ( ! config . path ) {
@@ -37,13 +49,13 @@ export function deactivate(): Promise<void> | undefined {
37
49
return languageClient . stop ( )
38
50
}
39
51
40
- function getServerOptions ( config ) : ServerOptions {
52
+ function getServerOptions ( config : PhpactorConfig ) : ServerOptions {
41
53
let serverOptions
42
54
if ( ! config . remote . enabled ) {
43
55
// launch language server via stdio
44
56
serverOptions = {
45
57
run : {
46
- command : config . path ,
58
+ command : config . path ! ,
47
59
args : [ 'language-server' , ...config . launchServerArgs ] ,
48
60
} ,
49
61
debug : {
@@ -55,13 +67,13 @@ function getServerOptions(config): ServerOptions {
55
67
// credits: https://github.com/itemis/xtext-languageserver-example/blob/master/vscode-extension/src/extension.ts
56
68
// launch language server via socket
57
69
serverOptions = ( ) => {
58
- let { host, port } = config . remote
59
- let socket = net . connect ( {
70
+ const { host, port } = config . remote
71
+ const socket = net . connect ( {
60
72
host,
61
73
port,
62
74
} )
63
75
64
- let result = /* <StreamInfo>*/ {
76
+ const result = < StreamInfo > {
65
77
writer : socket ,
66
78
reader : socket ,
67
79
}
@@ -73,10 +85,10 @@ function getServerOptions(config): ServerOptions {
73
85
return serverOptions
74
86
}
75
87
76
- function createClient ( config : any ) : LanguageClient {
77
- let serverOptions = getServerOptions ( config )
88
+ function createClient ( config : PhpactorConfig ) : LanguageClient {
89
+ const serverOptions = getServerOptions ( config )
78
90
79
- let clientOptions : LanguageClientOptions = {
91
+ const clientOptions : LanguageClientOptions = {
80
92
documentSelector : [
81
93
{ language : LanguageID , scheme : 'file' } ,
82
94
{ language : 'blade' , scheme : 'file' } ,
@@ -91,7 +103,7 @@ function createClient(config: any): LanguageClient {
91
103
vscode . commands . registerCommand ( 'phpactor.config.dump' , dumpConfig )
92
104
vscode . commands . registerCommand ( 'phpactor.services.list' , servicesList )
93
105
vscode . commands . registerCommand ( 'phpactor.status' , status )
94
- const updateConfig = { cwd : dirname ( dirname ( config . path ) ) }
106
+ const updateConfig = { cwd : dirname ( dirname ( config . path ! ) ) }
95
107
vscode . commands . registerCommand ( 'phpactor.update' , updatePhpactor , updateConfig )
96
108
97
109
return languageClient
@@ -102,7 +114,7 @@ function reindex(): void {
102
114
return
103
115
}
104
116
105
- languageClient . sendRequest ( 'indexer/reindex' )
117
+ void languageClient . sendRequest ( 'indexer/reindex' )
106
118
}
107
119
108
120
async function dumpConfig ( ) : Promise < void > {
@@ -121,7 +133,7 @@ function servicesList(): void {
121
133
return
122
134
}
123
135
124
- languageClient . sendRequest ( 'service/running' )
136
+ void languageClient . sendRequest ( 'service/running' )
125
137
}
126
138
127
139
async function status ( ) : Promise < any > {
@@ -144,22 +156,22 @@ async function installPhpactor(storagePath: string): Promise<string> {
144
156
145
157
if ( ! existsSync ( path ) ) {
146
158
const channel = vscode . window . createOutputChannel ( 'Phpactor Installation' )
147
- vscode . window . showInformationMessage ( 'Installing Phpactor' )
159
+ void vscode . window . showInformationMessage ( 'Installing Phpactor' )
148
160
await exec ( channel , 'git' , [ 'clone' , 'https://github.com/phpactor/phpactor' , '--depth=1' ] , storagePath )
149
161
await exec ( channel , 'composer' , [ 'install' , '--no-dev' ] , path )
150
- vscode . window . showInformationMessage ( `Phpactor installed at ${ path } ` )
162
+ void vscode . window . showInformationMessage ( `Phpactor installed at ${ path } ` )
151
163
}
152
164
153
165
return `${ storagePath } /phpactor/bin/phpactor`
154
166
}
155
167
156
- export async function updatePhpactor ( ) : Promise < void > {
168
+ export async function updatePhpactor ( this : { cwd : string } ) : Promise < void > {
157
169
const channel = vscode . window . createOutputChannel ( 'Phpactor Update' )
158
170
channel . appendLine ( this . cwd )
159
171
await exec ( channel , 'git' , [ 'pull' ] , this . cwd )
160
172
await exec ( channel , 'composer' , [ 'install' , '--no-dev' ] , this . cwd )
161
173
channel . appendLine ( 'Phpactor updated' )
162
- vscode . window . showInformationMessage ( 'Phpactor updated' )
174
+ void vscode . window . showInformationMessage ( 'Phpactor updated' )
163
175
}
164
176
165
177
function exec ( channel : vscode . OutputChannel , command : string , args : string [ ] , cwd : string ) : Promise < void > {
@@ -168,10 +180,10 @@ function exec(channel: vscode.OutputChannel, command: string, args: string[], cw
168
180
cwd,
169
181
timeout : 30000 ,
170
182
} )
171
- child . stdout . on ( 'data' , data => {
183
+ child . stdout . on ( 'data' , ( data : Buffer ) => {
172
184
channel . append ( data . toString ( 'utf8' ) )
173
185
} )
174
- child . stderr . on ( 'data' , data => {
186
+ child . stderr . on ( 'data' , ( data : Buffer ) => {
175
187
channel . append ( data . toString ( 'utf8' ) )
176
188
} )
177
189
child . on ( 'close' , code => {
0 commit comments