@@ -11,10 +11,53 @@ const _ = require('underscore-plus')
11
11
class RlsProject {
12
12
constructor ( server , busySignalServiceFn ) {
13
13
this . server = server
14
- this . lastSentConfig = null
15
14
this . getBusySignalService = busySignalServiceFn
15
+ this . _lastSentConfig = null
16
16
17
- // Rls sends 3 custom build notifications in sequence
17
+ /** @type {Map<string, BusyMessage> } */
18
+ this . _progress = new Map ( )
19
+
20
+ /** @type {?BusyMessage } */
21
+ this . _rustDocBusyMessage = null
22
+
23
+
24
+ // Rls (>= 2018-02-24) sends `window/progress` notifications
25
+ // see https://github.com/Microsoft/language-server-protocol/pull/245/files
26
+ server . connection . onCustom ( 'window/progress' , params => {
27
+ const busySignal = this . getBusySignalService ( )
28
+ if ( ! busySignal ) return
29
+
30
+ let { id, title, message, percentage, done } = params
31
+ let busyMessage = this . _progress . get ( id )
32
+
33
+ if ( done ) {
34
+ if ( busyMessage ) busyMessage . dispose ( )
35
+ this . _progress . delete ( id )
36
+ }
37
+ else {
38
+ let busyText = `${ path . basename ( this . server . projectPath ) } RLS ${ title . toLowerCase ( ) } `
39
+ if ( busyMessage ) {
40
+ // use previous percentages/messages according to the spec
41
+ percentage = percentage || busyMessage . lastProgressPercentage
42
+ message = message || busyMessage . lastProgressMessage
43
+ }
44
+ if ( percentage ) busyText += ` ${ percentage . toFixed ( ) } %`
45
+ if ( message ) busyText += `: ${ message } `
46
+
47
+ if ( busyMessage ) {
48
+ busyMessage . setTitle ( busyText )
49
+ }
50
+ else {
51
+ busyMessage = busySignal . reportBusy ( busyText )
52
+ this . _progress . set ( id , busyMessage )
53
+ }
54
+
55
+ busyMessage . lastProgressPercentage = percentage
56
+ busyMessage . lastProgressMessage = message
57
+ }
58
+ } )
59
+
60
+ // Rls (< 2018-02-24) sends 3 custom build notifications in sequence
18
61
// - rustDocument/beginBuild
19
62
// - rustDocument/diagnosticsBegin
20
63
// - rustDocument/diagnosticsEnd
@@ -23,30 +66,35 @@ class RlsProject {
23
66
// ie a `didChangeConfiguration` during a build, so we consider Rls
24
67
// to be building as long as we're waiting for _any_ build.
25
68
server . connection . onCustom ( 'rustDocument/beginBuild' , ( ) => {
26
- if ( this . _busyMessage ) {
27
- this . _busyMessage . count += 1
69
+ if ( this . _rustDocBusyMessage ) {
70
+ this . _rustDocBusyMessage . count += 1
28
71
}
29
72
else {
30
73
let busySignal = this . getBusySignalService ( )
31
74
if ( busySignal ) {
32
- this . _busyMessage = busySignal
33
- . reportBusy ( `RLS building ${ path . basename ( this . server . projectPath ) } ` )
34
- this . _busyMessage . count = 1
75
+ this . _rustDocBusyMessage = busySignal
76
+ . reportBusy ( `${ path . basename ( this . server . projectPath ) } RLS building ` )
77
+ this . _rustDocBusyMessage . count = 1
35
78
}
36
79
}
37
80
} )
38
81
server . connection . onCustom ( 'rustDocument/diagnosticsEnd' , ( ) => {
39
- if ( this . _busyMessage && this . _busyMessage . count > 0 ) {
40
- this . _busyMessage . count -= 1
82
+ if ( this . _rustDocBusyMessage && this . _rustDocBusyMessage . count > 0 ) {
83
+ this . _rustDocBusyMessage . count -= 1
41
84
42
- if ( this . _busyMessage . count === 0 ) {
43
- this . _busyMessage . dispose ( )
44
- this . _busyMessage = null
85
+ if ( this . _rustDocBusyMessage . count === 0 ) {
86
+ this . _rustDocBusyMessage . dispose ( )
87
+ this . _rustDocBusyMessage = null
45
88
}
46
89
}
47
90
} )
48
91
49
- this . server . process . on ( 'exit' , ( ) => this . _busyMessage && this . _busyMessage . dispose ( ) )
92
+ // clean up any busy messages
93
+ this . server . process . on ( 'exit' , ( ) => {
94
+ this . _progress . forEach ( msg => msg . dispose ( ) )
95
+ this . _progress . clear ( )
96
+ this . _rustDocBusyMessage && this . _rustDocBusyMessage . dispose ( )
97
+ } )
50
98
}
51
99
52
100
// Send rls.toml as `workspace/didChangeConfiguration` message (or empty/default if no rls.toml)
@@ -63,12 +111,12 @@ class RlsProject {
63
111
}
64
112
}
65
113
66
- if ( _ . isEqual ( config , this . lastSentConfig ) ) return
114
+ if ( _ . isEqual ( config , this . _lastSentConfig ) ) return
67
115
68
116
this . server . connection . didChangeConfiguration ( {
69
117
settings : { rust : config }
70
118
} )
71
- this . lastSentConfig = config
119
+ this . _lastSentConfig = config
72
120
} )
73
121
}
74
122
}
0 commit comments