Added dictionary configuration of ltex

This commit is contained in:
Sheldon Lee 2024-03-09 20:26:20 +08:00
parent 041fd6bd70
commit 8132992f59
5 changed files with 81 additions and 4 deletions

View File

@ -29,6 +29,32 @@ end)
-- (Optional) Configure lua language server for neovim -- (Optional) Configure lua language server for neovim
require('lspconfig').lua_ls.setup(lsp.nvim_lua_ls()) 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.skip_server_setup({'ltex'})
lsp.setup() lsp.setup()

View File

@ -1,3 +1,3 @@
require("sheldonmlee.packer") require("sheldonmlee.packer")
require("sheldonmlee.remap")
require("sheldonmlee.set") require("sheldonmlee.set")
require("sheldonmlee.remap")

View File

@ -50,4 +50,6 @@ return require('packer').startup(function(use)
use 'nvim-lua/plenary.nvim' use 'nvim-lua/plenary.nvim'
use 'ThePrimeagen/harpoon' use 'ThePrimeagen/harpoon'
use 'ap/vim-css-color'
end) end)

View File

@ -55,3 +55,50 @@ vim.keymap.set("n", "<leader>a", function() vim.cmd('lua require("harpoon.ui").n
vim.keymap.set("n", "<leader>r", function() vim.cmd('lua require("harpoon.ui").nav_file(2)') end) vim.keymap.set("n", "<leader>r", function() vim.cmd('lua require("harpoon.ui").nav_file(2)') end)
vim.keymap.set("n", "<leader>s", function() vim.cmd('lua require("harpoon.ui").nav_file(3)') end) vim.keymap.set("n", "<leader>s", function() vim.cmd('lua require("harpoon.ui").nav_file(3)') end)
vim.keymap.set("n", "<leader>t", function() vim.cmd('lua require("harpoon.ui").nav_file(4)') end) vim.keymap.set("n", "<leader>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", "<leader>zz", ltex_selection_add_word)
vim.keymap.set("n", "<leader>zz", ltex_add_word)
vim.keymap.set("n", "<leader>zd", function() vim.cmd.edit(LTEX_DICT) end)

View File

@ -14,7 +14,7 @@ vim.opt.incsearch = true
vim.opt.ignorecase = true vim.opt.ignorecase = true
vim.opt.smartcase = 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.undofile = true
vim.opt.scrolloff = 8 vim.opt.scrolloff = 8
@ -22,6 +22,8 @@ vim.opt.scrolloff = 8
-- 'no' disables signcolumn -- 'no' disables signcolumn
vim.opt.signcolumn = 'no' vim.opt.signcolumn = 'no'
LTEX_DICT = os.getenv("HOME") .. "/.config/ltex/dictionary.txt"
--vim.api.nvim_create_autocmd('BufWritePre', { --vim.api.nvim_create_autocmd('BufWritePre', {
-- pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' }, -- pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' },
-- command = 'silent! EslintFixAll', -- command = 'silent! EslintFixAll',
@ -29,7 +31,7 @@ vim.opt.signcolumn = 'no'
--}) --})
vim.api.nvim_create_autocmd('BufWritePre', { vim.api.nvim_create_autocmd('BufWritePre', {
pattern = { '*.tsx', '*.ts', '*.jsx', '*.js' }, pattern = { '*.tsx', '*.ts', '*.jsx', '*.js', html},
command = 'silent! Neoformat', command = 'silent! Neoformat',
group = vim.api.nvim_create_augroup('Eslint', {}), group = vim.api.nvim_create_augroup('Neoformat', {}),
}) })