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

Support Rls window/progress messages #60

Merged
merged 2 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 63 additions & 15 deletions lib/rls-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,53 @@ const _ = require('underscore-plus')
class RlsProject {
constructor(server, busySignalServiceFn) {
this.server = server
this.lastSentConfig = null
this.getBusySignalService = busySignalServiceFn
this._lastSentConfig = null

// Rls sends 3 custom build notifications in sequence
/** @type {Map<string, BusyMessage>} */
this._progress = new Map()

/** @type {?BusyMessage} */
this._rustDocBusyMessage = null


// Rls (>= 2018-02-24) sends `window/progress` notifications
// see https://github.com/Microsoft/language-server-protocol/pull/245/files
server.connection.onCustom('window/progress', params => {
const busySignal = this.getBusySignalService()
if (!busySignal) return

let { id, title, message, percentage, done } = params
let busyMessage = this._progress.get(id)

if (done) {
if (busyMessage) busyMessage.dispose()
this._progress.delete(id)
}
else {
let busyText = `${path.basename(this.server.projectPath)} RLS ${title.toLowerCase()}`
if (busyMessage) {
// use previous percentages/messages according to the spec
percentage = percentage || busyMessage.lastProgressPercentage
message = message || busyMessage.lastProgressMessage
}
if (percentage) busyText += ` ${percentage.toFixed()}%`
if (message) busyText += `: ${message}`

if (busyMessage) {
busyMessage.setTitle(busyText)
}
else {
busyMessage = busySignal.reportBusy(busyText)
this._progress.set(id, busyMessage)
}

busyMessage.lastProgressPercentage = percentage
busyMessage.lastProgressMessage = message
}
})

// Rls (< 2018-02-24) sends 3 custom build notifications in sequence
// - rustDocument/beginBuild
// - rustDocument/diagnosticsBegin
// - rustDocument/diagnosticsEnd
Expand All @@ -23,30 +66,35 @@ class RlsProject {
// ie a `didChangeConfiguration` during a build, so we consider Rls
// to be building as long as we're waiting for _any_ build.
server.connection.onCustom('rustDocument/beginBuild', () => {
if (this._busyMessage) {
this._busyMessage.count += 1
if (this._rustDocBusyMessage) {
this._rustDocBusyMessage.count += 1
}
else {
let busySignal = this.getBusySignalService()
if (busySignal) {
this._busyMessage = busySignal
.reportBusy(`RLS building ${path.basename(this.server.projectPath)}`)
this._busyMessage.count = 1
this._rustDocBusyMessage = busySignal
.reportBusy(`${path.basename(this.server.projectPath)} RLS building`)
this._rustDocBusyMessage.count = 1
}
}
})
server.connection.onCustom('rustDocument/diagnosticsEnd', () => {
if (this._busyMessage && this._busyMessage.count > 0) {
this._busyMessage.count -= 1
if (this._rustDocBusyMessage && this._rustDocBusyMessage.count > 0) {
this._rustDocBusyMessage.count -= 1

if (this._busyMessage.count === 0) {
this._busyMessage.dispose()
this._busyMessage = null
if (this._rustDocBusyMessage.count === 0) {
this._rustDocBusyMessage.dispose()
this._rustDocBusyMessage = null
}
}
})

this.server.process.on('exit', () => this._busyMessage && this._busyMessage.dispose())
// clean up any busy messages
this.server.process.on('exit', () => {
this._progress.forEach(msg => msg.dispose())
this._progress.clear()
this._rustDocBusyMessage && this._rustDocBusyMessage.dispose()
})
}

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

if (_.isEqual(config, this.lastSentConfig)) return
if (_.isEqual(config, this._lastSentConfig)) return

this.server.connection.didChangeConfiguration({
settings: { rust: config }
})
this.lastSentConfig = config
this._lastSentConfig = config
})
}
}
Expand Down
45 changes: 29 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"underscore-plus": "^1.6.6"
},
"devDependencies": {
"eslint": "^4.18.0"
"eslint": "^4.18.1"
},
"scripts": {
"test": "eslint lib test --max-warnings 0"
Expand Down