diff --git a/src/grammar-registry.js b/src/grammar-registry.js index c1fb33803..b442b4693 100644 --- a/src/grammar-registry.js +++ b/src/grammar-registry.js @@ -21,9 +21,15 @@ class GrammarRegistry extends FirstMate.GrammarRegistry { constructor ({config} = {}) { super({maxTokensPerLine: 100, maxLineLength: 1000}) this.config = config + this.subscriptions = new CompositeDisposable() + } + + clear () { + super.clear() + if (this.subscriptions) this.subscriptions.dispose() + this.subscriptions = new CompositeDisposable() this.languageNameOverridesByBufferId = new Map() this.grammarScoresByBuffer = new Map() - this.subscriptions = new CompositeDisposable() const grammarAddedOrUpdated = this.grammarAddedOrUpdated.bind(this) this.onDidAddGrammar(grammarAddedOrUpdated) diff --git a/src/project.js b/src/project.js index dec5c4db5..8de92b97e 100644 --- a/src/project.js +++ b/src/project.js @@ -2,7 +2,7 @@ const path = require('path') const _ = require('underscore-plus') const fs = require('fs-plus') -const {Emitter, Disposable} = require('event-kit') +const {Emitter, Disposable, CompositeDisposable} = require('event-kit') const TextBuffer = require('text-buffer') const {watchPath} = require('./path-watcher') @@ -37,6 +37,7 @@ class Project extends Model { this.watcherPromisesByPath = {} this.retiredBufferIDs = new Set() this.retiredBufferPaths = new Set() + this.subscriptions = new CompositeDisposable() this.consumeServices(packageManager) } @@ -56,6 +57,9 @@ class Project extends Model { this.emitter.dispose() this.emitter = new Emitter() + this.subscriptions.dispose() + this.subscriptions = new CompositeDisposable() + for (let buffer of this.buffers) { if (buffer != null) buffer.destroy() } @@ -658,7 +662,7 @@ class Project extends Model { addBuffer (buffer, options = {}) { this.buffers.push(buffer) - this.grammarRegistry.maintainLanguageMode(buffer) + this.subscriptions.add(this.grammarRegistry.maintainLanguageMode(buffer)) this.subscribeToBuffer(buffer) this.emitter.emit('did-add-buffer', buffer) return buffer