1
1
'use strict'
2
+ import * as path from 'path'
2
3
3
- import semverCompare = require( 'semver-compare' )
4
- import { ExtensionContext , window , workspace } from 'vscode'
4
+ import { ExtensionContext , workspace } from 'vscode'
5
5
import {
6
6
LanguageClient ,
7
7
LanguageClientOptions ,
8
8
ServerOptions ,
9
+ TransportKind ,
9
10
} from 'vscode-languageclient'
10
11
11
- import { getServerInfo } from './util'
12
-
13
- const MINIMUM_SERVER_VERSION = '1.5.2'
14
-
15
12
export async function activate ( context : ExtensionContext ) {
16
- try {
17
- const { command, version } = await getServerInfo ( )
18
- if ( semverCompare ( version , MINIMUM_SERVER_VERSION ) === - 1 ) {
19
- return handleOutdatedExecutable ( )
20
- }
21
-
22
- const explainshellEndpoint = workspace
23
- . getConfiguration ( 'bashIde' )
24
- . get ( 'explainshellEndpoint' , '' )
13
+ const explainshellEndpoint = workspace
14
+ . getConfiguration ( 'bashIde' )
15
+ . get ( 'explainshellEndpoint' , '' )
25
16
26
- const highlightParsingErrors = workspace
27
- . getConfiguration ( 'bashIde' )
28
- . get ( 'highlightParsingErrors' , false )
17
+ const highlightParsingErrors = workspace
18
+ . getConfiguration ( 'bashIde' )
19
+ . get ( 'highlightParsingErrors' , false )
29
20
30
- start ( context , command , explainshellEndpoint , highlightParsingErrors )
31
- } catch ( error ) {
32
- handleStartError ( error )
33
- }
34
- }
35
-
36
- function start (
37
- context : ExtensionContext ,
38
- command : string ,
39
- explainshellEndpoint : string ,
40
- highlightParsingErrors : boolean ,
41
- ) {
42
21
const env : any = {
43
22
...process . env ,
44
23
EXPLAINSHELL_ENDPOINT : explainshellEndpoint ,
45
24
HIGHLIGHT_PARSING_ERRORS : highlightParsingErrors ,
46
25
}
47
26
48
- const serverOptions : ServerOptions = {
49
- run : {
50
- command,
51
- args : [ 'start' ] ,
52
- options : {
53
- env,
54
- } ,
55
- } ,
56
- debug : {
57
- command,
58
- args : [ 'start' ] ,
59
- options : {
60
- env,
61
- } ,
27
+ const serverExecutable = {
28
+ module : context . asAbsolutePath ( path . join ( 'out' , 'src' , 'server.js' ) ) ,
29
+ transport : TransportKind . ipc ,
30
+ options : {
31
+ env,
62
32
} ,
63
33
}
64
34
35
+ const serverOptions : ServerOptions = {
36
+ run : serverExecutable ,
37
+ debug : serverExecutable ,
38
+ }
39
+
65
40
const clientOptions : LanguageClientOptions = {
66
41
documentSelector : [
67
42
{
@@ -76,26 +51,11 @@ function start(
76
51
} ,
77
52
}
78
53
79
- const disposable = new LanguageClient (
80
- 'Bash IDE' ,
81
- 'Bash IDE' ,
82
- serverOptions ,
83
- clientOptions ,
84
- ) . start ( )
54
+ const client = new LanguageClient ( 'Bash IDE' , 'Bash IDE' , serverOptions , clientOptions )
55
+
56
+ // client.registerProposedFeatures();
85
57
86
58
// Push the disposable to the context's subscriptions so that the
87
59
// client can be deactivated on extension deactivation
88
- context . subscriptions . push ( disposable )
89
- }
90
-
91
- function handleOutdatedExecutable ( ) {
92
- const message = `Outdated bash server. Please upgrade by running "npm i -g bash-language-server".`
93
- window . showErrorMessage ( message , { modal : false } )
94
- }
95
-
96
- function handleStartError ( error : Error ) {
97
- const message =
98
- 'Unable to start bash-language-server, did you install it by running "npm i -g bash-language-server"? Open DevTools for additional details.'
99
- console . error ( error )
100
- window . showErrorMessage ( message , { modal : false } )
60
+ context . subscriptions . push ( client . start ( ) )
101
61
}
0 commit comments