Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 335ea79

Browse files
authored
Support Rls window/progress messages (#60)
Resolves #59
1 parent d260afb commit 335ea79

File tree

3 files changed

+93
-32
lines changed

3 files changed

+93
-32
lines changed

lib/rls-project.js

+63-15
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,53 @@ const _ = require('underscore-plus')
1111
class RlsProject {
1212
constructor(server, busySignalServiceFn) {
1313
this.server = server
14-
this.lastSentConfig = null
1514
this.getBusySignalService = busySignalServiceFn
15+
this._lastSentConfig = null
1616

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
1861
// - rustDocument/beginBuild
1962
// - rustDocument/diagnosticsBegin
2063
// - rustDocument/diagnosticsEnd
@@ -23,30 +66,35 @@ class RlsProject {
2366
// ie a `didChangeConfiguration` during a build, so we consider Rls
2467
// to be building as long as we're waiting for _any_ build.
2568
server.connection.onCustom('rustDocument/beginBuild', () => {
26-
if (this._busyMessage) {
27-
this._busyMessage.count += 1
69+
if (this._rustDocBusyMessage) {
70+
this._rustDocBusyMessage.count += 1
2871
}
2972
else {
3073
let busySignal = this.getBusySignalService()
3174
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
3578
}
3679
}
3780
})
3881
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
4184

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
4588
}
4689
}
4790
})
4891

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+
})
5098
}
5199

52100
// Send rls.toml as `workspace/didChangeConfiguration` message (or empty/default if no rls.toml)
@@ -63,12 +111,12 @@ class RlsProject {
63111
}
64112
}
65113

66-
if (_.isEqual(config, this.lastSentConfig)) return
114+
if (_.isEqual(config, this._lastSentConfig)) return
67115

68116
this.server.connection.didChangeConfiguration({
69117
settings: { rust: config }
70118
})
71-
this.lastSentConfig = config
119+
this._lastSentConfig = config
72120
})
73121
}
74122
}

package-lock.json

+29-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"underscore-plus": "^1.6.6"
2525
},
2626
"devDependencies": {
27-
"eslint": "^4.18.0"
27+
"eslint": "^4.18.1"
2828
},
2929
"scripts": {
3030
"test": "eslint lib test --max-warnings 0"

0 commit comments

Comments
 (0)