Skip to content

Commit 627ecf4

Browse files
feat: improve go to source by using launch-editor (#121)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent dc7ad15 commit 627ecf4

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

.changeset/ripe-olives-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/devtools-vite': patch
3+
---
4+
5+
improve open-source by using a 3rd party package

docs/vite-plugin.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export default {
7171

7272
### editor
7373

74-
> [!IMPORTANT] `editor` is only needed for editors that are NOT VS Code, by default this works OOTB with VS Code. If you don't have `code` available in your terminal you need to set it up though, if you don't know how to do that you can follow this guide: https://stackoverflow.com/questions/29955500/code-is-not-working-in-on-the-command-line-for-visual-studio-code-on-os-x-ma
75-
74+
> [!IMPORTANT] `editor` is used as an escape hatch to implement your own go-to-source functionality if your system/editor does not work OOTB. We use `launch-editor` under the hood which supports a lot of editors but not all. If your editor is not supported you can implement your own version here. Here is the list of supported editors: https://github.com/yyx990803/launch-editor?tab=readme-ov-file#supported-editors
7675
7776
The open in editor configuration which has two fields, `name` and `open`,
7877
`name` is the name of your editor, and `open` is a function that opens the editor with the given file and line number. You can implement your version for your editor as follows:

packages/devtools-vite/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"@babel/traverse": "^7.28.3",
5858
"@babel/types": "^7.28.2",
5959
"@tanstack/devtools-event-bus": "workspace:*",
60-
"chalk": "^5.6.0"
60+
"chalk": "^5.6.0",
61+
"launch-editor": "^2.11.1"
6162
},
6263
"devDependencies": {
6364
"@types/babel__core": "^7.20.5",

packages/devtools-vite/src/editor.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ export type EditorConfig = {
2626
export const DEFAULT_EDITOR_CONFIG: EditorConfig = {
2727
name: 'VSCode',
2828
open: async (path, lineNumber, columnNumber) => {
29-
const { exec } = await import('node:child_process')
30-
exec(
31-
`code -g "${path.replaceAll('$', '\\$')}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}"`,
29+
const launch = (await import('launch-editor')).default
30+
launch(
31+
`${path.replaceAll('$', '\\$')}${lineNumber ? `:${lineNumber}` : ''}${columnNumber ? `:${columnNumber}` : ''}`,
32+
undefined,
33+
(filename, err) => {
34+
console.warn(`Failed to open ${filename} in editor: ${err}`)
35+
},
3236
)
3337
},
3438
}

pnpm-lock.yaml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)