
import { localize } from '../../../../../nls.js';
import { Extensions } from '../../../../../platform/configuration/common/configurationRegistry.js';
import { Registry } from '../../../../../platform/registry/common/platform.js';
import { TerminalSettingId } from '../../../../../platform/terminal/common/terminal.js';

var TerminalSuggestSettingId;
(function(TerminalSuggestSettingId) {
    TerminalSuggestSettingId["Enabled"] = "terminal.integrated.suggest.enabled";
    TerminalSuggestSettingId["QuickSuggestions"] = "terminal.integrated.suggest.quickSuggestions";
    TerminalSuggestSettingId["SuggestOnTriggerCharacters"] = "terminal.integrated.suggest.suggestOnTriggerCharacters";
    TerminalSuggestSettingId["RunOnEnter"] = "terminal.integrated.suggest.runOnEnter";
    TerminalSuggestSettingId["WindowsExecutableExtensions"] = "terminal.integrated.suggest.windowsExecutableExtensions";
    TerminalSuggestSettingId["Providers"] = "terminal.integrated.suggest.providers";
    TerminalSuggestSettingId["ShowStatusBar"] = "terminal.integrated.suggest.showStatusBar";
    TerminalSuggestSettingId["CdPath"] = "terminal.integrated.suggest.cdPath";
    TerminalSuggestSettingId["InlineSuggestion"] = "terminal.integrated.suggest.inlineSuggestion";
    TerminalSuggestSettingId["UpArrowNavigatesHistory"] = "terminal.integrated.suggest.upArrowNavigatesHistory";
    TerminalSuggestSettingId["SelectionMode"] = "terminal.integrated.suggest.selectionMode";
    TerminalSuggestSettingId["InsertTrailingSpace"] = "terminal.integrated.suggest.insertTrailingSpace";
})(TerminalSuggestSettingId || (TerminalSuggestSettingId = {}));
const windowsDefaultExecutableExtensions = [
"exe",
"bat",
"cmd",
"com",
"msi",
"ps1",
"vbs",
"js",
"jar",
"py",
"rb",
"pl",
"sh"];
const terminalSuggestConfigSection = "terminal.integrated.suggest";
function normalizeQuickSuggestionsConfig(config) {
    if (typeof config === "boolean") {
        return config ? {
            commands: "on",
            arguments: "on",
            unknown: "off"
        } : {
            commands: "off",
            arguments: "off",
            unknown: "off"
        };
    }
    return config;
}
const terminalSuggestConfiguration = {
    [TerminalSuggestSettingId.Enabled]: {
        restricted: true,
        markdownDescription: ( localize(
            15106,
            "Enables terminal IntelliSense suggestions (also known as autocomplete) for supported shells ({0}). This requires {1} to be enabled and working or [manually installed](https://code.visualstudio.com/docs/terminal/shell-integration#_manual-installation-install).",
            "Windows PowerShell, PowerShell v7+, zsh, bash, fish",
            `\`#${TerminalSettingId.ShellIntegrationEnabled}#\``
        )),
        type: "boolean",
        default: true
    },
    [TerminalSuggestSettingId.Providers]: {
        restricted: true,
        markdownDescription: ( localize(
            15107,
            "Providers are enabled by default. Omit them by setting the id of the provider to `false`."
        )),
        type: "object",
        properties: {}
    },
    [TerminalSuggestSettingId.QuickSuggestions]: {
        restricted: true,
        markdownDescription: ( localize(
            15108,
            "Controls whether suggestions should automatically show up while typing. Also be aware of the {0}-setting which controls if suggestions are triggered by special characters.",
            `\`#${TerminalSuggestSettingId.SuggestOnTriggerCharacters}#\``
        )),
        type: "object",
        properties: {
            commands: {
                description: ( localize(
                    15109,
                    "Enable quick suggestions for commands, the first word in a command line input."
                )),
                type: "string",
                enum: ["on", "off"]
            },
            arguments: {
                description: ( localize(
                    15110,
                    "Enable quick suggestions for arguments, anything after the first word in a command line input."
                )),
                type: "string",
                enum: ["on", "off"]
            },
            unknown: {
                description: ( localize(
                    15111,
                    "Enable quick suggestions when it's unclear what the best suggestion is, if this is on files and folders will be suggested as a fallback."
                )),
                type: "string",
                enum: ["on", "off"]
            }
        },
        additionalProperties: false,
        default: {
            commands: "off",
            arguments: "off",
            unknown: "off"
        }
    },
    [TerminalSuggestSettingId.SuggestOnTriggerCharacters]: {
        restricted: true,
        markdownDescription: ( localize(
            15112,
            "Controls whether suggestions should automatically show up when typing trigger characters."
        )),
        type: "boolean",
        default: false
    },
    [TerminalSuggestSettingId.RunOnEnter]: {
        restricted: true,
        markdownDescription: ( localize(
            15113,
            "Controls whether suggestions should run immediately when `Enter` (not `Tab`) is used to accept the result."
        )),
        enum: ["never", "exactMatch", "exactMatchIgnoreExtension", "always"],
        markdownEnumDescriptions: [( localize(15114, "Never run on `Enter`.")), ( localize(15115, "Run on `Enter` when the suggestion is typed in its entirety.")), ( localize(
            15116,
            "Run on `Enter` when the suggestion is typed in its entirety or when a file is typed without its extension included."
        )), ( localize(15117, "Always run on `Enter`."))],
        default: "never"
    },
    [TerminalSuggestSettingId.SelectionMode]: {
        markdownDescription: ( localize(
            15118,
            "Controls how suggestion selection works in the integrated terminal."
        )),
        type: "string",
        enum: ["partial", "always", "never"],
        markdownEnumDescriptions: [( localize(
            15119,
            "Partially select a suggestion when automatically triggering IntelliSense. `Tab` can be used to accept the first suggestion, only after navigating the suggestions via `Down` will `Enter` also accept the active suggestion."
        )), ( localize(
            15120,
            "Always select a suggestion when automatically triggering IntelliSense. `Enter` or `Tab` can be used to accept the first suggestion."
        )), ( localize(
            15121,
            "Never select a suggestion when automatically triggering IntelliSense. The list must be navigated via `Down` before `Enter` or `Tab` can be used to accept the active suggestion."
        ))],
        default: "partial"
    },
    [TerminalSuggestSettingId.WindowsExecutableExtensions]: {
        restricted: true,
        markdownDescription: ( localize(
            15122,
            "A set of windows command executable extensions that will be included as suggestions in the terminal.\n\nMany executables are included by default, listed below:\n\n{0}.\n\nTo exclude an extension, set it to `false`\n\n. To include one not in the list, add it and set it to `true`.",
            ( windowsDefaultExecutableExtensions.sort().map(extension => `- ${extension}`)).join("\n")
        )),
        type: "object",
        default: {}
    },
    [TerminalSuggestSettingId.ShowStatusBar]: {
        restricted: true,
        markdownDescription: ( localize(
            15123,
            "Controls whether the terminal suggestions status bar should be shown."
        )),
        type: "boolean",
        default: true
    },
    [TerminalSuggestSettingId.CdPath]: {
        restricted: true,
        markdownDescription: ( localize(
            15124,
            "Controls whether to enable $CDPATH support which exposes children of the folders in the $CDPATH variable regardless of the current working directory. $CDPATH is expected to be semi colon-separated on Windows and colon-separated on other platforms."
        )),
        type: "string",
        enum: ["off", "relative", "absolute"],
        markdownEnumDescriptions: [( localize(15125, "Disable the feature.")), ( localize(15126, "Enable the feature and use relative paths.")), ( localize(
            15127,
            "Enable the feature and use absolute paths. This is useful when the shell doesn't natively support `$CDPATH`."
        ))],
        default: "absolute"
    },
    [TerminalSuggestSettingId.InlineSuggestion]: {
        restricted: true,
        markdownDescription: ( localize(
            15128,
            "Controls whether the shell's inline suggestion should be detected and how it is scored."
        )),
        type: "string",
        enum: ["off", "alwaysOnTopExceptExactMatch", "alwaysOnTop"],
        markdownEnumDescriptions: [( localize(15129, "Disable the feature.")), ( localize(
            15130,
            "Enable the feature and sort the inline suggestion without forcing it to be on top. This means that exact matches will be above the inline suggestion."
        )), ( localize(15131, "Enable the feature and always put the inline suggestion on top."))],
        default: "alwaysOnTop"
    },
    [TerminalSuggestSettingId.UpArrowNavigatesHistory]: {
        restricted: true,
        markdownDescription: ( localize(
            15132,
            "Determines whether the up arrow key navigates the command history when focus is on the first suggestion and navigation has not yet occurred. When set to false, the up arrow will move focus to the last suggestion instead."
        )),
        type: "boolean",
        default: true
    },
    [TerminalSuggestSettingId.InsertTrailingSpace]: {
        restricted: true,
        markdownDescription: ( localize(
            15133,
            "Controls whether a space is automatically inserted after accepting a suggestion and re-trigger suggestions. Folders and symbolic link folders will never have a trailing space added."
        )),
        type: "boolean",
        default: false
    }
};
let terminalSuggestProvidersConfiguration;
function registerTerminalSuggestProvidersConfiguration(providers) {
    const oldProvidersConfiguration = terminalSuggestProvidersConfiguration;
    providers ??= ( new Map());
    if (!( providers.has("lsp"))) {
        providers.set("lsp", {
            id: "lsp",
            description: ( localize(15134, "Show suggestions from language servers."))
        });
    }
    const providersProperties = {};
    for (const id of Array.from(( providers.keys())).sort()) {
        providersProperties[id] = {
            type: "boolean",
            default: id === "lsp" ? false : true,
            description: providers.get(id)?.description ?? ( localize(15135, "Show suggestions from {0}.", id))
        };
    }
    const defaultValue = {};
    for (const key in providersProperties) {
        defaultValue[key] = providersProperties[key].default;
    }
    terminalSuggestProvidersConfiguration = {
        id: "terminalSuggestProviders",
        order: 100,
        title: ( localize(15136, "Terminal Suggest Providers")),
        type: "object",
        properties: {
            [TerminalSuggestSettingId.Providers]: {
                restricted: true,
                markdownDescription: ( localize(
                    15137,
                    "Controls which suggestions automatically show up while typing. Suggestion providers are enabled by default."
                )),
                type: "object",
                properties: providersProperties,
                default: defaultValue,
                tags: ["preview"],
                additionalProperties: false
            }
        }
    };
    const registry = ( Registry.as(Extensions.Configuration));
    registry.updateConfigurations({
        add: [terminalSuggestProvidersConfiguration],
        remove: oldProvidersConfiguration ? [oldProvidersConfiguration] : []
    });
}
registerTerminalSuggestProvidersConfiguration();

export { TerminalSuggestSettingId, normalizeQuickSuggestionsConfig, registerTerminalSuggestProvidersConfiguration, terminalSuggestConfigSection, terminalSuggestConfiguration, windowsDefaultExecutableExtensions };
