Nate ButlerAdd WIP settings-tableff027f12 years agoHistory
1448 lines · 43.8 KB · JavaScript
RawDownload
// - status/channel - None (stable) | Preview | Nightly | Experiemental | Unstable// - namespace?/key?// - name// - type (boolean, string, ...)// - default_value// - values[] | "See {name} for more &rarr;"// - short_description// - long_description? / examples? -> these ones get pulled out into sections // Every row should have a #permalink// Create a table from an array of settings const settings = [  {    status: "Preview",    key: "ui",    name: "font_weight",    type: "string",    default_value: 400,    values: [100, 200, 300, 400, 500, 600, 700, 800, 900],    short_description: "The weight of the ui font",    description: "The weight of the ui font",  },  {    status: "Nightly",    key: "ui",    name: "font_weight",    type: "number",    default_value: 400,    values: [100, 200, 300, 400, 500, 600, 700, 800, 900],    short_description: "The weight of the ui font",    description: "The weight of the ui font",  },]; const render_tag = (text, variant = "default") => {  let classes = "tag";   if (variant !== "default") {    switch (variant) {      case "info":        classes += "tag-info;";        break;      case "warning":        classes += "tag-warning;";        break;      case "error":        classes += "tag-error";        break;      default:        classes;    }  }   return `<span class="${classes}">${text}</span>`;}; function parseSettingsSchema(schema) {  const settings = [];   function processProperty(key, value, parentKey = "") {    const fullKey = parentKey ? `${parentKey}.${key}` : key;     if (value.type === "object" && value.properties) {      Object.entries(value.properties).forEach(([subKey, subValue]) => {        processProperty(subKey, subValue, fullKey);      });    } else {      settings.push({        key: fullKey,        name: key,        type: Array.isArray(value.type) ? value.type.join(" | ") : value.type,        default_value: value.default,        values: value.enum,        short_description: value.description,      });    }  }   Object.entries(schema.properties).forEach(([key, value]) => {    processProperty(key, value);  });   return settings;} function createSettingsTable(settings) {  const container = document.createElement("div");  container.className = "settings-list";   // Group settings by their top-level key  const groupedSettings = settings.reduce((acc, setting) => {    const [topLevelKey, ...rest] = setting.key.split(".");    if (!acc[topLevelKey]) {      acc[topLevelKey] = [];    }    acc[topLevelKey].push({ ...setting, subKey: rest.join(".") });    return acc;  }, {});   Object.entries(groupedSettings).forEach(([topLevelKey, groupSettings]) => {    let section;    if (groupSettings.length > 1) {      section = document.createElement("section");      section.id = `settings-${topLevelKey}`;       const title = document.createElement("h3");      title.textContent = topLevelKey;      section.appendChild(title);    }     groupSettings.forEach((setting) => {      const settingContainer = document.createElement("div");      settingContainer.className = "setting-container";      settingContainer.id = `setting-${setting.key}`;       // Line 1: name type [default]      const line1 = document.createElement("div");      line1.className = "setting-line";      line1.innerHTML = `<span class="setting-name">${setting.subKey || setting.name}</span>`;      if (setting.type !== null && setting.type !== undefined) {        line1.innerHTML += ` <span class="setting-type">${setting.type}</span>`;      }      settingContainer.appendChild(line1);       // Line 2: values (if present)      if (setting.values && setting.values.length > 0) {        const line2 = document.createElement("div");        line2.className = "setting-line setting-values";        line2.textContent = `Values: ${setting.values.join(", ")}`;        settingContainer.appendChild(line2);      }       // Line 3: description (if present)      if (setting.short_description) {        const line3 = document.createElement("div");        line3.className = "setting-line setting-description";        line3.textContent = setting.short_description;        settingContainer.appendChild(line3);      }       // Line 4: default value      if (setting.default_value !== undefined) {        const line4 = document.createElement("div");        line4.className = "setting-line setting-default";        line4.textContent = `Default value: ${setting.default_value}`;        settingContainer.appendChild(line4);      }       if (section) {        section.appendChild(settingContainer);      } else {        container.appendChild(settingContainer);      }    });     if (section) {      container.appendChild(section);    }  });   return container;} // Usagedocument.addEventListener("DOMContentLoaded", () => {  const settingsContainer = document.getElementById("settings-container");  if (settingsContainer) {    const parsedSettings = parseSettingsSchema(schema);    const settingsList = createSettingsTable(parsedSettings);    settingsContainer.appendChild(settingsList);  }}); const schema = {  type: "object",  properties: {    active_pane_magnification: {      description:        "Scale by which to zoom the active pane. When set to 1.0, the active pane has the same size as others, but when set to a larger value, the active pane takes up more space.\n\nDefault: `1.0`",      type: "number",      format: "float",    },    always_treat_brackets_as_autoclosed: {      description: "Default: false",      type: "boolean",    },    assistant: {      oneOf: [        {          type: "object",          required: ["version"],          properties: {            button: {              description:                "Whether to show the assistant panel button in the status bar.\n\nDefault: true",              type: "boolean",            },            default_height: {              description:                "Default height in pixels when the assistant is docked to the bottom.\n\nDefault: 320",              type: "number",              format: "float",            },            default_width: {              description:                "Default width in pixels when the assistant is docked to the left or right.\n\nDefault: 640",              type: "number",              format: "float",            },            dock: {              description: "Where to dock the assistant.\n\nDefault: right",              allOf: [                {                  $ref: "#/definitions/AssistantDockPosition",                },              ],            },            enabled: {              description: "Whether the Assistant is enabled.\n\nDefault: true",              type: "boolean",            },            provider: {              description:                'The provider of the assistant service.\n\nThis can be "openai", "anthropic", "ollama", "zed.dev" each with their respective default models and configurations.',              allOf: [                {                  $ref: "#/definitions/AssistantProviderContentV1",                },              ],            },            version: {              type: "string",              enum: ["1"],            },          },        },        {          type: "object",          required: ["version"],          properties: {            button: {              description:                "Whether to show the assistant panel button in the status bar.\n\nDefault: true",              type: "boolean",            },            default_height: {              description:                "Default height in pixels when the assistant is docked to the bottom.\n\nDefault: 320",              type: "number",              format: "float",            },            default_model: {              description:                "The default model to use when creating new contexts.",              allOf: [                {                  $ref: "#/definitions/LanguageModelSelection",                },              ],            },            default_width: {              description:                "Default width in pixels when the assistant is docked to the left or right.\n\nDefault: 640",              type: "number",              format: "float",            },            dock: {              description: "Where to dock the assistant.\n\nDefault: right",              allOf: [                {                  $ref: "#/definitions/AssistantDockPosition",                },              ],            },            enabled: {              description: "Whether the Assistant is enabled.\n\nDefault: true",              type: "boolean",            },            version: {              type: "string",              enum: ["2"],            },          },        },      ],    },    auto_install_extensions: {      description:        "The extensions that should be automatically installed by Zed.\n\nThis is used to make functionality provided by extensions (e.g., language support) available out-of-the-box.",      default: {},      type: "object",      additionalProperties: {        type: "boolean",      },    },    auto_signature_help: {      description:        "Whether to automatically show a signature help pop-up or not.\n\nDefault: false",      type: "boolean",    },    auto_update: {      type: "boolean",    },    auto_update_extensions: {      default: {},      type: "object",      additionalProperties: {        type: "boolean",      },    },    autosave: {      description: "When to automatically save edited buffers.\n\nDefault: off",      allOf: [        {          $ref: "#/definitions/AutosaveSetting",        },      ],    },    base_keymap: {      allOf: [        {          $ref: "#/definitions/BaseKeymap",        },      ],    },    buffer_font_fallbacks: {      description: "The font fallbacks to use for rendering in text buffers.",      default: null,      type: "array",      items: {        type: "string",      },      $ref: "#/definitions/FontFallbacks",    },    buffer_font_family: {      description: "The name of a font to use for rendering in text buffers.",      default: null,      type: "string",      $ref: "#/definitions/FontFamilies",    },    buffer_font_features: {      description:        "The OpenType features to enable for rendering in text buffers.",      default: null,      allOf: [        {          $ref: "#/definitions/FontFeatures",        },      ],    },    buffer_font_size: {      description: "The default font size for rendering in text buffers.",      default: null,      type: "number",      format: "float",    },    buffer_font_weight: {      description:        "The weight of the editor font in CSS units from 100 to 900.",      default: null,      type: "number",      format: "float",    },    buffer_line_height: {      description: "The buffer's line height.",      default: null,      allOf: [        {          $ref: "#/definitions/BufferLineHeight",        },      ],    },    calls: {      type: "object",      properties: {        mute_on_join: {          description:            "Whether the microphone should be muted when joining a channel or a call.\n\nDefault: false",          type: "boolean",        },        share_on_join: {          description:            "Whether your current project should be shared when joining an empty channel.\n\nDefault: true",          type: "boolean",        },      },    },    centered_layout: {      $ref: "#/definitions/CenteredLayoutSettings",    },    chat_panel: {      type: "object",      properties: {        button: {          description:            "Whether to show the panel button in the status bar.\n\nDefault: true",          type: "boolean",        },        default_width: {          description: "Default width of the panel in pixels.\n\nDefault: 240",          type: "number",          format: "float",        },        dock: {          description: "Where to dock the panel.\n\nDefault: left",          allOf: [            {              $ref: "#/definitions/DockPosition",            },          ],        },      },    },    code_actions_on_format: {      description:        'Which code actions to run on save after the formatter. These are not run if formatting is off.\n\nDefault: {} (or {"source.organizeImports": true} for Go).',      type: "object",      additionalProperties: {        type: "boolean",      },    },    collaboration_panel: {      type: "object",      properties: {        button: {          description:            "Whether to show the panel button in the status bar.\n\nDefault: true",          type: "boolean",        },        default_width: {          description: "Default width of the panel in pixels.\n\nDefault: 240",          type: "number",          format: "float",        },        dock: {          description: "Where to dock the panel.\n\nDefault: left",          allOf: [            {              $ref: "#/definitions/DockPosition",            },          ],        },      },    },    command_aliases: {      description:        "Aliases for the command palette. When you type a key in this map, it will be assumed to equal the value.\n\nDefault: true",      type: "object",      additionalProperties: {        type: "string",      },    },    completion_documentation_secondary_query_debounce: {      description:        "The debounce delay before re-querying the language server for completion documentation when not included in original completion list.\n\nDefault: 300 ms",      type: "integer",      format: "uint64",      minimum: 0.0,    },    confirm_quit: {      description:        "Whether or not to prompt the user to confirm before closing the application.\n\nDefault: false",      type: "boolean",    },    current_line_highlight: {      description:        "How to highlight the current line in the editor.\n\nDefault: all",      allOf: [        {          $ref: "#/definitions/CurrentLineHighlight",        },      ],    },    cursor_blink: {      description: "Whether the cursor blinks in the editor.\n\nDefault: true",      type: "boolean",    },    diagnostics: {      type: "object",      properties: {        include_warnings: {          description:            "Whether to show warnings or not by default.\n\nDefault: true",          type: "boolean",        },      },    },    double_click_in_multibuffer: {      description:        "What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).\n\nDefault: select",      allOf: [        {          $ref: "#/definitions/DoubleClickInMultibuffer",        },      ],    },    drop_target_size: {      description:        "The size of the workspace split drop targets on the outer edges. Given as a fraction that will be multiplied by the smaller dimension of the workspace.\n\nDefault: `0.2` (20% of the smaller dimension of the workspace)",

Lines 1–500 of 1448.