Skip to content

Commit

Permalink
Merge pull request #683 from JunoLab/sp/debugfile
Browse files Browse the repository at this point in the history
debug file
  • Loading branch information
pfitzseb committed Feb 15, 2020
2 parents d6236ea + a04dea0 commit 4600251
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 60 deletions.
6 changes: 4 additions & 2 deletions keymaps/julia-client.cson.cmd
Expand Up @@ -9,15 +9,17 @@ Any global commands should either be non-default or, ideally, prefixed with `C-J
'.platform-darwin atom-text-editor[data-grammar="source julia"]:not(.mini),
ink-terminal.julia-terminal,
.ink-debugger-container':
'f5': 'julia-debug:run-file'
'cmd-f5': 'julia-debug:step-through-file'
'shift-f5': 'julia-debug:stop-debugging'
'f8': 'julia-debug:continue'
'shift-f8': 'julia-debug:step-to-selected-line'
'f9': 'julia-debug:toggle-breakpoint'
'shift-f9': 'julia-debug:toggle-conditional-breakpoint'
'f10': 'julia-debug:step-to-next-expression'
'shift-f10': 'julia-debug:step-to-next-line'
'f11': 'julia-debug:step-into-function'
'shift-f11': 'julia-debug:finish-function'
'f11': 'julia-debug:step-into'
'shift-f11': 'julia-debug:step-out'

# Julia atom-text-editor
'.platform-darwin atom-text-editor[data-grammar="source julia"]':
Expand Down
6 changes: 4 additions & 2 deletions keymaps/julia-client.cson.ctrl
Expand Up @@ -10,15 +10,17 @@ Any global commands should either be non-default or, ideally, prefixed with `C-J
.platform-linux atom-text-editor[data-grammar="source julia"]:not(.mini),
ink-terminal.julia-terminal,
.ink-debugger-container':
'f5': 'julia-debug:run-file'
'ctrl-f5': 'julia-debug:step-through-file'
'shift-f5': 'julia-debug:stop-debugging'
'f8': 'julia-debug:continue'
'shift-f8': 'julia-debug:step-to-selected-line'
'f9': 'julia-debug:toggle-breakpoint'
'shift-f9': 'julia-debug:toggle-conditional-breakpoint'
'f10': 'julia-debug:step-to-next-expression'
'shift-f10': 'julia-debug:step-to-next-line'
'f11': 'julia-debug:step-into-function'
'shift-f11': 'julia-debug:finish-function'
'f11': 'julia-debug:step-into'
'shift-f11': 'julia-debug:step-out'

# Julia atom-text-editor
'.platform-win32 atom-text-editor[data-grammar="source julia"],
Expand Down
2 changes: 1 addition & 1 deletion lib/julia-client.coffee
Expand Up @@ -8,7 +8,7 @@ toolbar = require './package/toolbar'
semver = require 'semver'

# TODO: Update me when tagging a new relase:
INK_VERSION_COMPAT = "^0.11.6"
INK_VERSION_COMPAT = "^0.12"

INK_LINK = '[`ink`](https://github.com/JunoLab/atom-ink)'
LANGUAGE_JULIA_LINK = '[`language-julia`](https://github.com/JuliaEditorSupport/atom-language-julia)'
Expand Down
25 changes: 25 additions & 0 deletions lib/misc/paths.coffee
Expand Up @@ -107,3 +107,28 @@ module.exports =
path.join packageRoot, s...

script: (s...) -> @packageDir 'script', s...

getPathFromTreeView: (el) ->
# invoked from tree-view context menu
pathEl = el.closest('[data-path]')
if not pathEl
# invoked from command with focusing on tree-view
activeEl = el.querySelector('.tree-view .selected')
pathEl = activeEl.querySelector('[data-path]') if activeEl
return pathEl.dataset.path if pathEl
return null

