Skip to content

Commit 73df0f6

Browse files
committed
Merge pull request #3 from smashwilson/from-selection
Detect stack traces in the current selection
2 parents c849b82 + 008e88b commit 73df0f6

File tree

5 files changed

+43
-5
lines changed

5 files changed

+43
-5
lines changed

lib/main.coffee

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ EnterDialog = require './enter-dialog'
55
module.exports =
66

77
activate: (state) ->
8-
atom.workspaceView.command 'stacktrace:enter', ->
8+
atom.workspaceView.command 'stacktrace:paste', ->
99
atom.workspaceView.appendToTop new EnterDialog()
1010

11+
atom.workspaceView.command 'stacktrace:from-selection', ->
12+
selections = atom.workspace.getActiveEditor()?.getSelections()
13+
text = (s.getText() for s in (selections or [])).join ''
14+
atom.emit 'stacktrace:accept-trace', trace: text
15+
1116
StacktraceView.registerIn(atom.workspace)
1217

1318
atom.on 'stacktrace:accept-trace', ({trace}) =>

lib/stacktrace-view.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class StacktraceView extends View
99

1010
@content: (trace) ->
1111
tclass = if trace.isActive() then 'activated' else ''
12-
@div class: "stacktrace tool-panel padded #{tclass}", =>
12+
@div class: "stacktrace traceview tool-panel padded #{tclass}", =>
1313
@div class: 'panel padded', =>
1414
@h2 class: 'error-message', trace.message
1515
@p class: 'activate-control', =>

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "0.0.0",
55
"description": "Navigate stacktraces within Atom.",
66
"activationEvents": [
7-
"stacktrace:enter"
7+
"stacktrace:paste",
8+
"stacktrace:from-selection"
89
],
910
"repository": "https://github.com/smashwilson/stacktrace",
1011
"license": "MIT",

spec/fixtures/withtrace.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
this is a file with a stacktrace in it
2+
3+
/home/smash/samples/tracer/otherdir/file2.rb:6:in `block in outerfunction': whoops (RuntimeError)
4+
from /home/smash/samples/tracer/dir/file1.rb:3:in `innerfunction'
5+
from /home/smash/samples/tracer/otherdir/file2.rb:5:in `outerfunction'
6+
from /home/smash/samples/tracer/entry.rb:7:in `toplevel'
7+
from /home/smash/samples/tracer/entry.rb:10:in `<main>'
8+
9+
so i can test from-selection stuff

spec/main-spec.coffee

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
path = require 'path'
2+
13
{WorkspaceView} = require 'atom'
24
Stacktrace = require '../lib/main'
35

@@ -8,14 +10,35 @@ describe "Main", ->
810
atom.workspaceView = new WorkspaceView
911
activationPromise = atom.packages.activatePackage('stacktrace')
1012

11-
describe "when the stacktrace:enter event is triggered", ->
13+
describe 'when the stacktrace:paste event is triggered', ->
1214

1315
beforeEach ->
14-
atom.workspaceView.trigger 'stacktrace:enter'
16+
atom.workspaceView.trigger 'stacktrace:paste'
1517
waitsForPromise -> activationPromise
1618

1719
it 'activates the package', ->
1820
expect(atom.packages.isPackageActive 'stacktrace').toBe(true)
1921

2022
it 'displays the EnterDialog', ->
2123
expect(atom.workspaceView.find '.enter-dialog').toExist()
24+
25+
describe 'when the stacktrace:from-selection event is triggered', ->
26+
27+
beforeEach ->
28+
p = path.join __dirname, 'fixtures', 'withtrace.txt'
29+
editorPromise = atom.workspace.open(p)
30+
31+
waitsForPromise -> editorPromise
32+
33+
runs ->
34+
editorPromise.then (editor) ->
35+
editor.setSelectedBufferRange [[1, 0], [7, 0]]
36+
atom.workspaceView.trigger 'stacktrace:from-selection'
37+
38+
waitsForPromise -> activationPromise
39+
40+
it 'activates the package', ->
41+
expect(atom.packages.isPackageActive 'stacktrace').toBe(true)
42+
43+
it 'displays a StacktraceView', ->
44+
expect(atom.workspaceView.find '.traceview').toExist()

0 commit comments

Comments
 (0)