-- Minimal test configuration
-- Run with: nvim -u minimal-nvim-test.lua example.eas

-- Set up the runtime path
vim.opt.runtimepath:prepend(vim.fn.stdpath('data') .. '/site/pack/packer/start/nvim-lspconfig')

-- Simple filetype detection
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
  pattern = {"*.eas", "*.evm"},
  command = "set filetype=evmasm",
})

-- Check if lspconfig is available
local ok, lspconfig = pcall(require, 'lspconfig')
if not ok then
  print("LSPConfig not found. Install with:")
  print("git clone https://github.com/neovim/nvim-lspconfig ~/.local/share/nvim/site/pack/packer/start/nvim-lspconfig")
  return
end

-- Simple LSP setup
local configs = require('lspconfig.configs')

configs.evm_asm_lsp = {
  default_config = {
    cmd = { './target/release/evm-asm-lsp' }, -- Adjust path as needed
    filetypes = { 'evmasm' },
    root_dir = function() return vim.fn.getcwd() end,
  },
}

lspconfig.evm_asm_lsp.setup{
  on_attach = function(_, bufnr)
    print("EVM ASM LSP attached!")
    vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = bufnr })
    vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { buffer = bufnr })
    vim.keymap.set('n', 'gr', vim.lsp.buf.references, { buffer = bufnr })
  end,
}

-- Auto-start LSP for evmasm files
vim.api.nvim_create_autocmd("FileType", {
  pattern = "evmasm",
  callback = function()
    vim.lsp.start({
      name = 'evm-asm-lsp',
      cmd = { './target/release/evm-asm-lsp' }, -- Adjust path
      root_dir = vim.fn.getcwd(),
    })
  end,
})

print("Minimal EVM ASM config loaded. Press K on an opcode to test hover.")