Skip to content

Commit 82eef12

Browse files
fix(devtools): open Sublime Text with the subl CLI (#1134)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent e727f2d commit 82eef12

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎packages/devtools/client/pages/settings.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const editorOptions = [
2828
['Zed', 'zed'],
2929
['Zed (zeditor)', 'zeditor'],
3030
['WebStorm', 'webstorm'],
31-
['Sublime Text', 'sublime'],
31+
['Sublime Text', 'subl'],
3232
['Atom', 'atom'],
3333
['Windsurf', 'windsurf'],
3434
]

‎packages/devtools/src/server-rpc/general.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ export function setupGeneralRPC({
210210
let editor = getOptions()?.behavior.openInEditor ?? undefined
211211
if (editor === 'auto')
212212
editor = undefined
213+
else if (editor === 'sublime')
214+
editor = 'subl'
213215
await import('devframe/utils/launch-editor').then(r => r.launchEditor(path + suffix, editor))
214216
return true
215217
}

‎packages/devtools/test/open-in-editor.test.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ import type { Nuxt } from 'nuxt/schema'
22
import type { NuxtDevtoolsServerContext } from '../src/types'
33
import fsp from 'node:fs/promises'
44
import { tmpdir } from 'node:os'
5+
import { launchEditor } from 'devframe/utils/launch-editor'
56
import { createHooks } from 'hookable'
67
import { join, normalize } from 'pathe'
78
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
89
import { setupGeneralRPC } from '../src/server-rpc/general'
10+
import { getOptions } from '../src/server-rpc/options'
911

10-
function fakeContext(root: string) {
12+
vi.mock('devframe/utils/launch-editor', () => ({
13+
launchEditor: vi.fn(),
14+
}))
15+
16+
vi.mock('../src/server-rpc/options', () => ({
17+
getOptions: vi.fn(),
18+
}))
19+
20+
function fakeContext(root: string, handledByHook = true) {
1121
const hooks = createHooks()
1222
const opened: string[] = []
1323
const ctx = {
@@ -23,7 +33,7 @@ function fakeContext(root: string) {
2333
refresh: () => {},
2434
openInEditorHooks: [(filepath: string) => {
2535
opened.push(filepath)
26-
return true
36+
return handledByHook
2737
}],
2838
} as unknown as NuxtDevtoolsServerContext
2939
return { ctx, opened }
@@ -37,6 +47,8 @@ describe('openInEditor', () => {
3747
await fsp.mkdir(join(root, 'apps/web/app/components'), { recursive: true })
3848
await fsp.writeFile(join(root, 'apps/web/app/components/Foo.vue'), '<template><div /></template>')
3949
vi.spyOn(process, 'cwd').mockReturnValue(join(root, 'apps/web'))
50+
vi.mocked(getOptions).mockReset()
51+
vi.mocked(launchEditor).mockClear()
4052
})
4153

4254
afterEach(async () => {
@@ -78,6 +90,19 @@ describe('openInEditor', () => {
7890
expect(opened).toEqual([filepath])
7991
})
8092

93+
it.each(['subl', 'sublime'])('opens Sublime Text with subl for the %s setting', async (setting) => {
94+
vi.mocked(getOptions).mockReturnValue({
95+
behavior: { openInEditor: setting },
96+
} as any)
97+
const { ctx, opened } = fakeContext(root, false)
98+
const { openInEditor } = setupGeneralRPC(ctx)
99+
const filepath = join(root, 'apps/web/app/components/Foo.vue')
100+
101+
await expect(openInEditor('app/components/Foo.vue')).resolves.toBe(true)
102+
expect(opened).toEqual([filepath])
103+
expect(launchEditor).toHaveBeenCalledWith(filepath, 'subl')
104+
})
105+
81106
it('reports a path that exists under none of the base directories', async () => {
82107
const error = vi.spyOn(console, 'error').mockImplementation(() => {})
83108
const { ctx, opened } = fakeContext(root)

0 commit comments

Comments
 (0)