getDirPathFromTreeView: (el) ->
# invoked from tree-view context menu
dirEl = el.closest('.directory')
if not dirEl
# invoked from command with focusing on tree-view
activeEl = el.querySelector('.tree-view .selected')
dirEl = activeEl.closest('.directory') if activeEl
if dirEl
pathEl = dirEl.querySelector('[data-path]')
return pathEl.dataset.path if pathEl
return null

readCode: (path) ->
fs.readFileSync(path, 'utf-8')
57 changes: 52 additions & 5 deletions lib/package/commands.coffee
Expand Up @@ -67,8 +67,32 @@ module.exports =
done = true
juno.connection.client.stdin s.getText()
juno.connection.client.stdin ed.getText() unless done
'julia-debug:run-block': =>
@withInk ->
boot()
juno.runtime.debugger.debugBlock(false, false)
'julia-debug:step-through-block': =>
@withInk ->
boot()
juno.runtime.debugger.debugBlock(true, false)
'julia-debug:run-cell': =>
@withInk ->
boot()
juno.runtime.debugger.debugBlock(false, true)
'julia-debug:step-through-cell': =>
@withInk ->
boot()
juno.runtime.debugger.debugBlock(true, true)
'julia-debug:toggle-breakpoint': =>
@withInk ->
boot()
juno.runtime.debugger.togglebp()
'julia-debug:toggle-conditional-breakpoint': =>
@withInk ->
boot()
juno.runtime.debugger.togglebp(true)

# Only Julia atom-text-editor
# atom-text-editor with Julia grammar scope
@subs.add atom.commands.add 'atom-text-editor[data-grammar="source julia"]',
'julia-client:format-code': =>
@withInk ->
Expand All @@ -81,6 +105,22 @@ module.exports =
.ink-workspace',
'julia-client:set-working-module': -> juno.runtime.modules.chooseModule()

# tree-view
@subs.add atom.commands.add '.tree-view',
'julia-client:run-all': (ev) =>
cancelComplete ev
@withInk ->
boot()
juno.runtime.evaluation.evalAll(ev.target)
'julia-debug:run-file': (ev) =>
@withInk ->
boot()
juno.runtime.debugger.debugFile(false, ev.target)
'julia-debug:step-through-file': (ev) =>
@withInk ->
boot()
juno.runtime.debugger.debugFile(true, ev.target)

# atom-work-space
@subs.add atom.commands.add 'atom-workspace',
'julia-client:open-external-REPL': -> juno.connection.terminal.repl()
Expand All @@ -99,15 +139,22 @@ module.exports =
'julia-client:close-juno-panes': -> juno.ui.layout.closePromises()
'julia-client:reset-default-layout-settings': -> juno.ui.layout.resetDefaultLayoutSettings()
'julia-client:settings': -> atom.workspace.open('atom://config/packages/julia-client')
'julia-debug:toggle-breakpoint': => juno.runtime.debugger.togglebp()
'julia-debug:toggle-conditional-breakpoint': => juno.runtime.debugger.togglebp(true)

'julia-debug:run-file': =>
@withInk ->
boot()
juno.runtime.debugger.debugFile(false)
'julia-debug:step-through-file': =>
@withInk ->
boot()
juno.runtime.debugger.debugFile(true)
'julia-debug:clear-all-breakpoints': => juno.runtime.debugger.clearbps()
'julia-debug:step-to-next-line': (ev) => juno.runtime.debugger.nextline(ev)
'julia-debug:step-to-selected-line': (ev) => juno.runtime.debugger.toselectedline(ev)
'julia-debug:step-to-next-expression': (ev) => juno.runtime.debugger.stepexpr(ev)
'julia-debug:step-into-function': (ev) => juno.runtime.debugger.stepin(ev)
'julia-debug:step-into': (ev) => juno.runtime.debugger.stepin(ev)
'julia-debug:stop-debugging': (ev) => juno.runtime.debugger.stop(ev)
'julia-debug:finish-function': (ev) => juno.runtime.debugger.finish(ev)
'julia-debug:step-out': (ev) => juno.runtime.debugger.finish(ev)
'julia-debug:continue': (ev) => juno.runtime.debugger.continueForward(ev)
'julia-debug:open-debugger-pane': => juno.runtime.debugger.open()

