diff --git a/lib/package/commands.coffee b/lib/package/commands.coffee index feac6139..c2da337a 100644 --- a/lib/package/commands.coffee +++ b/lib/package/commands.coffee @@ -81,8 +81,9 @@ module.exports = "julia-client:clear-console": => juno.runtime.console.reset() 'julia-client:open-plot-pane': => @withInk -> juno.runtime.plots.open() 'julia-client:open-workspace': => @withInk -> juno.runtime.workspace.open() - 'julia-client:settings': -> - atom.workspace.open('atom://config/packages/julia-client') + 'julia-client:settings': -> atom.workspace.open('atom://config/packages/julia-client') + 'julia-debug:clear-all-breakpoints': => juno.runtime.debugger.clearall() + 'julia-debug:get-all-breakpoints': => juno.runtime.debugger.getBPs() 'julia-debug:step-to-next-line': => juno.runtime.debugger.nextline() 'julia-debug:step-to-next-expression': => juno.runtime.debugger.stepexpr() 'julia-debug:step-into-function': => juno.runtime.debugger.stepin() diff --git a/lib/runtime/completions.coffee b/lib/runtime/completions.coffee index 68009d7a..1921c7e6 100644 --- a/lib/runtime/completions.coffee +++ b/lib/runtime/completions.coffee @@ -15,6 +15,9 @@ module.exports = filterSuggestions: true excludeLowerPriority: false + sleep: (n) -> + new Promise((resolve) -> setTimeout(resolve, n*1000)) + getTextEditorSelector: -> 'atom-text-editor' rawCompletions: ({editor, bufferPosition: {row, column}, activatedManually}) -> @@ -41,9 +44,10 @@ module.exports = getSuggestions: (data) -> return [] unless client.isActive() and @validScope data.scopeDescriptor - @rawCompletions(data).then ({completions, prefix, mod}) => + cs = @rawCompletions(data).then ({completions, prefix, mod}) => return @fromCache mod, prefix if not completions? @processCompletions completions, prefix + Promise.race([cs, @sleep(1).then(->[])]) cache: {} diff --git a/lib/runtime/debugger.js b/lib/runtime/debugger.js index 94f57e2e..7c773577 100644 --- a/lib/runtime/debugger.js +++ b/lib/runtime/debugger.js @@ -1,4 +1,5 @@ 'use babel' +/** @jsx etch.dom */ import { CompositeDisposable } from 'atom' import { views } from '../ui' @@ -6,29 +7,28 @@ import { client } from '../connection' import workspace from './workspace' -let {nextline, stepin, finish, stepexpr} = - client.import(['nextline', 'stepin', 'finish', 'stepexpr']) +let {addsourcebp, removesourcebp, getbps, loadgallium} = + client.import(['addsourcebp', 'removesourcebp', 'getbps', 'loadgallium']) -let ink, active, stepper, subs +let ink, active, stepper, subs, breakpoints export function activate() { - subs = new CompositeDisposable + subs = new CompositeDisposable() - client.handle({ - debugmode: state => debugmode(state), - stepto: (file, line, text) => stepto(file, line, text) - }) - - subs.add(client.onDetached(() => debugmode(false))) + subs.add(client.onDetached(() => { + debugmode(false) + clearbps() + })) } export function deactivate() { + breakpoints.destroy() subs.dispose() } function activeError() { if (!active) { - atom.notifications.addError("You need to be debugging to do that.", { + atom.notifications.addError('You need to be debugging to do that.', { detail: 'You can start debugging by setting a breakpoint,\nor by calling `@step f(args...)`.', dismissable: true }) @@ -46,32 +46,57 @@ function debugmode(a) { } } -function stepto(file, line, text) { - stepper.goto(file, line-1) - stepper.setText(views.render(text)) - workspace.update() +client.handle({ + debugmode, + stepto(file, line, text) { + stepper.goto(file, line - 1) + stepper.setText(views.render(text)) + workspace.update() + }, + working() { client.ipc.loading.working() }, + doneWorking() { client.ipc.loading.done() } +}) + +export function finish() { requireDebugging(() => client.import('finish')()) } +export function nextline() { requireDebugging(() => client.import('nextline')()) } +export function stepexpr() { requireDebugging(() => client.import('stepexpr')()) } +export function stepin() { requireDebugging(() => client.import('stepin')()) } + +function bufferForFile(file) { + for (let ed of atom.workspace.getTextEditors()) { + if (ed.getBuffer().getPath() === file) + return ed.getBuffer() + } + return } -export function nextline() { requireDebugging(() => nextline()) } -export function stepin() { requireDebugging(() => stepin()) } -export function finish() { requireDebugging(() => finish()) } -export function stepexpr() { requireDebugging(() => stepexpr()) } +function bp(file, line) { + client.require(async () => { + let bp = breakpoints.toggle(file, line) + try { + await loadgallium() + let response = await ((bp ? addsourcebp : removesourcebp)(file, line+1)) + } catch (e) { + console.error('Setting breakpoint:', e) + breakpoints.toggle(file, line) + } + }) +} -let breakpoints = [] +export function clearbps() { + breakpoints.clear() + if (client.isActive()) client.import('clearbps')() +} -function bp(file, line) { - let existing - if ((existing = ink.breakpoints.get(file, line, breakpoints)[0]) != null) { - breakpoints = breakpoints.filter(x => x !== existing) - existing.destroy() - } else { - let thebp = ink.breakpoints.add(file, line) - breakpoints.push(thebp) - } +export function getBPs() { + console.log(getbps()) } export function togglebp(ed = atom.workspace.getActiveTextEditor()) { - if (!ed) return + if (!ed || !ed.getPath()) { + atom.notifications.addError('Need a saved file to add a breakpoint') + return + } ed.getCursors().map((cursor) => bp(ed.getPath(), cursor.getBufferPosition().row)) } @@ -85,5 +110,5 @@ export function consumeInk(i) { {icon: 'sign-in', command: 'julia-debug:step-into-function'} ] }) - subs.add(ink.breakpoints.addScope('source.julia')) + breakpoints = new ink.breakpoints('source.julia') } diff --git a/lib/ui/views.coffee b/lib/ui/views.coffee index 4ddf4f32..8434ef7c 100644 --- a/lib/ui/views.coffee +++ b/lib/ui/views.coffee @@ -30,7 +30,10 @@ module.exports = views = lazy: ({head, id}, opts) -> conn = client.conn - opts.registerLazy id + if opts.registerLazy? + opts.registerLazy id + else + console.warn 'Unregistered lazy view' view = @ink.tree.treeView @render(head, opts), [], onToggle: once => return unless client.conn == conn diff --git a/styles/julia-client.less b/styles/julia-client.less index 7cd797d2..666a3918 100644 --- a/styles/julia-client.less +++ b/styles/julia-client.less @@ -22,7 +22,7 @@ } atom-text-editor.editor { - .keyword.control.end.julia { + .syntax--keyword.syntax--end { opacity: 0.5; } }