Skip to content

Commit

Permalink
feat: add support for vscode like file schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinAgha authored and mxlje committed Apr 26, 2018
1 parent c5e54e2 commit 59c0b5e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ customize its behaviour:

### `editorScheme` `[?string]`
If a filename in the stack trace is local, the component can create the
link to open your editor using this scheme eg: `subl` to create
`subl://open?url=file:///filename`.
link to open your editor using this scheme eg:
- `subl` to create
`subl://open?url=file:///filename`.
- or `vscode` to create
`vscode://file/filename`.

### `useLines` `[boolean=true]`
Line numbers in the stack trace may be unreliable depending on the
Expand Down
12 changes: 11 additions & 1 deletion src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ export const makeUrl = (filename, scheme, line, column) => {

let url = `file://${actualFilename}`

if (scheme) {
if (scheme === 'vscode') {
url = `${scheme}://file/${url}`
url = url.replace(/file:\/\/\//, '') // visual studio code does not need file:/// in its scheme
if (line && actualFilename === filename) {
url = `${url}:${line}`

if (column) {
url = `${url}:${column}`
}
}
} else if (scheme) {
url = `${scheme}://open?url=${url}`

if (line && actualFilename === filename) {
Expand Down
31 changes: 31 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,37 @@ test('RedBoxError with filename and editorScheme', t => {
afterEach()
})

test('RedBoxError with filename and vscode like editorScheme', t => {
t.plan(1)
beforeEach(framesStub)
const error = new Error()
const filename = 'some-optional-webpack-loader!/filename'
const editorScheme = 'vscode'
const component = createComponent(RedBoxError, {error, filename, editorScheme})

const renderedStack = component
.props.children[1]

t.deepEqual(
renderedStack,
<div style={style.stack}>
<div style={style.frame} key={0}>
<div>App.render</div>
<div style={style.file}>
<a style={style.linkToFile} href="vscode://file/filename">/filename</a>
</div>
</div>
<div style={style.frame} key={1}>
<div>App.render</div>
<div style={style.file}>
<a style={style.linkToFile} href="webpack:///./~/react-hot-loader/~/react-hot-api/modules/makeAssimilatePrototype.js?">webpack:///./~/react-hot-loader/~/react-hot-api/modules/makeAssimilatePrototype.js?:17:41</a>
</div>
</div>
</div>
)
afterEach()
})

test('RedBoxError with absolute filenames', t => {
t.plan(1)
beforeEach(framesStubAbsoluteFilenames)
Expand Down

0 comments on commit 59c0b5e

Please sign in to comment.