Expand Down
10 changes: 10 additions & 0 deletions lib/package/menu.coffee
Expand Up @@ -55,10 +55,20 @@ module.exports =

{label: 'Run Block', command: 'julia-client:run-block'}
{label: 'Run All', command: 'julia-client:run-all'}

{type: 'separator'}

{label: 'Format Code', command: 'julia-client:format-code'}

{type: 'separator'}

{label: 'Debug: Run Block', command: 'julia-debug:run-block'}
{label: 'Debug: Step through Block', command: 'julia-debug:step-through-block'}
{label: 'Debug: Run File', command: 'julia-debug:run-file'}
{label: 'Debug: Step through File', command: 'julia-debug:step-through-file'}

{type: 'separator'}

{label: 'Open Workspace', command: 'julia-client:open-workspace'}
{label: 'Open Outline Pane', command: 'julia-client:open-outline-pane'}
{label: 'Open Documentation Browser', command: 'julia-client:open-documentation-browser'}
Expand Down
5 changes: 4 additions & 1 deletion lib/runtime/console.js
Expand Up @@ -70,7 +70,10 @@ export function activate (_ink) {
client.handle({
updateWorkspace: () => require('./workspace').update(),
clearconsole: () => terminal.clear(),
cursorpos: () => terminal.cursorPosition()
cursorpos: () => terminal.cursorPosition(),
writeToTerminal: (str) => {
terminal.ty.write(str)
}
})

let promptObserver
Expand Down
105 changes: 87 additions & 18 deletions lib/runtime/debugger.js
Expand Up @@ -5,29 +5,37 @@ import { CompositeDisposable } from 'atom'
import { views } from '../ui'
import { client } from '../connection'
import connection from '../connection'
import { blocks, cells, paths } from '../misc'
import modules from './modules'

import workspace from './workspace'

let {addsourcebp, removesourcebp, getbps} =
client.import(['addsourcebp', 'removesourcebp', 'getbps'])
const { debugfile, module: getmodule } = client.import(['debugfile', 'module'])

let active, stepper, subs, breakpoints, debuggerPane
let active, stepper, subs, breakpoints, debuggerPane, ink

export function activate (ink) {
export function activate (_ink) {
ink = _ink
const buttons = [
{icon: 'playback-fast-forward', tooltip: 'Debug: Continue', command: 'julia-debug:continue'},
{icon: 'link-external', tooltip: 'Debug: Finish Function', command: 'julia-debug:finish-function'},
{icon: 'arrow-down', tooltip: 'Debug: Next Line', command: 'julia-debug:step-to-next-line'},
{icon: 'playback-fast-forward', tooltip: 'Debug: Continue', command: 'julia-debug:continue', color: 'success'},
{icon: 'triangle-down', tooltip: 'Debug: Next Line', command: 'julia-debug:step-to-next-line'},
{icon: 'jump-down', tooltip: 'Debug: Step to Selected Line', command: 'julia-debug:step-to-selected-line'},
{icon: 'triangle-right', tooltip: 'Debug: Next Expression', command: 'julia-debug:step-to-next-expression'},
{icon: 'sign-in', tooltip: 'Debug: Step into Function', command: 'julia-debug:step-into-function'},
{icon: 'x', tooltip: 'Debug: Stop Debugging', command: 'julia-debug:stop-debugging'},
{icon: 'alignment-align', tooltip: 'Debug: Step Into', command: 'julia-debug:step-into'},
{icon: 'alignment-aligned-to', tooltip: 'Debug: Step Out', command: 'julia-debug:step-out'},
{icon: 'x', tooltip: 'Debug: Stop Debugging', command: 'julia-debug:stop-debugging', color: 'error'},
]
const startButtons = [
{text: 'Run File', tooltip: 'Debug: Run File', command: 'julia-debug:run-file'},
{text: 'Step Through File', tooltip: 'Debug: Step Through File', command: 'julia-debug:step-through-file'},
{text: 'Run Block', tooltip: 'Debug: Run Block', command: 'julia-debug:run-block'},
{text: 'Step Through Block', tooltip: 'Debug: Step Through Block', command: 'julia-debug:step-through-block'},
]
stepper = new ink.Stepper({
buttons: buttons,
pending: !atom.config.get('julia-client.uiOptions.openNewEditorWhenDebugging')
})
breakpoints = new ink.breakpoints('source.julia', {
breakpoints = new ink.breakpoints(atom.config.get('julia-client.juliaSyntaxScopes'), {
toggle: toggleJuliaBP,
clear: clearJulia,
toggleUncaught: toggleUncaughtJulia,
Expand All @@ -40,7 +48,7 @@ export function activate (ink) {
setLevel: setLevel,
toggleCompiled: toggleCompiled
})
debuggerPane = ink.DebuggerPane.fromId('julia-debugger-pane', stepper, breakpoints, buttons)
debuggerPane = ink.DebuggerPane.fromId('julia-debugger-pane', stepper, breakpoints, buttons, startButtons)

subs = new CompositeDisposable()
subs.add(atom.config.observe('julia-client.uiOptions.layouts.debuggerPane.defaultLocation', (defaultLocation) => {
Expand Down Expand Up @@ -90,14 +98,25 @@ function requireDebugging(ev, f) {
}
}

function requireNotDebugging(f) {
if (active) {
atom.notifications.addError('Can\'t start a debugging session while debugging.', {
description: 'Please finish the current session first.',
dismissable: true
})
} else {
f()
}
}

function debugmode(a) {
active = a
if (!active) {
stepper.destroy()
workspace.update()
debuggerPane.reset()
} else {
debuggerPane.open()
debuggerPane.ensureVisible()
}
}

Expand Down Expand Up @@ -136,12 +155,62 @@ export function toselectedline (ev) {
})
}

function bufferForFile(file) {
for (const ed of atom.workspace.getTextEditors()) {
if (ed.getBuffer().getPath() === file)
return ed.getBuffer()
}
return
export function debugFile(shouldStep, el) {
requireNotDebugging(() => {
if (el) {
const path = paths.getPathFromTreeView(el)
if (!path) {
atom.notifications.addError('This file has no path.')
return
}
try {
const code = paths.readCode(path)
const data = { path, code, row: 1, column: 1 }
getmodule(data).then(mod => {
debugfile(modules.current(mod), code, path, shouldStep)
})
} catch (err) {
atom.notifications.addError('Error happened', {
detail: err,
dismissable: true
})
}
} else {
const ed = atom.workspace.getActiveTextEditor()
if (!(ed && ed.getGrammar && ed.getGrammar().id === 'source.julia')) {
atom.notifications.addError('Can\'t debug current file.', {
description: 'Please make sure a Julia file is open in the workspace.'
})
return
}
const edpath = client.editorPath(ed) || 'untitled-' + ed.getBuffer().id
const mod = modules.current() || 'Main'
debugfile(mod, ed.getText(), edpath, shouldStep)
}
})
}

export function debugBlock(shouldStep, cell) {
requireNotDebugging(() => {
const ed = atom.workspace.getActiveTextEditor()
if (!ed) {
atom.notifications.addError('Can\'t debug current code block.', {
description: 'Please make sure a file is open in the workspace.'
})
return
}
const edpath = client.editorPath(ed) || 'untitled-' + ed.getBuffer().id
const mod = modules.current() || 'Main'
const selector = cell ? cells : blocks
const blks = selector.get(ed)
if (blks.length === 0) {
return
}
const { range, text, line } = blks[0]
const [[start], [end]] = range
ink.highlight(ed, start, end)
debugfile(mod, text, edpath, shouldStep, line)
})
}

export function clearbps() {
Expand Down

0 comments on commit 4600251

Please sign in to comment.