Created
April 4, 2015 16:25
-
-
Save johanlunds/58519a4d630b9724167e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 2232eebb66837edb93b8f96d582c645a8a91f981 | |
Author: Johan Lundström <[email protected]> | |
Date: Mon Feb 23 20:45:42 2015 +0100 | |
WIP breakpoints (buggy) | |
diff --git a/lib/breakpoint-manager.coffee b/lib/breakpoint-manager.coffee | |
new file mode 100644 | |
index 0000000..4ae0165 | |
--- /dev/null | |
+++ b/lib/breakpoint-manager.coffee | |
@@ -0,0 +1,66 @@ | |
+{$} = require 'atom-space-pen-views' | |
+{CompositeDisposable} = require 'atom' | |
+_ = require 'underscore-plus' | |
+ | |
+module.exports = | |
+class BreakpointManager | |
+ | |
+ constructor: () -> | |
+ @breakpoints = [] | |
+ @disposables = new CompositeDisposable() | |
+ @subs = [] | |
+ @observeTextEditors() | |
+ | |
+ getBreakpoints: -> | |
+ @breakpoints | |
+ | |
+ observeTextEditors: -> | |
+ @disposables.add atom.workspace.observeTextEditors (editor) => | |
+ @addBreakpointsToEditor(editor) | |
+ | |
+ # Hack to get clicking in gutter to toggle breakpoint | |
+ # Taken from https://github.com/mark-hahn/node-ide/blob/master/lib/code-display.coffee | |
+ $shadowRoot = $(atom.views.getView(editor).shadowRoot) | |
+ $lineNumbers = $shadowRoot.children().find '.line-numbers' | |
+ @subs.push $lineNumbers.click (e) => | |
+ file = editor.getPath() | |
+ line = +$(e.target).closest('.line-number').attr 'data-buffer-row' | |
+ @toggleBreakpoint file, line | |
+ false | |
+ | |
+ toggleBreakpoint: (file, line) -> | |
+ line = line + 1 | |
+ existing = _.findWhere @breakpoints, file: file, line: line | |
+ if existing | |
+ existing.enabled = not existing.enabled | |
+ else | |
+ @breakpoints.push | |
+ file: file | |
+ line: line | |
+ enabled: true | |
+ | |
+ @refreshBreakpoints() | |
+ | |
+ refreshBreakpoints: -> | |
+ @addBreakpointsToEditor(editor) for editor in atom.workspace.getTextEditors() | |
+ | |
+ addBreakpointsToEditor: (editor) -> | |
+ # TODO: clear breakpoints first | |
+ | |
+ file = editor.getPath() | |
+ # if file # TODO: return? | |
+ # editor.rubyDebuggerBreakpoints = [] # TODO: when to remove? | |
+ for breakpoint in @breakpoints | |
+ if breakpoint.file is file | |
+ marker = editor.markBufferPosition [breakpoint.line - 1, 0] | |
+ decoration = editor.decorateMarker marker, @getDecorationData breakpoint | |
+ # editor.rubyDebuggerBreakpoints.push marker | |
+ | |
+ getDecorationData: (bp) -> | |
+ type: 'gutter' | |
+ class: 'ruby-debugger-breakpoint-' + (if bp.enabled then 'enabled' else 'disabled') | |
+ | |
+ # TODO: call | |
+ destroy: -> | |
+ @disposables.dispose() | |
+ sub.off() for sub in @subs | |
\ No newline at end of file | |
diff --git a/lib/ruby-debugger-view.coffee b/lib/ruby-debugger-view.coffee | |
index 76de3f2..f783ba3 100644 | |
--- a/lib/ruby-debugger-view.coffee | |
+++ b/lib/ruby-debugger-view.coffee | |
@@ -1,13 +1,8 @@ | |
module.exports = | |
class RubyDebuggerView | |
- constructor: (serializeState, client) -> | |
+ constructor: (serializeState, client, breakpointManager) -> | |
@client = client | |
- breakpoints = [ | |
- "/Users/johan_lunds/Documents/Kod/apoex2/app/controllers/care/authentication_controller.rb:18" | |
- "/Users/johan_lunds/Documents/Kod/apoex2/app/controllers/care/authentication_controller.rb:35" | |
- ] | |
- | |
# Create root element | |
@element = document.createElement('div') | |
@element.classList.add('ruby-debugger') | |
@@ -32,8 +27,8 @@ class RubyDebuggerView | |
message = document.createElement('button') | |
message.textContent = "Run cmd: " + cmd | |
message.addEventListener 'click', => | |
- for breakpoint in breakpoints | |
- @client.runCmd(cmd, breakpoint) | |
+ for breakpoint in breakpointManager.getBreakpoints() | |
+ @client.runCmd(cmd, "#{breakpoint.file}:#{breakpoint.line}") | |
# message.classList.add('message') | |
@element.appendChild(message) | |
diff --git a/lib/ruby-debugger.coffee b/lib/ruby-debugger.coffee | |
index 295d6cf..b1393ae 100644 | |
--- a/lib/ruby-debugger.coffee | |
+++ b/lib/ruby-debugger.coffee | |
@@ -1,5 +1,6 @@ | |
RubyDebuggerView = require './ruby-debugger-view' | |
RubyDebuggerClient = require './ruby-debugger-client' | |
+BreakpointManager = require './breakpoint-manager' | |
{CompositeDisposable} = require 'atom' | |
module.exports = RubyDebugger = | |
@@ -17,7 +18,8 @@ module.exports = RubyDebugger = | |
activate: (state) -> | |
@client = new RubyDebuggerClient() | |
- @rubyDebuggerView = new RubyDebuggerView(state.rubyDebuggerViewState, @client) | |
+ breakpointManager = new BreakpointManager() | |
+ @rubyDebuggerView = new RubyDebuggerView(state.rubyDebuggerViewState, @client, breakpointManager) | |
@modalPanel = atom.workspace.addBottomPanel(item: @rubyDebuggerView.getElement(), visible: false) | |
# Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable | |
diff --git a/package.json b/package.json | |
index 075ab49..6e611e8 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -12,6 +12,8 @@ | |
"atom": ">0.50.0" | |
}, | |
"dependencies": { | |
- "sax": "^0.6.1" | |
+ "atom-space-pen-views": "^2.0.4", | |
+ "sax": "^0.6.1", | |
+ "underscore-plus": "^1.6.6" | |
} | |
} | |
diff --git a/styles/ruby-debugger.atom-text-editor.less b/styles/ruby-debugger.atom-text-editor.less | |
new file mode 100644 | |
index 0000000..a7f9cbf | |
--- /dev/null | |
+++ b/styles/ruby-debugger.atom-text-editor.less | |
@@ -0,0 +1,47 @@ | |
+// The ui-variables file is provided by base themes provided by Atom. | |
+// | |
+// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less | |
+// for a full listing of what's available. | |
+@import "ui-variables"; | |
+@import "syntax-variables"; | |
+@import "octicon-utf-codes"; | |
+ | |
+// Very specific way to style the gutter numbers. Doing this so they show up | |
+// above the `.cursor-line` decorations applied when you select lines. | |
+// | |
+// A less specific way to select them would be | |
+// | |
+// `.gutter .line-number.gutter-green`{} | |
+// | |
+// But will be overridden by the `.cursor-line` decorations. | |
+:host .gutter .line-number { | |
+ &.ruby-debugger-breakpoint-enabled, | |
+ &.ruby-debugger-breakpoint-disabled { | |
+ color: white; | |
+ background-color: @syntax-color-added; | |
+ // .icon-right { | |
+ // display: inline-block; | |
+ // visibility: visible; | |
+ // &:before { | |
+ // content: @primitive-dot; | |
+ // position: relative; | |
+ // //left: -4px; | |
+ // top: -2px; | |
+ // } | |
+ // } | |
+ } | |
+ | |
+ &.ruby-debugger-breakpoint-enabled { | |
+ // .icon-right { | |
+ // color: cyan; | |
+ // } | |
+ } | |
+ &.ruby-debugger-breakpoint-disabled { | |
+ color: white; | |
+ background-color: @syntax-color-renamed; | |
+ | |
+ // .icon-right { | |
+ // color: gray; | |
+ // } | |
+ } | |
+} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment