Cant seem to get format on save work on kate

i have been trying to figure this out on AI, Google and forums and i seem not to find what i am doing wrong. What i am trying is to use prettier as default formatter on save and nix has it own since prettier dosent support this yet as what i read and i just cant get it working and need some help pointers and there might be something more issues on my kate.nix too that i havent found yet since being just stuck on format on save…

kate.nix

{ pkgs, ... }:

let
  lspSettings = {
    servers = {
      nix = {
        command = [ "nixd" ];
        # Explicit formatting option for nixd
        options.formatting.command = [ "nixfmt" ];
      };
      markdown = {
        command = [
          "marksman"
          "server"
        ];
      };
      toml = {
        command = [
          "taplo"
          "lsp"
          "stdio"
        ];
      };
      yaml = {
        command = [
          "yaml-language-server"
          "--stdio"
        ];
      };
      typescript = {
        command = [
          "typescript-language-server"
          "--stdio"
        ];
        rootIndicationFileNames = [
          "package.json"
          "tsconfig.json"
        ];
        filetypes = [
          "javascript"
          "typescript"
          "javascriptreact"
          "typescriptreact"
        ];
        # DEEP FIX: Explicitly enabling formatting providers
        initializationOptions = {
          documentFormattingProvider = true;
          provideFormatter = true;
          preferences = {
            includeInlayParameterNameHints = "all";
            includeInlayVariableTypeHints = true;
            includeInlayFunctionParameterTypeHints = true;
          };
        };
      };
      css = {
        command = [
          "vscode-css-language-server"
          "--stdio"
        ];
      };
      html = {
        command = [
          "vscode-html-language-server"
          "--stdio"
        ];
      };
      python = {
        command = [ "python-lsp-server" ];
        configuration = {
          pylsp.plugins.jedi_completion.include_params = true;
          # Ensure black/autopep8 formatting is enabled if installed
          pylsp.plugins.black.enabled = true;
        };
      };
      cpp = {
        command = [ "clangd" ];
      };
      csharp = {
        command = [ "csharp-ls" ];
      };
      php = {
        command = [ "phpactor" ];
      };
    };
  };
