diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua index 6dbc831..e278897 100644 --- a/.config/nvim/after/plugin/lsp.lua +++ b/.config/nvim/after/plugin/lsp.lua @@ -29,6 +29,32 @@ end) -- (Optional) Configure lua language server for neovim require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls()) +local function load_dictionary(file_path) + if not os.rename(file_path, file_path) and true or false then + print("Ltex Dictionary path not found.") + return + end + + local dict = {} + local lines = io.lines(file_path) + for line in io.lines(file_path) do + table.insert(dict, line) + end + return dict +end + +local dictionary = load_dictionary(LTEX_DICT) + +require('lspconfig').ltex.setup{ + settings = { + ltex = { + dictionary = { + ["en-US"] = dictionary, + ["en-GB"] = dictionary, + }, + }, + }, +} -- lsp.skip_server_setup({'ltex'}) lsp.setup() diff --git a/.config/nvim/lua/sheldonmlee/init.lua b/.config/nvim/lua/sheldonmlee/init.lua index 35c86dc..2d59153 100644 --- a/.config/nvim/lua/sheldonmlee/init.lua +++ b/.config/nvim/lua/sheldonmlee/init.lua @@ -1,3 +1,3 @@ require("sheldonmlee.packer") -require("sheldonmlee.remap") require("sheldonmlee.set") +require("sheldonmlee.remap") diff --git a/.config/nvim/lua/sheldonmlee/packer.lua b/.config/nvim/lua/sheldonmlee/packer.lua index 6bd05d1..b9543c3 100644 --- a/.config/nvim/lua/sheldonmlee/packer.lua +++ b/.config/nvim/lua/sheldonmlee/packer.lua @@ -50,4 +50,6 @@ return require('packer').startup(function(use) use 'nvim-lua/plenary.nvim' use 'ThePrimeagen/harpoon' + + use 'ap/vim-css-color' end) diff --git a/.config/nvim/lua/sheldonmlee/remap.lua b/.config/nvim/lua/sheldonmlee/remap.lua index 084fbdf..f46c290 100644 --- a/.config/nvim/lua/sheldonmlee/remap.lua +++ b/.config/nvim/lua/sheldonmlee/remap.lua @@ -55,3 +55,50 @@ vim.keymap.set("n", "a", function() vim.cmd('lua require("harpoon.ui").n vim.keymap.set("n", "r", function() vim.cmd('lua require("harpoon.ui").nav_file(2)') end) vim.keymap.set("n", "s", function() vim.cmd('lua require("harpoon.ui").nav_file(3)') end) vim.keymap.set("n", "t", function() vim.cmd('lua require("harpoon.ui").nav_file(4)') end) + +local function ltex_append_dictionary(word) + if not word or word == "\n" or word == "" then + print("Word empty:", word) + return + end + + local file = io.open(LTEX_DICT, "a") + if not file then + print("Failed to open the dictionary file.") + return + end + file:write(word .. "\n") + file:close() + print("Added word to dictionary:", word) +end + +local function ltex_selection_add_word() + local _, csrow, cscol, _ = unpack(vim.fn.getpos("'<")) + local _, cerow, cecol, _ = unpack(vim.fn.getpos("'>")) + if csrow ~= cerow then + print("Multi-line selection is not supported") + return + end + + local word = vim.fn.getline(csrow):sub(cscol, cecol) + + ltex_append_dictionary(word) +end + +local function ltex_add_word() + local line = vim.api.nvim_get_current_line() + local col = vim.api.nvim_win_get_cursor(0)[2] + 1 -- Cursor column position is 0-indexed + local startCol, _ = line:sub(1, col):find("%w+%s*$") + local _, endCol = line:sub(col):find("%s*%w+") + + local word = nil + if startCol and endCol then + word = line:sub(startCol, col + endCol-1) + end + + ltex_append_dictionary(word) +end + +vim.keymap.set("v", "zz", ltex_selection_add_word) +vim.keymap.set("n", "zz", ltex_add_word) +vim.keymap.set("n", "zd", function() vim.cmd.edit(LTEX_DICT) end) diff --git a/.config/nvim/lua/sheldonmlee/set.lua b/.config/nvim/lua/sheldonmlee/set.lua index e65fadd..33a51cf 100644 --- a/.config/nvim/lua/sheldonmlee/set.lua +++ b/.config/nvim/lua/sheldonmlee/set.lua @@ -14,7 +14,7 @@ vim.opt.incsearch = true vim.opt.ignorecase = true vim.opt.smartcase = true -vim.opt.undodir = os.getenv("HOME") .. "/.config/nvim/.undodir" +vim.opt.undodir = os.getenv("HOME") .. "/.local/share/nvim-undo" vim.opt.undofile = true vim.opt.scrolloff = 8 @@ -22,6 +22,8 @@ vim.opt.scrolloff = 8 -- 'no' disables signcolumn vim.opt.signcolumn = 'no' +LTEX_DICT = os.getenv("HOME") .. "/.config/ltex/dictionary.txt" + --vim.api.nvim_create_autocmd('BufWritePre', { -- pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' }, -- command = 'silent! EslintFixAll', @@ -29,7 +31,7 @@ vim.opt.signcolumn = 'no' --}) vim.api.nvim_create_autocmd('BufWritePre', { - pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' }, + pattern = { '*.tsx', '*.ts', '*.jsx', '*.js', html}, command = 'silent! Neoformat', - group = vim.api.nvim_create_augroup('Eslint', {}), + group = vim.api.nvim_create_augroup('Neoformat', {}), })