
import { isNative, isWeb } from '../../../../base/common/platform.js';
import { editorConfigurationBaseNode } from '../../../../editor/common/config/editorConfigurationSchema.js';
import { localize } from '../../../../nls.js';
import { Extensions, ConfigurationScope } from '../../../../platform/configuration/common/configurationRegistry.js';
import { HotExitConfiguration, FILES_READONLY_FROM_PERMISSIONS_CONFIG, FILES_READONLY_EXCLUDE_CONFIG, FILES_READONLY_INCLUDE_CONFIG, AutoSaveConfiguration, FILES_ASSOCIATIONS_CONFIG, FILES_EXCLUDE_CONFIG } from '../../../../platform/files/common/files.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { GUESSABLE_ENCODINGS, SUPPORTED_ENCODINGS } from '../../../services/textfile/common/encoding.js';

const configurationRegistry = ( Registry.as(Extensions.Configuration));
const hotExitConfiguration = isNative ? {
    "type": "string",
    "scope": ConfigurationScope.APPLICATION,
    "enum": [
        HotExitConfiguration.OFF,
        HotExitConfiguration.ON_EXIT,
        HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE
    ],
    "default": HotExitConfiguration.ON_EXIT,
    "markdownEnumDescriptions": [( localize(
        9662,
        "Disable hot exit. A prompt will show when attempting to close a window with editors that have unsaved changes."
    )), ( localize(
        9663,
        "Hot exit will be triggered when the last window is closed on Windows/Linux or when the `workbench.action.quit` command is triggered (command palette, keybinding, menu). All windows without folders opened will be restored upon next launch. A list of previously opened windows with unsaved files can be accessed via `File > Open Recent > More...`"
    )), ( localize(
        9664,
        "Hot exit will be triggered when the last window is closed on Windows/Linux or when the `workbench.action.quit` command is triggered (command palette, keybinding, menu), and also for any window with a folder opened regardless of whether it's the last window. All windows without folders opened will be restored upon next launch. A list of previously opened windows with unsaved files can be accessed via `File > Open Recent > More...`"
    ))],
    "markdownDescription": ( localize(
        9665,
        "[Hot Exit](https://aka.ms/vscode-hot-exit) controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.",
        HotExitConfiguration.ON_EXIT,
        HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE
    ))
} : {
    "type": "string",
    "scope": ConfigurationScope.APPLICATION,
    "enum": [HotExitConfiguration.OFF, HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE],
    "default": HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE,
    "markdownEnumDescriptions": [( localize(
        9662,
        "Disable hot exit. A prompt will show when attempting to close a window with editors that have unsaved changes."
    )), ( localize(
        9666,
        "Hot exit will be triggered when the browser quits or the window or tab is closed."
    ))],
    "markdownDescription": ( localize(
        9665,
        "[Hot Exit](https://aka.ms/vscode-hot-exit) controls whether unsaved files are remembered between sessions, allowing the save prompt when exiting the editor to be skipped.",
        HotExitConfiguration.ON_EXIT,
        HotExitConfiguration.ON_EXIT_AND_WINDOW_CLOSE
    ))
};
configurationRegistry.registerConfiguration({
    "id": "files",
    "order": 9,
    "title": ( localize(9667, "Files")),
    "type": "object",
    "properties": {
        [FILES_EXCLUDE_CONFIG]: {
            "type": "object",
            "markdownDescription": ( localize(
                9668,
                "Configure [glob patterns](https://aka.ms/vscode-glob-patterns) for excluding files and folders. For example, the File Explorer decides which files and folders to show or hide based on this setting. Refer to the `#search.exclude#` setting to define search-specific excludes. Refer to the `#explorer.excludeGitIgnore#` setting for ignoring files based on your `.gitignore`."
            )),
            "default": {
                ...{
                    "**/.git": true,
                    "**/.svn": true,
                    "**/.hg": true,
                    "**/.DS_Store": true,
                    "**/Thumbs.db": true
                },
                ...(isWeb ? {
                    "**/*.crswap": true
                } : undefined)
            },
            "scope": ConfigurationScope.RESOURCE,
            "additionalProperties": {
                "anyOf": [{
                    "type": "boolean",
                    "enum": [true, false],
                    "enumDescriptions": [( localize(9669, "Enable the pattern.")), ( localize(9670, "Disable the pattern."))],
                    "description": ( localize(
                        9671,
                        "The glob pattern to match file paths against. Set to true or false to enable or disable the pattern."
                    ))
                }, {
                    "type": "object",
                    "properties": {
                        "when": {
                            "type": "string",
                            "pattern": "\\w*\\$\\(basename\\)\\w*",
                            "default": "$(basename).ext",
                            "markdownDescription": ( localize(
                                9672,
                                "Additional check on the siblings of a matching file. Use \\$(basename) as variable for the matching file name."
                            ))
                        }
                    }
                }]
            }
        },
        [FILES_ASSOCIATIONS_CONFIG]: {
            "type": "object",
            "markdownDescription": ( localize(
                9673,
                "Configure [glob patterns](https://aka.ms/vscode-glob-patterns) of file associations to languages (for example `\"*.extension\": \"html\"`). Patterns will match on the absolute path of a file if they contain a path separator and will match on the name of the file otherwise. These have precedence over the default associations of the languages installed."
            )),
            "additionalProperties": {
                "type": "string"
            }
        },
        "files.encoding": {
            "type": "string",
            "enum": ( Object.keys(SUPPORTED_ENCODINGS)),
            "default": "utf8",
            "description": ( localize(
                9674,
                "The default character set encoding to use when reading and writing files. This setting can also be configured per language."
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE,
            "enumDescriptions": ( ( Object.keys(SUPPORTED_ENCODINGS)).map(key => SUPPORTED_ENCODINGS[key].labelLong)),
            "enumItemLabels": ( ( Object.keys(SUPPORTED_ENCODINGS)).map(key => SUPPORTED_ENCODINGS[key].labelLong))
        },
        "files.autoGuessEncoding": {
            "type": "boolean",
            "default": false,
            "markdownDescription": ( localize(
                9675,
                "When enabled, the editor will attempt to guess the character set encoding when opening files. This setting can also be configured per language. Note, this setting is not respected by text search. Only {0} is respected.",
                "`#files.encoding#`"
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.candidateGuessEncodings": {
            "type": "array",
            "items": {
                "type": "string",
                "enum": ( Object.keys(GUESSABLE_ENCODINGS)),
                "enumDescriptions": ( ( Object.keys(GUESSABLE_ENCODINGS)).map(key => GUESSABLE_ENCODINGS[key].labelLong))
            },
            "default": [],
            "markdownDescription": ( localize(
                9676,
                "List of character set encodings that the editor should attempt to guess in the order they are listed. In case it cannot be determined, {0} is respected",
                "`#files.encoding#`"
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.eol": {
            "type": "string",
            "enum": ["\n", "\r\n", "auto"],
            "enumDescriptions": [( localize(9677, "LF")), ( localize(9678, "CRLF")), ( localize(9679, "Uses operating system specific end of line character."))],
            "default": "auto",
            "description": ( localize(9680, "The default end of line character.")),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.enableTrash": {
            "type": "boolean",
            "default": true,
            "description": ( localize(
                9681,
                "Moves files/folders to the OS trash (recycle bin on Windows) when deleting. Disabling this will delete files/folders permanently."
            ))
        },
        "files.trimTrailingWhitespace": {
            "type": "boolean",
            "default": false,
            "description": ( localize(9682, "When enabled, will trim trailing whitespace when saving a file.")),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.trimTrailingWhitespaceInRegexAndStrings": {
            "type": "boolean",
            "default": true,
            "description": ( localize(
                9683,
                "When enabled, trailing whitespace will be removed from multiline strings and regexes on save or when executing 'editor.action.trimTrailingWhitespace'. This can cause whitespace to not be trimmed from lines when there isn't up-to-date token information."
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.insertFinalNewline": {
            "type": "boolean",
            "default": false,
            "description": ( localize(
                9684,
                "When enabled, insert a final new line at the end of the file when saving it."
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.trimFinalNewlines": {
            "type": "boolean",
            "default": false,
            "description": ( localize(
                9685,
                "When enabled, will trim all new lines after the final new line at the end of the file when saving it."
            )),
            scope: ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.autoSave": {
            "type": "string",
            "enum": [
                AutoSaveConfiguration.OFF,
                AutoSaveConfiguration.AFTER_DELAY,
                AutoSaveConfiguration.ON_FOCUS_CHANGE,
                AutoSaveConfiguration.ON_WINDOW_CHANGE
            ],
            "markdownEnumDescriptions": [( localize(9686, "An editor with changes is never automatically saved.")), ( localize(
                9687,
                "An editor with changes is automatically saved after the configured `#files.autoSaveDelay#`."
            )), ( localize(
                9688,
                "An editor with changes is automatically saved when the editor loses focus."
            )), ( localize(
                9689,
                "An editor with changes is automatically saved when the window loses focus."
            ))],
            "default": isWeb ? AutoSaveConfiguration.AFTER_DELAY : AutoSaveConfiguration.OFF,
            "markdownDescription": ( localize(
                9690,
                "Controls [auto save](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save) of editors that have unsaved changes.",
                AutoSaveConfiguration.OFF,
                AutoSaveConfiguration.AFTER_DELAY,
                AutoSaveConfiguration.ON_FOCUS_CHANGE,
                AutoSaveConfiguration.ON_WINDOW_CHANGE,
                AutoSaveConfiguration.AFTER_DELAY
            )),
            scope: ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.autoSaveDelay": {
            "type": "number",
            "default": 1000,
            "minimum": 0,
            "markdownDescription": ( localize(
                9691,
                "Controls the delay in milliseconds after which an editor with unsaved changes is saved automatically. Only applies when `#files.autoSave#` is set to `{0}`.",
                AutoSaveConfiguration.AFTER_DELAY
            )),
            scope: ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.autoSaveWorkspaceFilesOnly": {
            "type": "boolean",
            "default": false,
            "markdownDescription": ( localize(
                9692,
                "When enabled, will limit [auto save](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save) of editors to files that are inside the opened workspace. Only applies when {0} is enabled.",
                "`#files.autoSave#`"
            )),
            scope: ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.autoSaveWhenNoErrors": {
            "type": "boolean",
            "default": false,
            "markdownDescription": ( localize(
                9693,
                "When enabled, will limit [auto save](https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save) of editors to files that have no errors reported in them at the time the auto save is triggered. Only applies when {0} is enabled.",
                "`#files.autoSave#`"
            )),
            scope: ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.watcherExclude": {
            "type": "object",
            "patternProperties": {
                ".*": {
                    "type": "boolean"
                }
            },
            "default": {
                "**/.git/objects/**": true,
                "**/.git/subtree-cache/**": true,
                "**/.hg/store/**": true
            },
            "markdownDescription": ( localize(
                9694,
                "Configure paths or [glob patterns](https://aka.ms/vscode-glob-patterns) to exclude from file watching. Paths can either be relative to the watched folder or absolute. Glob patterns are matched relative from the watched folder. When you experience the file watcher process consuming a lot of CPU, make sure to exclude large folders that are of less interest (such as build output folders)."
            )),
            "scope": ConfigurationScope.RESOURCE
        },
        "files.watcherInclude": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "default": [],
            "description": ( localize(
                9695,
                "Configure extra paths to watch for changes inside the workspace. By default, all workspace folders will be watched recursively, except for folders that are symbolic links. You can explicitly add absolute or relative paths to support watching folders that are symbolic links. Relative paths will be resolved to an absolute path using the currently opened workspace."
            )),
            "scope": ConfigurationScope.RESOURCE
        },
        "files.hotExit": hotExitConfiguration,
        "files.defaultLanguage": {
            "type": "string",
            "markdownDescription": ( localize(
                9696,
                "The default language identifier that is assigned to new files. If configured to `${activeEditorLanguage}`, will use the language identifier of the currently active text editor if any."
            ))
        },
        [FILES_READONLY_INCLUDE_CONFIG]: {
            "type": "object",
            "patternProperties": {
                ".*": {
                    "type": "boolean"
                }
            },
            "default": {},
            "markdownDescription": ( localize(
                9697,
                "Configure paths or [glob patterns](https://aka.ms/vscode-glob-patterns) to mark as read-only. Glob patterns are always evaluated relative to the path of the workspace folder unless they are absolute paths. You can exclude matching paths via the `#files.readonlyExclude#` setting. Files from readonly file system providers will always be read-only independent of this setting."
            )),
            "scope": ConfigurationScope.RESOURCE
        },
        [FILES_READONLY_EXCLUDE_CONFIG]: {
            "type": "object",
            "patternProperties": {
                ".*": {
                    "type": "boolean"
                }
            },
            "default": {},
            "markdownDescription": ( localize(
                9698,
                "Configure paths or [glob patterns](https://aka.ms/vscode-glob-patterns) to exclude from being marked as read-only if they match as a result of the `#files.readonlyInclude#` setting. Glob patterns are always evaluated relative to the path of the workspace folder unless they are absolute paths. Files from readonly file system providers will always be read-only independent of this setting."
            )),
            "scope": ConfigurationScope.RESOURCE
        },
        [FILES_READONLY_FROM_PERMISSIONS_CONFIG]: {
            "type": "boolean",
            "markdownDescription": ( localize(
                9699,
                "Marks files as read-only when their file permissions indicate as such. This can be overridden via `#files.readonlyInclude#` and `#files.readonlyExclude#` settings."
            )),
            "default": false
        },
        "files.restoreUndoStack": {
            "type": "boolean",
            "description": ( localize(9700, "Restore the undo stack when a file is reopened.")),
            "default": true
        },
        "files.saveConflictResolution": {
            "type": "string",
            "enum": ["askUser", "overwriteFileOnDisk"],
            "enumDescriptions": [( localize(
                9701,
                "Will refuse to save and ask for resolving the save conflict manually."
            )), ( localize(
                9702,
                "Will resolve the save conflict by overwriting the file on disk with the changes in the editor."
            ))],
            "description": ( localize(
                9703,
                "A save conflict can occur when a file is saved to disk that was changed by another program in the meantime. To prevent data loss, the user is asked to compare the changes in the editor with the version on disk. This setting should only be changed if you frequently encounter save conflict errors and may result in data loss if used without caution."
            )),
            "default": "askUser",
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "files.dialog.defaultPath": {
            "type": "string",
            "pattern": "^((\\/|\\\\\\\\|[a-zA-Z]:\\\\).*)?$",
            "patternErrorMessage": ( localize(
                9704,
                "Default path for file dialogs must be an absolute path (e.g. C:\\\\myFolder or /myFolder)."
            )),
            "description": ( localize(
                9705,
                "Default path for file dialogs, overriding user's home path. Only used in the absence of a context-specific path, such as most recently opened file or folder."
            )),
            "scope": ConfigurationScope.MACHINE
        },
        "files.simpleDialog.enable": {
            "type": "boolean",
            "description": ( localize(
                9706,
                "Enables the simple file dialog for opening and saving files and folders. The simple file dialog replaces the system file dialog when enabled."
            )),
            "default": false
        },
        "files.participants.timeout": {
            type: "number",
            default: 60000,
            markdownDescription: ( localize(
                9707,
                "Timeout in milliseconds after which file participants for create, rename, and delete are cancelled. Use `0` to disable participants."
            ))
        }
    }
});
configurationRegistry.registerConfiguration({
    ...editorConfigurationBaseNode,
    properties: {
        "editor.formatOnSave": {
            "type": "boolean",
            "markdownDescription": ( localize(
                9708,
                "Format a file on save. A formatter must be available and the editor must not be shutting down. When {0} is set to `afterDelay`, the file will only be formatted when saved explicitly.",
                "`#files.autoSave#`"
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        },
        "editor.formatOnSaveMode": {
            "type": "string",
            "default": "file",
            "enum": ["file", "modifications", "modificationsIfAvailable"],
            "enumDescriptions": [( localize(9709, "Format the whole file.")), ( localize(
                9710,
                "Format modifications. Requires source control and a formatter that supports 'Format Selection'."
            )), ( localize(
                9711,
                "Will attempt to format modifications only (requires source control and a formatter that supports 'Format Selection'). If source control can't be used, then the whole file will be formatted."
            ))],
            "markdownDescription": ( localize(
                9712,
                "Controls if format on save formats the whole file or only modifications. Only applies when `#editor.formatOnSave#` is enabled."
            )),
            "scope": ConfigurationScope.LANGUAGE_OVERRIDABLE
        }
    }
});
