4
4
import * as Path from "path" ;
5
5
import * as FS from "fs" ;
6
6
import { window , workspace , ExtensionContext , commands , tasks , Task , TaskExecution , ShellExecution , Uri , TaskDefinition , languages , IndentAction , Progress , ProgressLocation , debug , DebugConfiguration , Range , Position , TextDocument , TextDocumentContentProvider , CancellationToken , ProviderResult , ConfigurationChangeEvent } from 'vscode' ;
7
- import { LanguageClient , LanguageClientOptions , ServerOptions , NotificationType } from "vscode-languageclient" ;
7
+ import { LanguageClient , LanguageClientOptions , ServerOptions , NotificationType } from "vscode-languageclient/node " ;
8
8
import { loadStyles , decoration } from './textMate' ;
9
9
import * as AdmZip from 'adm-zip' ;
10
10
@@ -17,7 +17,7 @@ export async function activate(context: ExtensionContext) {
17
17
18
18
// Teach VSCode to open JAR files
19
19
workspace . registerTextDocumentContentProvider ( 'jar' , new JarFileSystemProvider ( ) ) ;
20
-
20
+
21
21
// Options to control the language client
22
22
let clientOptions : LanguageClientOptions = {
23
23
// Register the server for java documents
@@ -42,7 +42,7 @@ export async function activate(context: ExtensionContext) {
42
42
let launcherRelativePath = platformSpecificLangServer ( ) ;
43
43
let launcherPath = [ context . extensionPath ] . concat ( launcherRelativePath ) ;
44
44
let launcher = Path . resolve ( ...launcherPath ) ;
45
-
45
+
46
46
// Start the child java process
47
47
let serverOptions : ServerOptions = {
48
48
command : launcher ,
@@ -58,19 +58,20 @@ export async function activate(context: ExtensionContext) {
58
58
59
59
// Create the language client and start the client.
60
60
let client = new LanguageClient ( 'java' , 'Java Language Server' , serverOptions , clientOptions ) ;
61
- let disposable = client . start ( ) ;
62
61
63
- // Push the disposable to the context's subscriptions so that the
62
+ // Push the client to the context's subscriptions so that the
64
63
// client can be deactivated on extension deactivation
65
- context . subscriptions . push ( disposable ) ;
64
+ context . subscriptions . push ( client ) ;
65
+
66
+ await client . start ( ) ;
66
67
67
68
// Register test commands
68
69
commands . registerCommand ( 'java.command.test.run' , runTest ) ;
69
70
commands . registerCommand ( 'java.command.test.debug' , debugTest ) ;
70
71
commands . registerCommand ( 'java.command.findReferences' , runFindReferences ) ;
71
72
72
- // When the language client activates, register a progress-listener
73
- client . onReady ( ) . then ( ( ) => createProgressListeners ( client ) ) ;
73
+ // Register a progress-listener
74
+ createProgressListeners ( client ) ;
74
75
75
76
// Apply semantic colors using custom notification
76
77
function asRange ( r : RangeLike ) {
@@ -119,12 +120,12 @@ export async function activate(context: ExtensionContext) {
119
120
applySemanticColors ( )
120
121
}
121
122
}
122
- client . onReady ( ) . then ( ( ) => {
123
- client . onNotification ( new NotificationType ( 'java/colors' ) , cacheSemanticColors ) ;
124
- context . subscriptions . push ( window . onDidChangeVisibleTextEditors ( applySemanticColors ) ) ;
125
- context . subscriptions . push ( workspace . onDidCloseTextDocument ( forgetSemanticColors ) ) ;
126
- context . subscriptions . push ( workspace . onDidChangeConfiguration ( onChangeConfiguration ) )
127
- } ) ;
123
+
124
+ client . onNotification ( new NotificationType ( 'java/colors' ) , cacheSemanticColors ) ;
125
+ context . subscriptions . push ( window . onDidChangeVisibleTextEditors ( applySemanticColors ) ) ;
126
+ context . subscriptions . push ( workspace . onDidCloseTextDocument ( forgetSemanticColors ) ) ;
127
+ context . subscriptions . push ( workspace . onDidChangeConfiguration ( onChangeConfiguration ) )
128
+
128
129
await loadStyles ( ) ;
129
130
applySemanticColors ( ) ;
130
131
}
@@ -259,7 +260,7 @@ function templateCommand(command: string[], file: string, className: string, met
259
260
}
260
261
261
262
interface ProgressMessage {
262
- message : string
263
+ message : string
263
264
increment : number
264
265
}
265
266
@@ -268,7 +269,7 @@ function createProgressListeners(client: LanguageClient) {
268
269
let progressListener = new class {
269
270
progress : Progress < { message : string , increment ?: number } >
270
271
resolve : ( nothing : { } ) => void
271
-
272
+
272
273
startProgress ( message : string ) {
273
274
if ( this . progress != null )
274
275
this . endProgress ( ) ;
@@ -278,11 +279,11 @@ function createProgressListeners(client: LanguageClient) {
278
279
this . resolve = resolve ;
279
280
} ) ) ;
280
281
}
281
-
282
+
282
283
reportProgress ( message : string , increment : number ) {
283
284
if ( increment == - 1 )
284
285
this . progress . report ( { message} ) ;
285
- else
286
+ else
286
287
this . progress . report ( { message, increment} )
287
288
}
288
289
@@ -340,10 +341,10 @@ function platformSpecificLangServer(): string[] {
340
341
// Alternative server options if you want to use visualvm
341
342
function visualVmConfig ( context : ExtensionContext ) : ServerOptions {
342
343
let javaExecutablePath = findJavaExecutable ( 'java' ) ;
343
-
344
+
344
345
if ( javaExecutablePath == null ) {
345
346
window . showErrorMessage ( "Couldn't locate java in $JAVA_HOME or $PATH" ) ;
346
-
347
+
347
348
throw "Gave up" ;
348
349
}
349
350
const jars = [
@@ -353,7 +354,7 @@ function visualVmConfig(context: ExtensionContext): ServerOptions {
353
354
] ;
354
355
const classpath = jars . map ( jar => Path . resolve ( context . extensionPath , "dist" , "classpath" , jar ) ) . join ( ':' ) ;
355
356
let args = [
356
- '-cp' , classpath ,
357
+ '-cp' , classpath ,
357
358
'-Xverify:none' , // helps VisualVM avoid 'error 62'
358
359
'-Xdebug' ,
359
360
// '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005',
@@ -369,9 +370,9 @@ function visualVmConfig(context: ExtensionContext): ServerOptions {
369
370
// Opens, needed at runtime for reflection
370
371
"--add-opens" , "jdk.compiler/com.sun.tools.javac.api=javacs" ,
371
372
] ;
372
-
373
+
373
374
console . log ( javaExecutablePath + ' ' + args . join ( ' ' ) ) ;
374
-
375
+
375
376
// Start the child java process
376
377
return {
377
378
command : javaExecutablePath ,
@@ -410,7 +411,7 @@ function findJavaExecutable(binname: string) {
410
411
// Then search PATH parts
411
412
if ( process . env [ 'PATH' ] ) {
412
413
console . log ( 'Looking for java in PATH' ) ;
413
-
414
+
414
415
let pathparts = process . env [ 'PATH' ] . split ( Path . delimiter ) ;
415
416
for ( let i = 0 ; i < pathparts . length ; i ++ ) {
416
417
let binpath = Path . join ( pathparts [ i ] , binname ) ;
@@ -419,8 +420,8 @@ function findJavaExecutable(binname: string) {
419
420
}
420
421
}
421
422
}
422
-
423
- // Else return the binary name directly (this will likely always fail downstream)
423
+
424
+ // Else return the binary name directly (this will likely always fail downstream)
424
425
return null ;
425
426
}
426
427
@@ -437,7 +438,7 @@ function findJavaExecutableInJavaHome(javaHome: string, binname: string) {
437
438
for ( let i = 0 ; i < workspaces . length ; i ++ ) {
438
439
let binpath = Path . join ( workspaces [ i ] , 'bin' , binname ) ;
439
440
440
- if ( FS . existsSync ( binpath ) )
441
+ if ( FS . existsSync ( binpath ) )
441
442
return binpath ;
442
443
}
443
444
0 commit comments