{
  config,
  lib,
  pkgs,
  ...
}: let
  palette-hex = pkgs.lib.nix-rice.palette.toRgbHex pkgs.rice.palette;
  palette-shex = pkgs.lib.nix-rice.palette.toRGBShortHex pkgs.rice.palette;
in {
  programs.helix = {
    enable = true;
    themes = with palette-hex; {
      nix-rice = {
        "attribute" = bright.cyan;
        "keyword" = {fg = normal.red;};
        "keyword.directive" = normal.red;
        "namespace" = bright.cyan;
        "punctuation" = bright.yellow;
        "punctuation.delimiter" = bright.yellow;
        "operator" = bright.magenta;
        "special" = normal.magenta;
        "variable.other.member" = bright.blue;
        "variable" = util.fg;
        "variable.builtin" = bright.yellow;
        "variable.parameter" = bright.white;
        "type" = normal.yellow;
        "type.builtin" = normal.yellow;
        "constructor" = {
          fg = bright.magenta;
          modifiers = ["bold"];
        };
        "function" = {
          fg = normal.green;
          modifiers = ["bold"];
        };
        "function.macro" = bright.cyan;
        "function.builtin" = normal.yellow;
        "tag" = normal.red;
        "comment" = {
          fg = normal.magenta;
          modifiers = ["italic"];
        };
        "constant" = {fg = bright.magenta;};
        "constant.builtin" = {
          fg = bright.magenta;
          modifiers = ["bold"];
        };
        "string" = normal.green;
        "constant.numeric" = bright.magenta;
        "constant.character.escape" = {
          fg = bright.white;
          modifiers = ["bold"];
        };
        "label" = bright.cyan;
        "module" = bright.cyan;
        "diff.plus" = bright.green;
        "diff.delta" = bright.yellow;
        "diff.minus" = bright.red;
        "warning" = bright.yellow;
        "error" = bright.red;
        "info" = bright.cyan;
        "hint" = bright.blue;
        "ui.background" = {bg = util.bg;};
        "ui.linenr" = {fg = normal.cyan;};
        "ui.linenr.selected" = {
          fg = normal.yellow;
          modifiers = ["bold"];
        };
        "ui.cursorline" = {bg = normal.black;};
        "ui.statusline" = {
          fg = util.fg;
          bg = bright.black;
        };
        "ui.statusline.normal" = {
          fg = util.fg;
          bg = bright.black;
        };
        "ui.statusline.insert" = {
          fg = util.fg;
          bg = normal.blue;
        };
        "ui.statusline.select" = {
          fg = util.fg;
          bg = bright.yellow;
        };
        "ui.statusline.inactive" = {
          fg = normal.white;
          bg = normal.black;
        };
        "ui.popup" = {bg = normal.black;};
        "ui.window" = {bg = normal.black;};
        "ui.help" = {
          bg = normal.black;
          fg = util.fg;
        };
        "ui.text" = {fg = util.fg;};
        "ui.text.focus" = {fg = util.fg;};
        "ui.selection" = {
          # modifiers = ["reversed"];
          bg = bright.yellow;
        };
        "ui.selection.primary" = {modifiers = ["reversed"];};
        # "ui.selection.primary" = { bg = bright.cyan; };
        "ui.cursor.primary" = {
          bg = normal.white;
          fg = normal.black;
        };
        "ui.cursor.match" = {bg = bright.cyan;};
        "ui.menu" = {
          fg = util.fg;
          bg = bright.black;
        };
        "ui.menu.selected" = {
          fg = bright.black;
          bg = bright.blue;
          modifiers = ["bold"];
        };
        "ui.virtual.whitespace" = bright.black;
        "ui.virtual.ruler" = {bg = normal.black;};
        "ui.virtual.inlay-hint" = {fg = normal.magenta;};
        "diagnostic.warning" = {
          underline = {
            color = bright.yellow;
            style = "curl";
          };
        };
        "diagnostic.error" = {
          underline = {
            color = bright.red;
            style = "curl";
          };
        };
        "diagnostic.info" = {
          underline = {
            color = bright.cyan;
            style = "curl";
          };
        };
        "diagnostic.hint" = {
          underline = {
            color = bright.blue;
            style = "curl";
          };
        };
        "markup.heading" = bright.cyan;
        "markup.bold" = {modifiers = ["bold"];};
        "markup.italic" = {modifiers = ["italic"];};
        "markup.strikethrough" = {modifiers = ["crossed_out"];};
        "markup.link.url" = {
          fg = bright.green;
          modifiers = ["underlined"];
        };
        "markup.link.text" = bright.red;
        "markup.raw" = bright.red;
      };
    };

    # theme = "nix-rice"

    # [editor]
    # bufferline = "multiple"
    # cursorline = true
    # true-color = true

    # [editor.cursor-shape]
    # insert = "bar"
    # normal = "block"
    # select = "underline"

    # [editor.lsp]
    # display-messages = true

    # [editor.statusline]
    # left = ["mode", "spinner", "version-control", "file-name", "file-modification-indicator"]

    settings = {
      theme = "nix-rice";
      editor = {
        bufferline = "multiple";
        cursorline = true;
        true-color = true;
        cursor-shape = {
          insert = "bar";
          normal = "block";
          select = "underline";
        };
        statusline.left = ["mode" "spinner" "version-control" "file-name" "file-modification-indicator"];
        lsp.display-messages = true;
        keys = let
          extend = {
            "A-x" = "extend_to_line_bounds";
            "X" = ["extend_line_up" "extend_to_line_bounds"];
          };
        in {
          normal = extend;
          select = extend;
        };
      };
    };

    languages = {
      language = [
        {
          name = "rust";
          language-servers = ["rust-analyzer" "lsp-ai"];
          auto-format = true;
        }
        {
          name = "nix";
          language-servers = ["nixd" "lsp-ai"];
          file-types = ["nix"];
          # auto-format = true;
          formatter = {
            command = "alejandra";
          };
        }
        {
          name = "ocaml";
          language-servers = ["ocamllsp" "lsp-ai"];
          file-types = ["ml" "mli"];
          auto-format = true;
          formatter = {
            command = "ocamlformat";
          };
        }
      ];

      language-server = {
        nixd = {
          command = "nixd";
        };

        lsp-ai = {
          command = "lsp-ai";
          config = {
            memory.fileStore = {};
            models = {
              llama32 = {
                type = "ollama";
                model = "llama3.2";
              };
              starcoder2 = {
                type = "ollama";
                model = "starcoder2:7b";
              };
            };
            completion = {
              model = "starcoder2";
              parameters = {
                maxContext = 1024;
                options = {
                  numPredict = 32;
                };
                postProcess = {
                  removeDuplicateStart = true;
                  removeDuplicateEnd = true;
                };
              };
            };
            chat = {
              trigger = "!C";
              action_display_name = "Chat";
              model = "llama32";
              parameters = {
                max_context = 4096;
                max_tokens = 1024;
                system = "You are a code assistant chatbot. The user will ask you for assistance coding and you will do your best to answer succinctly and accurately.";
              };
            };
          };
        };

        rust-analyzer = {
          config = {
            cargo = {
              buildScripts = {
                enable = true;
              };
            };
            procMacro = {
              enable = true;
            };
            check = {
              command = "clippy";
            };
          };
        };
      }; #language-server
    }; #languages
  }; #helix config
}
