<commit_before>{CompositeDisposable} = require 'atom'

_ = require 'lodash'


Config = require './config'
KernelManager = require './kernel-manager'
ResultView = require './result-view'
SignalListView = require './signal-list-view'
WatchSidebar = require './watch-sidebar'
KernelPicker = require './kernel-picker'
AutocompleteProvider = require './autocomplete-provider'
Inspector = require './inspector'
CellManager = require './cell-manager'

module.exports = Hydrogen =
    config: Config.schema

    subscriptions: null

    statusBarElement: null
    statusBarTile: null

    editor: null

    markerBubbleMap: {}

    activate: (state) ->
        @subscriptions = new CompositeDisposable

        @subscriptions.add atom.commands.add 'atom-text-editor',
            'hydrogen:run': => @run()
            'hydrogen:run-all': => @runAll()
            'hydrogen:run-all-above': => @runAllAbove()
            'hydrogen:run-and-move-down': => @runAndMoveDown()
            'hydrogen:run-cell': => @runCell()
            'hydrogen:run-cell-and-move-down': => @runCellAndMoveDown()
            'hydrogen:toggle-watches': => @toggleWatchSidebar()
            'hydrogen:select-watch-kernel': => @showWatchKernelPicker()
            'hydrogen:select-kernel': => @showKernelPicker()
            'hydrogen:add-watch': => @watchSidebar.addWatchFromEditor()
            'hydrogen:remove-watch': => @watchSidebar.removeWatch()
            'hydrogen:update-kernels': -> KernelManager.updateKernelSpecs()
            'hydrogen:inspect': -> Inspector.inspect()
            'hydrogen:interrupt-kernel': =>
                @handleKernelCommand command: 'interrupt-kernel'
            'hydrogen:restart-kernel': =>
                @handleKernelCommand command: 'restart-kernel'
            'hydrogen:toggle-breakpoint': ->
                CellManager.toggleBreakpoint()
            'hydrogen:remove-all-breakpoints': ->
                CellManager.removeAllBreakpoints()

        @subscriptions.add atom.commands.add 'atom-workspace',
            'hydrogen:clear-results': => @clearResultBubbles()
            'hydrogen:toggle-inspector-size': -> Inspector.toggleInspectorSize()
            'hydrogen:close-inspector': -> Inspector.closeInspector()

        @editor = atom.workspace.getActiveTextEditor()
        @subscriptions.add atom.workspace.observeActivePaneItem (item) =>
            @editor = item
            @setStatusBarElement()

        KernelManager.updateKernelSpecs()


    deactivate: ->
        @subscriptions.dispose()
        KernelManager.destroy()
        @statusBarTile.destroy()


    consumeStatusBar: (statusBar) ->
        console.log 'making status bar'
        @statusBarElement = document.createElement('div')
        @statusBarElement.classList.add('hydrogen')
        @statusBarElement.classList.add('status-container')
        @statusBarElement.onclick = @showKernelCommands.bind @
        @statusBarTile = statusBar.addLeftTile
            item: @statusBarElement, priority: 100


    provide: ->
        if atom.config.get('Hydrogen.autocomplete') is true
            return AutocompleteProvider


    showKernelCommands: ->
        unless @signalListView?
            @signalListView = new SignalListView()
            @signalListView.onConfirmed = (kernelCommand) =>
                @handleKernelCommand kernelCommand
        @signalListView.toggle()


    handleKernelCommand: ({kernel, command, grammar, language, kernelSpec}) ->
        console.log 'handleKernelCommand:', arguments<commit_msg>Move creation of status bar element to constructor<commit_after>{CompositeDisposable} = require 'atom'

_ = require 'lodash'


Config = require './config'
KernelManager = require './kernel-manager'
ResultView = require './result-view'
SignalListView = require './signal-list-view'
WatchSidebar = require './watch-sidebar'
KernelPicker = require './kernel-picker'
AutocompleteProvider = require './autocomplete-provider'
Inspector = require './inspector'
CellManager = require './cell-manager'

module.exports = Hydrogen =
    config: Config.schema

    subscriptions: null

    statusBarElement: null
    statusBarTile: null

    editor: null

    markerBubbleMap: {}

    activate: (state) ->
        @subscriptions = new CompositeDisposable

        @subscriptions.add atom.commands.add 'atom-text-editor',
            'hydrogen:run': => @run()
            'hydrogen:run-all': => @runAll()
            'hydrogen:run-all-above': => @runAllAbove()
            'hydrogen:run-and-move-down': => @runAndMoveDown()
            'hydrogen:run-cell': => @runCell()
            'hydrogen:run-cell-and-move-down': => @runCellAndMoveDown()
            'hydrogen:toggle-watches': => @toggleWatchSidebar()
            'hydrogen:select-watch-kernel': => @showWatchKernelPicker()
            'hydrogen:select-kernel': => @showKernelPicker()
            'hydrogen:add-watch': => @watchSidebar.addWatchFromEditor()
            'hydrogen:remove-watch': => @watchSidebar.removeWatch()
            'hydrogen:update-kernels': -> KernelManager.updateKernelSpecs()
            'hydrogen:inspect': -> Inspector.inspect()
            'hydrogen:interrupt-kernel': =>
                @handleKernelCommand command: 'interrupt-kernel'
            'hydrogen:restart-kernel': =>
                @handleKernelCommand command: 'restart-kernel'
            'hydrogen:toggle-breakpoint': ->
                CellManager.toggleBreakpoint()
            'hydrogen:remove-all-breakpoints': ->
                CellManager.removeAllBreakpoints()

        @subscriptions.add atom.commands.add 'atom-workspace',
            'hydrogen:clear-results': => @clearResultBubbles()
            'hydrogen:toggle-inspector-size': -> Inspector.toggleInspectorSize()
            'hydrogen:close-inspector': -> Inspector.closeInspector()

        @statusBarElement = document.createElement('div')
        @statusBarElement.classList.add('hydrogen')
        @statusBarElement.classList.add('status-container')
        @statusBarElement.onclick = @showKernelCommands.bind @

        @editor = atom.workspace.getActiveTextEditor()

        @subscriptions.add atom.workspace.observeActivePaneItem (item) =>
            @editor = item
            @setStatusBarElement()

        KernelManager.updateKernelSpecs()


    deactivate: ->
        @subscriptions.dispose()
        KernelManager.destroy()
        @statusBarTile.destroy()


    consumeStatusBar: (statusBar) ->
        @statusBarTile = statusBar.addLeftTile
            item: @statusBarElement, priority: 100


    provide: ->
        if atom.config.get('Hydrogen.autocomplete') is true
            return AutocompleteProvider


    showKernelCommands: ->
        unless @signalListView?
            @signalListView = new SignalListView()
            @signalListView.onConfirmed = (kernelCommand) =>
                @handleKernelCommand kernelCommand
        @signalListView.toggle()


    handleKernelCommand: ({kernel, command, grammar, language, kernelSpec}) ->
        console.log 'handleKernelCommand:', arguments
{'fraction_non_alphanumeric': 0.12434275969873526, 'fraction_numerical': 0.0008526360665056132, 'mean_word_length': 2.769683985002678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4892270', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1805, 'n_words': 318}