()
| 94 | * @returns Map of plugin ID to the user-editable scope that owns it |
| 95 | */ |
| 96 | export function getPluginEditableScopes(): Map<string, ExtendedPluginScope> { |
| 97 | const result = new Map<string, ExtendedPluginScope>() |
| 98 | |
| 99 | // Process --add-dir directories FIRST (lowest priority, overridden by all standard sources) |
| 100 | const addDirPlugins = getAddDirEnabledPlugins() |
| 101 | for (const [pluginId, value] of Object.entries(addDirPlugins)) { |
| 102 | if (!pluginId.includes('@')) { |
| 103 | continue |
| 104 | } |
| 105 | if (value === true) { |
| 106 | result.set(pluginId, 'flag') // 'flag' scope = session-only, no write-back |
| 107 | } else if (value === false) { |
| 108 | result.delete(pluginId) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Process standard sources in precedence order (later overrides earlier) |
| 113 | const scopeSources: Array<{ |
| 114 | scope: ExtendedPluginScope |
| 115 | source: SettingSource |
| 116 | }> = [ |
| 117 | { scope: 'managed', source: 'policySettings' }, |
| 118 | { scope: 'user', source: 'userSettings' }, |
| 119 | { scope: 'project', source: 'projectSettings' }, |
| 120 | { scope: 'local', source: 'localSettings' }, |
| 121 | { scope: 'flag', source: 'flagSettings' }, |
| 122 | ] |
| 123 | |
| 124 | for (const { scope, source } of scopeSources) { |
| 125 | const settings = getSettingsForSource(source) |
| 126 | if (!settings?.enabledPlugins) { |
| 127 | continue |
| 128 | } |
| 129 | |
| 130 | for (const [pluginId, value] of Object.entries(settings.enabledPlugins)) { |
| 131 | // Skip invalid format |
| 132 | if (!pluginId.includes('@')) { |
| 133 | continue |
| 134 | } |
| 135 | |
| 136 | // Log when a standard source overrides an --add-dir plugin |
| 137 | if (pluginId in addDirPlugins && addDirPlugins[pluginId] !== value) { |
| 138 | logForDebugging( |
| 139 | `Plugin ${pluginId} from --add-dir (${addDirPlugins[pluginId]}) overridden by ${source} (${value})`, |
| 140 | ) |
| 141 | } |
| 142 | |
| 143 | if (value === true) { |
| 144 | // Plugin enabled at this scope |
| 145 | result.set(pluginId, scope) |
| 146 | } else if (value === false) { |
| 147 | // Explicitly disabled - remove from result |
| 148 | result.delete(pluginId) |
| 149 | } |
| 150 | // Note: Other values (like version strings for future P2) are ignored for now |
| 151 | } |
| 152 | } |
| 153 |
no test coverage detected