Skip to content

Commit a7f85e6

Browse files
committed
refactor(recipes): declare KnownEditor as a literal union
Write KnownEditor directly as a union of editor-command literals instead of deriving it via (typeof KNOWN_EDITORS)[number] — the tsnapi snapshot now prints the actual union instead of the indexed access expression. KNOWN_EDITORS is now typed against KnownEditor (as const satisfies readonly KnownEditor[]) to keep the two in sync.
1 parent e153305 commit a7f85e6

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

packages/devframe/src/recipes/common-rpc-functions.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,44 @@ import { defineRpcFunction } from '../rpc/define'
55
* Editor commands that `launch-editor` (the library behind
66
* `devframe/utils/launch-editor`) recognizes with a tailored
77
* `file:line:column` invocation. `openInEditor`'s optional second argument
8-
* is restricted to this list, so the RPC surface can't be used to spawn an
8+
* is restricted to this union, so the RPC surface can't be used to spawn an
99
* arbitrary command.
1010
*/
11+
export type KnownEditor
12+
= | 'atom'
13+
| 'subl'
14+
| 'sublime'
15+
| 'sublime_text'
16+
| 'wstorm'
17+
| 'charm'
18+
| 'zed'
19+
| 'notepad++'
20+
| 'vim'
21+
| 'mvim'
22+
| 'joe'
23+
| 'gvim'
24+
| 'emacs'
25+
| 'emacsclient'
26+
| 'rmate'
27+
| 'mate'
28+
| 'code'
29+
| 'code-insiders'
30+
| 'codium'
31+
| 'vscodium'
32+
| 'trae'
33+
| 'antigravity'
34+
| 'cursor'
35+
| 'appcode'
36+
| 'clion'
37+
| 'idea'
38+
| 'phpstorm'
39+
| 'pycharm'
40+
| 'rubymine'
41+
| 'webstorm'
42+
| 'goland'
43+
| 'rider'
44+
45+
/** Runtime list of every {@link KnownEditor}, in the order `v.picklist` reports them. */
1146
export const KNOWN_EDITORS = [
1247
'atom',
1348
'subl',
@@ -41,10 +76,7 @@ export const KNOWN_EDITORS = [
4176
'webstorm',
4277
'goland',
4378
'rider',
44-
] as const
45-
46-
/** One of the editor commands in {@link KNOWN_EDITORS}. */
47-
export type KnownEditor = (typeof KNOWN_EDITORS)[number]
79+
] as const satisfies readonly KnownEditor[]
4880

4981
/**
5082
* Prebuilt RPC action that opens a file in the user's configured editor.

tests/__snapshots__/tsnapi/devframe/recipes/common-rpc-functions.snapshot.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Generated by tsnapi — public API snapshot of `devframe/recipes/common-rpc-functions`
33
*/
44
// #region Types
5-
export type KnownEditor = (typeof KNOWN_EDITORS)[number];
5+
export type KnownEditor = 'atom' | 'subl' | 'sublime' | 'sublime_text' | 'wstorm' | 'charm' | 'zed' | 'notepad++' | 'vim' | 'mvim' | 'joe' | 'gvim' | 'emacs' | 'emacsclient' | 'rmate' | 'mate' | 'code' | 'code-insiders' | 'codium' | 'vscodium' | 'trae' | 'antigravity' | 'cursor' | 'appcode' | 'clion' | 'idea' | 'phpstorm' | 'pycharm' | 'rubymine' | 'webstorm' | 'goland' | 'rider';
66
// #endregion
77

88
// #region Variables

0 commit comments

Comments
 (0)