Skip to content

Commit

Permalink
main: .dispose() all the disposables
Browse files Browse the repository at this point in the history
  • Loading branch information
jdanbrown committed Apr 25, 2018
1 parent 890c741 commit 5f90415
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $ = null

MouseEventWhichDict = {"left click": 1, "middle click": 2, "right click": 3}
module.exports =
disposable: null
disposables: new CompositeDisposable()

config:
disableComplete:
Expand Down Expand Up @@ -50,26 +50,26 @@ module.exports =
@ctagsCache.activate()

@ctagsCache.initTags(atom.project.getPaths(), atom.config.get('atom-ctags.autoBuildTagsWhenActive'))
@disposable = atom.project.onDidChangePaths (paths)=>
@disposables.add atom.project.onDidChangePaths (paths)=>
@ctagsCache.initTags(paths, atom.config.get('atom-ctags.autoBuildTagsWhenActive'))

atom.commands.add 'atom-workspace', 'atom-ctags:rebuild', (e, cmdArgs)=>
@disposables.add atom.commands.add 'atom-workspace', 'atom-ctags:rebuild', (e, cmdArgs)=>
console.error "rebuild: ", e
@ctagsCache.cmdArgs = cmdArgs if Array.isArray(cmdArgs)
@createFileView().rebuild(true)
if t
clearTimeout(t)
t = null

atom.commands.add 'atom-workspace', 'atom-ctags:toggle-project-symbols', =>
@disposables.add atom.commands.add 'atom-workspace', 'atom-ctags:toggle-project-symbols', =>
@createFileView().toggleAll()

atom.commands.add 'atom-text-editor',
@disposables.add atom.commands.add 'atom-text-editor',
'atom-ctags:toggle-file-symbols': => @createFileView().toggle()
'atom-ctags:go-to-declaration': => @createFileView().goto()
'atom-ctags:return-from-declaration': => @createGoBackView().toggle()

atom.workspace.observeTextEditors (editor) =>
@disposables.add atom.workspace.observeTextEditors (editor) =>
editorView = atom.views.getView(editor)
{$} = require 'atom-space-pen-views' unless $
$(editorView).on 'mousedown', (event) =>
Expand All @@ -85,22 +85,20 @@ module.exports =
atom-ctags replaces and enhances the symbols-view package.
Therefore, symbols-view has been disabled."

atom.config.observe 'atom-ctags.disableComplete', =>
@disposables.add atom.config.observe 'atom-ctags.disableComplete', =>
return unless @provider
@provider.disabled = atom.config.get('atom-ctags.disableComplete')

initExtraTagsTime = null
atom.config.observe 'atom-ctags.extraTagFiles', =>
@disposables.add atom.config.observe 'atom-ctags.extraTagFiles', =>
clearTimeout initExtraTagsTime if initExtraTagsTime
initExtraTagsTime = setTimeout((=>
@ctagsCache.initExtraTags(atom.config.get('atom-ctags.extraTagFiles').split(" "))
initExtraTagsTime = null
), 1000)

deactivate: ->
if @disposable?
@disposable.dispose()
@disposable = null
@disposables.dispose()

if @fileView?
@fileView.destroy()
Expand Down

0 comments on commit 5f90415

Please sign in to comment.