4
4
import * as vscode from 'vscode' ;
5
5
import * as path from "path" ;
6
6
import * as fs from "fs" ;
7
- import { LanguageClient , LanguageClientOptions , ServerOptions } from "vscode-languageclient" ;
7
+ import * as child_process from "child_process" ;
8
+ import { LanguageClient , LanguageClientOptions , ServerOptions } from "vscode-languageclient" ;
9
+ import { isOSUnixoid } from './osUtils' ;
10
+ import { LOG } from './logger' ;
8
11
9
12
// this method is called when your extension is activated
10
13
// your extension is activated the very first time the command is executed
11
14
export function activate ( context : vscode . ExtensionContext ) {
12
- console . log ( 'Activating Kotlin language server...' ) ;
15
+ LOG . info ( 'Activating Kotlin language server...' ) ;
13
16
14
17
let javaExecutablePath = findJavaExecutable ( 'java' ) ;
15
18
@@ -42,14 +45,20 @@ export function activate(context: vscode.ExtensionContext) {
42
45
}
43
46
let startScriptPath = path . resolve ( context . extensionPath , "build" , "install" , "kotlin-language-server" , "bin" , correctScriptName ( "kotlin-language-server" ) )
44
47
let args = [ ] ;
48
+
49
+ // Ensure that start script can be executed
50
+ if ( isOSUnixoid ( ) ) {
51
+ child_process . exec ( "chmod +x " + startScriptPath )
52
+ }
53
+
45
54
// Start the child java process
46
55
let serverOptions : ServerOptions = {
47
56
command : startScriptPath ,
48
57
args : args ,
49
58
options : { cwd : vscode . workspace . rootPath }
50
59
}
51
60
52
- console . log ( startScriptPath + ' ' + args . join ( ' ' ) ) ;
61
+ LOG . info ( "Launching {} with args {}" , startScriptPath , args . join ( ' ' ) ) ;
53
62
54
63
// Create the language client and start the client.
55
64
let languageClient = new LanguageClient ( 'kotlin' , 'Kotlin Language Server' , serverOptions , clientOptions ) ;
@@ -64,14 +73,14 @@ export function activate(context: vscode.ExtensionContext) {
64
73
export function deactivate ( ) {
65
74
}
66
75
67
- function findJavaExecutable ( binname : string ) {
68
- binname = correctBinname ( binname ) ;
76
+ function findJavaExecutable ( rawBinname : string ) {
77
+ let binname = correctBinname ( rawBinname ) ;
69
78
70
79
// First search java.home setting
71
80
let userJavaHome = vscode . workspace . getConfiguration ( 'java' ) . get ( 'home' ) as string ;
72
81
73
82
if ( userJavaHome != null ) {
74
- console . log ( ' Looking for java in settings java.home ' + userJavaHome + '...' ) ;
83
+ LOG . debug ( " Looking for Java in java.home (settings): {}" , userJavaHome ) ;
75
84
76
85
let candidate = findJavaExecutableInJavaHome ( userJavaHome , binname ) ;
77
86
@@ -83,7 +92,7 @@ function findJavaExecutable(binname: string) {
83
92
let envJavaHome = process . env [ 'JAVA_HOME' ] ;
84
93
85
94
if ( envJavaHome ) {
86
- console . log ( ' Looking for java in environment variable JAVA_HOME ' + envJavaHome + '...' ) ;
95
+ LOG . debug ( " Looking for Java in JAVA_HOME ( environment variable): {}" , envJavaHome ) ;
87
96
88
97
let candidate = findJavaExecutableInJavaHome ( envJavaHome , binname ) ;
89
98
@@ -93,7 +102,7 @@ function findJavaExecutable(binname: string) {
93
102
94
103
// Then search PATH parts
95
104
if ( process . env [ 'PATH' ] ) {
96
- console . log ( ' Looking for java in PATH' ) ;
105
+ LOG . debug ( " Looking for Java in PATH" ) ;
97
106
98
107
let pathparts = process . env [ 'PATH' ] . split ( path . delimiter ) ;
99
108
for ( let i = 0 ; i < pathparts . length ; i ++ ) {
@@ -104,8 +113,9 @@ function findJavaExecutable(binname: string) {
104
113
}
105
114
}
106
115
107
- // Else return the binary name directly (this will likely always fail downstream)
108
- return null ;
116
+ // Else return the binary name directly (this will likely always fail downstream)
117
+ LOG . debug ( "Could not find Java, will try using binary name directly" ) ;
118
+ return binname ;
109
119
}
110
120
111
121
function correctBinname ( binname : string ) {
@@ -131,4 +141,4 @@ function findJavaExecutableInJavaHome(javaHome: string, binname: string) {
131
141
if ( fs . existsSync ( binpath ) )
132
142
return binpath ;
133
143
}
134
- }
144
+ }
0 commit comments