@@ -14,7 +14,7 @@ import { ContextProxy } from "./ContextProxy"
1414import { CustomModesManager } from "./CustomModesManager"
1515import { t } from "../../i18n"
1616
17- type ImportOptions = {
17+ export type ImportOptions = {
1818 providerSettingsManager : ProviderSettingsManager
1919 contextProxy : ContextProxy
2020 customModesManager : CustomModesManager
@@ -24,7 +24,6 @@ type ExportOptions = {
2424 providerSettingsManager : ProviderSettingsManager
2525 contextProxy : ContextProxy
2626}
27-
2827type ImportWithProviderOptions = ImportOptions & {
2928 provider : {
3029 settingsImportedAt ?: number
@@ -33,33 +32,14 @@ type ImportWithProviderOptions = ImportOptions & {
3332}
3433
3534/**
36- * Import settings from a file using a file dialog
37- * @param options - Import options containing managers and proxy
38- * @returns Promise resolving to import result
35+ * Imports configuration from a specific file path
36+ * Shares base functionality for import settings for both the manual
37+ * and automatic settings importing
3938 */
40- export const importSettings = async ( { providerSettingsManager, contextProxy, customModesManager } : ImportOptions ) => {
41- const uris = await vscode . window . showOpenDialog ( {
42- filters : { JSON : [ "json" ] } ,
43- canSelectMany : false ,
44- } )
45-
46- if ( ! uris ) {
47- return { success : false , error : "User cancelled file selection" }
48- }
49-
50- return await importSettingsFromFile ( { providerSettingsManager, contextProxy, customModesManager } , uris [ 0 ] )
51- }
52-
53- /**
54- * Import settings from a specific file
55- * @param options - Import options containing managers and proxy
56- * @param fileUri - URI of the file to import from
57- * @returns Promise resolving to import result
58- */
59- export const importSettingsFromFile = async (
39+ export async function importSettingsFromPath (
40+ filePath : string ,
6041 { providerSettingsManager, contextProxy, customModesManager } : ImportOptions ,
61- fileUri : vscode . Uri ,
62- ) => {
42+ ) {
6343 const schema = z . object ( {
6444 providerProfiles : providerProfilesSchema ,
6545 globalSettings : globalSettingsSchema . optional ( ) ,
@@ -68,8 +48,9 @@ export const importSettingsFromFile = async (
6848 try {
6949 const previousProviderProfiles = await providerSettingsManager . export ( )
7050
71- const data = JSON . parse ( await fs . readFile ( fileUri . fsPath , "utf-8" ) )
72- const { providerProfiles : newProviderProfiles , globalSettings = { } } = schema . parse ( data )
51+ const { providerProfiles : newProviderProfiles , globalSettings = { } } = schema . parse (
52+ JSON . parse ( await fs . readFile ( filePath , "utf-8" ) ) ,
53+ )
7354
7455 const providerProfiles = {
7556 currentApiConfigName : newProviderProfiles . currentApiConfigName ,
@@ -119,6 +100,45 @@ export const importSettingsFromFile = async (
119100 }
120101}
121102
103+ /**
104+ * Import settings from a file using a file dialog
105+ * @param options - Import options containing managers and proxy
106+ * @returns Promise resolving to import result
107+ */
108+ export const importSettings = async ( { providerSettingsManager, contextProxy, customModesManager } : ImportOptions ) => {
109+ const uris = await vscode . window . showOpenDialog ( {
110+ filters : { JSON : [ "json" ] } ,
111+ canSelectMany : false ,
112+ } )
113+
114+ if ( ! uris ) {
115+ return { success : false , error : "User cancelled file selection" }
116+ }
117+
118+ return importSettingsFromPath ( uris [ 0 ] . fsPath , {
119+ providerSettingsManager,
120+ contextProxy,
121+ customModesManager,
122+ } )
123+ }
124+
125+ /**
126+ * Import settings from a specific file
127+ * @param options - Import options containing managers and proxy
128+ * @param fileUri - URI of the file to import from
129+ * @returns Promise resolving to import result
130+ */
131+ export const importSettingsFromFile = async (
132+ { providerSettingsManager, contextProxy, customModesManager } : ImportOptions ,
133+ fileUri : vscode . Uri ,
134+ ) => {
135+ return importSettingsFromPath ( fileUri . fsPath , {
136+ providerSettingsManager,
137+ contextProxy,
138+ customModesManager,
139+ } )
140+ }
141+
122142export const exportSettings = async ( { providerSettingsManager, contextProxy } : ExportOptions ) => {
123143 const uri = await vscode . window . showSaveDialog ( {
124144 filters : { JSON : [ "json" ] } ,
@@ -162,13 +182,13 @@ export const importSettingsWithFeedback = async (
162182 if ( filePath ) {
163183 // Validate file path and check if file exists
164184 try {
165- const fileUri = vscode . Uri . file ( filePath )
166185 // Check if file exists and is readable
167- await fs . access ( fileUri . fsPath , fs . constants . F_OK | fs . constants . R_OK )
168- result = await importSettingsFromFile (
169- { providerSettingsManager, contextProxy, customModesManager } ,
170- fileUri ,
171- )
186+ await fs . access ( filePath , fs . constants . F_OK | fs . constants . R_OK )
187+ result = await importSettingsFromPath ( filePath , {
188+ providerSettingsManager,
189+ contextProxy,
190+ customModesManager,
191+ } )
172192 } catch ( error ) {
173193 result = {
174194 success : false ,
0 commit comments