diff --git a/CHANGELOG.md b/CHANGELOG.md index 04f3d4ba..7590b031 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - [#127](https://github.com/estruyf/vscode-front-matter/issues/127): Title bar action added to open the dashboard - [#128](https://github.com/estruyf/vscode-front-matter/issues/128): Support for multi-select on image fields added - [#131](https://github.com/estruyf/vscode-front-matter/issues/131): Folder creation support added on media dashboard +- [#134](https://github.com/estruyf/vscode-front-matter/issues/134): On startup, the extension checks if local settings can be promoted ### 🐞 Fixes diff --git a/src/constants/ExtensionState.ts b/src/constants/ExtensionState.ts index 8efd291e..9ec19108 100644 --- a/src/constants/ExtensionState.ts +++ b/src/constants/ExtensionState.ts @@ -2,5 +2,6 @@ export const ExtensionState = { PagesView: `frontMatter:Pages:ViewType`, SelectedFolder: `frontMatter:SelectedFolder`, - Version: `frontMatter:Version` + Version: `frontMatter:Version`, + SettingPromoted: `frontMatter:Settings:Promoted` }; \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index 93e7a99c..3d9e416b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -34,6 +34,8 @@ export async function activate(context: vscode.ExtensionContext) { SettingsHelper.init(); extension.migrateSettings(); + + SettingsHelper.checkToPromote(); collection = vscode.languages.createDiagnosticCollection('frontMatter'); diff --git a/src/helpers/SettingsHelper.ts b/src/helpers/SettingsHelper.ts index 52e9cb1a..36ff27d0 100644 --- a/src/helpers/SettingsHelper.ts +++ b/src/helpers/SettingsHelper.ts @@ -1,8 +1,8 @@ import { Notifications } from './Notifications'; -import { commands, Uri, workspace } from 'vscode'; +import { commands, Uri, workspace, window } from 'vscode'; import * as vscode from 'vscode'; -import { TaxonomyType } from '../models'; -import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY, CONTEXT, SETTINGS_CONTENT_STATIC_FOLDER } from '../constants'; +import { ContentType, TaxonomyType } from '../models'; +import { SETTING_TAXONOMY_TAGS, SETTING_TAXONOMY_CATEGORIES, CONFIG_KEY, CONTEXT, SETTINGS_CONTENT_STATIC_FOLDER, ExtensionState } from '../constants'; import { Folders } from '../commands/Folders'; import { join, basename } from 'path'; import { existsSync, readFileSync, watch, writeFileSync } from 'fs'; @@ -34,6 +34,26 @@ export class Settings { }); } + /** + * Check if the setting is present in the workspace and ask to promote them to the global settings + */ + public static async checkToPromote() { + const isPromoted = await Extension.getInstance().getState(ExtensionState.SettingPromoted); + if (!isPromoted) { + if (Settings.hasSettings()) { + window.showInformationMessage(`You have local settings. Would you like to promote them to the global settings ("frontmatter.json")?`, 'Yes', 'No').then(async (result) => { + if (result === "Yes") { + Settings.promote(); + } + + if (result === "No" || result === "Yes") { + Extension.getInstance().setState(ExtensionState.SettingPromoted, true); + } + }); + } + } + } + /** * Check for config changes on global and local settings * @param callback @@ -116,6 +136,12 @@ export class Settings { Settings.globalConfig = JSON.parse(localConfig); Settings.globalConfig[`${CONFIG_KEY}.${name}`] = value; writeFileSync(fmConfig, JSON.stringify(Settings.globalConfig, null, 2), 'utf8'); + + const workspaceSettingValue = Settings.hasWorkspaceSettings(name); + if (workspaceSettingValue) { + await Settings.update(name, undefined); + } + return; } } else { @@ -199,6 +225,16 @@ export class Settings { Notifications.info(`All settings promoted to team level.`); } + /** + * Check if the setting is present in the workspace + * @param name + * @returns + */ + public static hasWorkspaceSettings(name: string): T | undefined { + const setting = Settings.config.inspect(name); + return (setting && typeof setting.workspaceValue !== "undefined") ? setting.workspaceValue : undefined; + } + /** * Check if there are any Front Matter settings in the workspace * @returns