in
{
  # 1. LSP Config
  xdg.configFile."kate/lspclient/settings.json".text = builtins.toJSON lspSettings;

  # 2. Main IDE Configuration
  xdg.configFile."katerc".text = ''
    [General]
    Show Welcome Page=false
    Startup Session=last

    [KTextEditor::Document]
    Auto Bracket Insertion=true
    Indentation Width=4
    Replace Tabs w/ Spaces=true
    Line Modification Markers=true
    NewLine at End of File=true
    Auto Trim Stale Spaces=true

    [KTextEditor::View]
    Dynamic Word Wrap=true
    Line Numbers=true
    Show Icons Border=true
    Highlight Caret Line=true
    Show Scrollbar Marks=true
    Default Encoding=UTF-8
    Bracket Matching=true
    Show Indentation Lines=true
    Automatic Completion Preselection=true

    [LSPClient]
    Auto Format On Save=true
    Incremental Sync=true
    Show Diagnostics=true
    Messages Limit=100
    Show Signature Help=true
    Show Inlay Hints=true
    # The crucial fix for the "Prompt on start" and formatting permissions
    Allowed and Blocked Servers={\\"allowed\\":[\\"*\\"],\\"blocked\\":[]}

    [MainWindow]
    Plugins=lspclient,kateprojectplugin,konsoleplugin,katesearchplugin,katesymbolviewer,katefiletree,markdownpreview,gitblame,externaltools,katectagsplugin,filebrowser,katesnippets,katebacktraceplugin,compilationproxy

    [Project]
    Git Integration=true
    Show Git Branch=true
    Index Project=true
    Multi-Project Behavior=Restore Last

    [externaltools]
    # DEEP SEARCH SOLUTION: If LSP fails, these force format on save
    # This creates a "Manual Format" option in the Tools menu as a fallback
    0-name=Prettier (Force)
    0-command=prettier --write %f
    0-executable=prettier
    0-mimetype=text/html;text/css;application/javascript;application/x-typescript
    0-savebefore=true

    1-name=Nixfmt (Force)
    1-command=nixfmt %f
    1-executable=nixfmt
    1-mimetype=text/x-nix
    1-savebefore=true
  '';

  # 3. Global Shortcuts
  xdg.configFile."kglobalshortcutsrc".text = ''
    [kate]
    activate toolview konsole=Ctrl+`
    Quick Open=Ctrl+P
    Search in Files=Ctrl+Shift+F
    activate toolview kateprojectgit=Ctrl+G
    activate toolview katesnippets=Ctrl+Alt+S
    Go to Definition=F12
    Find References=Shift+F12
    Rename=F2
    View: Hide Sidebar=Ctrl+B
    # Shortcut for the Force Prettier tool if LSP save fails
    External Tool: Prettier (Force)=Ctrl+Alt+L
  '';
}

i also have kate imported to home-manager since so many settings still works

home.nix

{
  config,
  pkgs,
  lib,
  ...
}:

let
  ## =============================================================
  ## PACKAGE SETS FOR ORGANIZATION
  ## =============================================================

  kdeApps = with pkgs.kdePackages; [
    kate
    audiotube
    plasmatube
    kdenlive
    #neochat
  ];

  developmentDependencies = with pkgs; [
    # Runtimes & Compilers
    nodejs # JS, React, Next.js
    (python3.withPackages (
      ps: with ps; [
        pandas
        requests
      ]
    ))
    php # PHP development
    phpPackages.composer # PHP package manager
    gcc # C++ compiler
    gnumake # Build tool
    dotnet-sdk # C# / .NET development

    # Web & UI (HTML, CSS, JS, React, Next.js)
    typescript-language-server # Intelligence for JS/TS/React
    vscode-langservers-extracted # HTML, CSS, and JSON intelligence
    tailwindcss-language-server # For modern CSS utility support

    # Documentation & Config (README, TOML, YAML)
    marksman # LSP for Markdown (README.md)
    taplo # The gold-standard LSP for TOML
    yaml-language-server # Professional intelligence for YAML

    # Nix & System
    nixd # Poweruser Nix intelligence
    nixfmt-rfc-style # Official Nix code formatter
    python3Packages.python-lsp-server # Python intelligence
    phpactor # Advanced PHP refactoring
    clang-tools # Provides clangd for C++
    csharp-ls # Fast C# LSP

    # Essential Formatters & Tools (Required for Kate Auto-format)
    nodePackages.prettier
    nixfmt-rfc-style
    git
    universal-ctags # Added: Powers the 'katectags' plugin for jumping to code symbols
  ];

  mediaAndGraphics = with pkgs; [
    darktable
    gimp
    inkscape
  ];

  otherApps = with pkgs; [
    thunderbird
    libreoffice
    signal-desktop
  ];

  securityApps = with pkgs; [
    protonvpn-gui
    protonmail-bridge-gui
    proton-pass
  ];

  userPackages =
    with pkgs;
    [
      zsh-powerlevel10k
      fastfetch
    ]
    ++ kdeApps
    ++ developmentDependencies
    ++ mediaAndGraphics
    ++ otherApps
    ++ securityApps;

in
{
  imports = [
    ./kate.nix
  ];

  home.username = "phatle";
  home.homeDirectory = "/home/phatle";

  home.stateVersion = "25.11";

  home.packages = userPackages;

  ## -------------------------------------------------------------
  ## 1. DECLARATIVE GIT CONFIGURATION
  ## -------------------------------------------------------------
  programs.git = {
    enable = true;
    userName = "Marko Jokinen";
    userEmail = "thephatle@proton.me";
    aliases = {
      s = "status";
      co = "checkout";
      ci = "commit";
      ac = "!git add -A && git commit -m";
    };
    extraConfig = {
      init.defaultBranch = "main";
      pull.rebase = true;
    };
  };

  ## -------------------------------------------------------------
  ## 2. SYSTEM MONITORING (BTOP)
  ## -------------------------------------------------------------
  programs.btop = {
    enable = true;
    settings = {
      color_theme = "default";
      vim_keys = true;
      update_ms = 1000;
    };
  };

  ## -------------------------------------------------------------
  ## 3. ENHANCED ZSH & PRODUCTIVITY ALIASES
  ## -------------------------------------------------------------
  programs.zsh = {
    enable = true;
    enableCompletion = true;
    autosuggestion.enable = true;
    syntaxHighlighting.enable = true;

    shellAliases = {
      update = "nh os switch /home/phatle/NixOS";
      c = "clear";
      v = "kate";
      gc = "nix-collect-garbage -d";
    };

    history = {
      path = "${config.home.homeDirectory}/.zsh_history";
      size = 10000;
      save = 10000;
    };

    oh-my-zsh = {
      enable = true;
      theme = "robbyrussell";
      plugins = [
        "git"
        "sudo"
        "node"
        "python"
        "dotnet"
        "direnv"
      ];
    };

    initContent = ''
      source ${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/powerlevel10k.zsh-theme
      [[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
    '';
  };

  programs.ssh = {
    enable = true;
    enableDefaultConfig = false;
    matchBlocks = {
      "codeberg.org" = {
        hostname = "codeberg.org";
        user = "git";
        identityFile = "~/.ssh/codeberg";
      };
    };
  };

  programs.direnv = {
    enable = true;
    nix-direnv.enable = true;
    enableZshIntegration = true;
  };

  programs.fastfetch.enable = true;
  programs.firefox.enable = true;

  ## -------------------------------------------------------------
  ## 4. SESSION VARIABLES (SAFE LOGIN + POWER SAVING)
  ## -------------------------------------------------------------
  home.sessionVariables = {
    EDITOR = "kate";
    # Ensures dotnet tools are in your PATH for the C# LSP
    DOTNET_ROOT = "${pkgs.dotnet-sdk}";

    # Tells Python where to look for the libraries you installed (like pandas)
    PYTHONPATH = "${pkgs.python3}/lib/python/site-packages";

    # Makes sure Kate uses the Nix-provided binary for its embedded terminal
    SHELL = "${pkgs.zsh}/bin/zsh"; # or bash
  };
}