client/atom/main.js in yoda-language-server-0.6.1 vs client/atom/main.js in yoda-language-server-0.6.2

- old
+ new

@@ -1,31 +1,30 @@ const { AutoLanguageClient } = require('atom-languageclient') const { spawn } = require('child_process') const { resolve } = require('path') +const busyMessages = { + text_document_hover: 'Preparing hover help', + text_document_signature_help: 'Preparing signature help', + text_document_completion: 'Completing', + text_document_definition: 'Finding definition', +}; + class YodaClient extends AutoLanguageClient { constructor() { super() + this.busyHandlers = {}; } preInitialization(connection) { - connection.onTelemetryEvent(({ type, phase, message }) => { - if (!this.busySignalService) { return; } - if (type != 'initialization') { return; } - - if (this.initializationBusyMessage) { - this.initializationBusyMessage.setTitle(message); - } else { - this.initializationBusyMessage = this.busySignalService.reportBusy(message); - } - }); + connection.onTelemetryEvent((event) => this.handleTelemetryEvent(event)); } postInitialization(_server) { - if (this.initializationBusyMessage) { - this.initializationBusyMessage.dispose(); - this.initializationBusyMessage = null; + if (this.busyHandlers.initialization) { + this.busyHandlers.initialization.dispose(); + this.busyHandlers.initialization = null; } } getGrammarScopes () { return ['source.ruby', 'source.rb', 'source.ruby.rails'] } getLanguageName () { return 'Ruby' } @@ -49,9 +48,47 @@ } _launchYoda(projectPath) { const commandOptions = { cwd: projectPath }; return spawn(this.getServerPath(), ['server'], commandOptions); + } + + handleTelemetryEvent(eventBody) { + if (!this.busySignalService || !eventBody) { return; } + switch (eventBody.type) { + case 'initialization': + return this.handleInitializationEvent(eventBody); + case 'text_document_hover': + case 'text_document_completion': + case 'text_document_signature_help': + case 'text_document_completion': + return this.handleBusyEvent(eventBody.type, eventBody); + default: + } + } + + handleInitializationEvent({ phase, message }) { + if (this.busyHandlers.initialization) { + this.busyHandlers.initialization.setTitle(message); + } else { + this.busyHandlers.initialization = this.busySignalService.reportBusy(message); + } + } + + handleBusyEvent(handlerName, { phase, message }) { + switch (phase) { + case 'begin': + if (!this.busyHandlers[handlerName]) { + this.busyHandlers[handlerName] = this.busySignalService.reportBusy("(Yoda) " + busyMessages[handlerName]); + } + break; + case 'end': + if (this.busyHandlers[handlerName]) { + this.busyHandlers[handlerName].dispose(); + this.busyHandlers[handlerName] = null; + } + break; + } } } module.exports = new YodaClient()