@@ -16,6 +16,12 @@ import {
1616import { basename , dirname , join } from "../../deno_ral/path.ts" ;
1717import { existsSync } from "../../deno_ral/fs.ts" ;
1818import { isMac , isWindows } from "../../deno_ral/platform.ts" ;
19+ import {
20+ enforcer ,
21+ makeStringEnumTypeFunctions ,
22+ objectPredicate ,
23+ stringTypePredicate ,
24+ } from "../../typing/dynamic.ts" ;
1925
2026export interface Editor {
2127 // A short, command line friendly id
@@ -77,11 +83,14 @@ interface EditorInfo {
7783 open : ( path : string , createResult : CreateResult ) => ( ) => Promise < void > ;
7884}
7985
80- interface ScanAction {
81- action : "path" | "which" | "env" ;
86+ const scanActionActions = [ "path" , "which" , "env" ] as const ;
87+ type ScanActionAction = typeof scanActionActions [ number ] ;
88+
89+ type ScanAction = {
90+ action : ScanActionAction ;
8291 arg : string ;
8392 filter ?: ( path : string ) => string ;
84- }
93+ } ;
8594
8695function vscodeEditorInfo ( ) : EditorInfo {
8796 const editorInfo : EditorInfo = {
@@ -110,29 +119,26 @@ function vscodeEditorInfo(): EditorInfo {
110119 action : "which" ,
111120 arg : "code.exe" ,
112121 } ) ;
113- const pathActions = windowsAppPaths ( "Microsoft VS Code" , "code.exe" ) . map (
114- ( path ) => {
115- return {
116- action : "path" ,
117- arg : path ,
118- } as ScanAction ;
119- } ,
120- ) ;
122+ const pathActions : ScanAction [ ] = windowsAppPaths (
123+ "Microsoft VS Code" ,
124+ "code.exe" ,
125+ ) . map ( ( path ) => ( {
126+ action : "path" ,
127+ arg : path ,
128+ } ) ) ;
121129 editorInfo . actions . push ( ...pathActions ) ;
122130 } else if ( isMac ) {
123131 editorInfo . actions . push ( {
124132 action : "which" ,
125133 arg : "code" ,
126134 } ) ;
127135
128- const pathActions = macosAppPaths (
136+ const pathActions : ScanAction [ ] = macosAppPaths (
129137 "Visual Studio Code.app/Contents/Resources/app/bin/code" ,
130- ) . map ( ( path ) => {
131- return {
132- action : "path" ,
133- arg : path ,
134- } as ScanAction ;
135- } ) ;
138+ ) . map ( ( path ) => ( {
139+ action : "path" ,
140+ arg : path ,
141+ } ) ) ;
136142 editorInfo . actions . push ( ...pathActions ) ;
137143 } else {
138144 editorInfo . actions . push ( {
@@ -174,13 +180,14 @@ function positronEditorInfo(): EditorInfo {
174180 action : "which" ,
175181 arg : "Positron.exe" ,
176182 } ) ;
177- const pathActions = windowsAppPaths ( "Positron" , "Positron.exe" ) . map (
178- ( path ) => {
179- return {
180- action : "path" ,
181- arg : path ,
182- } as ScanAction ;
183- } ,
183+ const pathActions : ScanAction [ ] = windowsAppPaths (
184+ "Positron" ,
185+ "Positron.exe" ,
186+ ) . map (
187+ ( path ) => ( {
188+ action : "path" ,
189+ arg : path ,
190+ } ) ,
184191 ) ;
185192 editorInfo . actions . push ( ...pathActions ) ;
186193 } else if ( isMac ) {
@@ -189,13 +196,13 @@ function positronEditorInfo(): EditorInfo {
189196 arg : "positron" ,
190197 } ) ;
191198
192- const pathActions = macosAppPaths (
199+ const pathActions : ScanAction [ ] = macosAppPaths (
193200 "Positron.app/Contents/Resources/app/bin/code" ,
194201 ) . map ( ( path ) => {
195202 return {
196203 action : "path" ,
197204 arg : path ,
198- } as ScanAction ;
205+ } ;
199206 } ) ;
200207 editorInfo . actions . push ( ...pathActions ) ;
201208 } else {
@@ -249,22 +256,19 @@ function rstudioEditorInfo(): EditorInfo {
249256 } ,
250257 } ) ;
251258
252- const paths = windowsAppPaths ( join ( "RStudio" , "bin" ) , rstudioExe ) . map (
253- ( path ) => {
254- return {
255- action : "path" ,
256- arg : path ,
257- } as ScanAction ;
258- } ,
259- ) ;
259+ const paths : ScanAction [ ] = windowsAppPaths (
260+ join ( "RStudio" , "bin" ) ,
261+ rstudioExe ,
262+ ) . map ( ( path ) => ( {
263+ action : "path" ,
264+ arg : path ,
265+ } ) ) ;
260266 editorInfo . actions . push ( ...paths ) ;
261267 } else if ( isMac ) {
262- const paths = macosAppPaths ( "RStudio.app" ) . map ( ( path ) => {
263- return {
264- action : "path" ,
265- arg : path ,
266- } as ScanAction ;
267- } ) ;
268+ const paths : ScanAction [ ] = macosAppPaths ( "RStudio.app" ) . map ( ( path ) => ( {
269+ action : "path" ,
270+ arg : path ,
271+ } ) ) ;
268272 editorInfo . actions . push ( ...paths ) ;
269273 } else {
270274 editorInfo . actions . push ( {
0 commit comments