-- Neovim LSP configuration for liquid_lsp
-- Place this in your init.lua or in a dedicated LSP config file

-- File type detection
vim.filetype.add({
  extension = {
    liquid = 'liquid',
  },
  pattern = {
    ['.*%.liquid'] = 'liquid',
    ['.*%.liquid%.html'] = 'liquid',
  },
})

local lspconfig = require('lspconfig')

-- Custom liquid_lsp configuration
local configs = require('lspconfig.configs')
if not configs.liquid_lsp then
  configs.liquid_lsp = {
    default_config = {
      cmd = { 'liquid_lsp' },  -- Assumes binary is in PATH
      filetypes = { 'liquid' },
      root_dir = function(fname)
        return lspconfig.util.root_pattern('.git', 'package.json', '.')(fname)
          or lspconfig.util.path.dirname(fname)
      end,
      settings = {},
      init_options = {},
    },
    docs = {
      description = [[
https://github.com/YOUR_USERNAME/liquid_lsp

Language server for Liquid template language
]],
      default_config = {
        root_dir = [[root_pattern('.git', '.')]],
      },
    },
  }
end

-- Setup liquid_lsp
lspconfig.liquid_lsp.setup({
  capabilities = require('cmp_nvim_lsp').default_capabilities(),
  on_attach = function(client, bufnr)
    -- Your standard LSP on_attach setup
    local bufopts = { noremap = true, silent = true, buffer = bufnr }
    vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
    vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
    vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
  end,
})

-- Optional: Treesitter syntax highlighting for Liquid
-- Add this to your treesitter config if you have one
require('nvim-treesitter.configs').setup({
  ensure_installed = {
    -- other parsers...
    'liquid'  -- If available
  },
  highlight = {
    enable = true,
  },
})