MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / autoImportSettings

Function autoImportSettings

src/utils/autoImportSettings.ts:16–76  ·  view source on GitHub ↗
(
	outputChannel: vscode.OutputChannel,
	{ providerSettingsManager, contextProxy, customModesManager }: ImportOptions,
)

Source from the content-addressed store, hash-verified

14 * their settings by placing a settings file at a predefined location.
15 */
16export async function autoImportSettings(
17 outputChannel: vscode.OutputChannel,
18 { providerSettingsManager, contextProxy, customModesManager }: ImportOptions,
19): Promise<void> {
20 try {
21 // Get the auto-import settings path from VSCode settings
22 const settingsPath = vscode.workspace.getConfiguration(Package.name).get<string>("autoImportSettingsPath")
23
24 if (!settingsPath || settingsPath.trim() === "") {
25 outputChannel.appendLine("[AutoImport] No auto-import settings path specified, skipping auto-import")
26 return
27 }
28
29 // Resolve the path (handle ~ for home directory and relative paths)
30 const resolvedPath = resolvePath(settingsPath.trim())
31 outputChannel.appendLine(`[AutoImport] Checking for settings file at: ${resolvedPath}`)
32
33 // Check if the file exists
34 if (!(await fileExistsAtPath(resolvedPath))) {
35 outputChannel.appendLine(`[AutoImport] Settings file not found at ${resolvedPath}, skipping auto-import`)
36 return
37 }
38
39 // Attempt to import the configuration
40 const result = await importSettingsFromPath(resolvedPath, {
41 providerSettingsManager,
42 contextProxy,
43 customModesManager,
44 })
45
46 if (result.success) {
47 outputChannel.appendLine(`[AutoImport] Successfully imported settings from ${resolvedPath}`)
48
49 if (result.warnings && result.warnings.length > 0) {
50 const count = result.warnings.length
51 outputChannel.appendLine(
52 `[AutoImport] Import completed with ${count} warning${count === 1 ? "" : "s"}.`,
53 )
54 for (const warning of result.warnings) {
55 outputChannel.appendLine(`[AutoImport] Warning: ${warning}`)
56 }
57 }
58
59 // Show a notification to the user
60 vscode.window.showInformationMessage(
61 t("common:info.auto_import_success", { filename: path.basename(resolvedPath) }),
62 )
63 } else {
64 outputChannel.appendLine(`[AutoImport] Failed to import settings: ${result.error}`)
65
66 // Show a warning but don't fail the extension activation
67 vscode.window.showWarningMessage(t("common:warnings.auto_import_failed", { error: result.error }))
68 }
69 } catch (error) {
70 const errorMessage = error instanceof Error ? error.message : String(error)
71 outputChannel.appendLine(`[AutoImport] Unexpected error during auto-import: ${errorMessage}`)
72
73 // Log error but don't fail extension activation

Callers 2

activateFunction · 0.90

Calls 11

fileExistsAtPathFunction · 0.90
importSettingsFromPathFunction · 0.90
tFunction · 0.90
resolvePathFunction · 0.85
appendLineMethod · 0.80
showWarningMessageMethod · 0.80
StringInterface · 0.70
getMethod · 0.65
getConfigurationMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected