[NeoVim] Configure LTeX
This commit is contained in:
111
.config/nvim/lua/lspconfig/ltex.lua
Normal file
111
.config/nvim/lua/lspconfig/ltex.lua
Normal file
@@ -0,0 +1,111 @@
|
||||
local M = {}
|
||||
|
||||
M.file = {
|
||||
dictionary = vim.fn.stdpath('config') .. '/spell/en.utf-8.add',
|
||||
disabledRules = vim.fn.stdpath('config') .. '/spell/disable.txt',
|
||||
hiddenFalsePositives = vim.fn.stdpath('config') .. '/spell/false.txt',
|
||||
}
|
||||
|
||||
local file_exists = function(file)
|
||||
local f = io.open(file, 'rb')
|
||||
if f then
|
||||
f:close()
|
||||
end
|
||||
return f ~= nil
|
||||
end
|
||||
|
||||
M.lines_from = function(file)
|
||||
if not file_exists(file) then
|
||||
return {}
|
||||
end
|
||||
local lines = {}
|
||||
for line in io.lines(file) do
|
||||
table.insert(lines, line)
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
local get_client_by_name = function(name)
|
||||
local buf_clients = vim.lsp.buf_get_clients()
|
||||
for _, client in ipairs(buf_clients) do
|
||||
if client.name == name then
|
||||
return client
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local update_config = function(lang, configtype)
|
||||
local client = get_client_by_name('ltex')
|
||||
if client then
|
||||
if client.config.settings.ltex[configtype] then
|
||||
client.config.settings.ltex[configtype] = {
|
||||
[lang] = M.lines_from(M.file[configtype]),
|
||||
}
|
||||
return client.notify('workspace/didChangeConfiguration', client.config.settings)
|
||||
else
|
||||
return vim.notify('Error when reading dictionary config, check it')
|
||||
end
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local add_to_file = function(configtype, lang, file, value)
|
||||
local dict = M.lines_from(file)
|
||||
for _, v in ipairs(dict) do
|
||||
if v == value then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
file = io.open(file, 'a+')
|
||||
if file then
|
||||
file:write(value .. '\n')
|
||||
file:close()
|
||||
else
|
||||
return vim.notify(string.format('Failed insert %s', value))
|
||||
end
|
||||
return update_config(lang, configtype)
|
||||
end
|
||||
|
||||
local do_command = function(arg, configtype)
|
||||
for lang, words in pairs(arg) do
|
||||
for _, word in ipairs(words) do
|
||||
add_to_file(configtype, lang, M.file[configtype], word)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
vim.lsp.commands['_ltex.addToDictionary'] = function(command, _)
|
||||
do_command(command.arguments[1].words, 'dictionary')
|
||||
end
|
||||
vim.lsp.commands['_ltex.disableRules'] = function(command, _)
|
||||
do_command(command.arguments[1].ruleIds, 'disabledRules')
|
||||
end
|
||||
vim.lsp.commands['_ltex.hideFalsePositives'] = function(command, _)
|
||||
do_command(command.arguments[1].falsePositives, 'hiddenFalsePositives')
|
||||
end
|
||||
|
||||
M.on_attach = function()
|
||||
vim.cmd('setlocal spell')
|
||||
vim.cmd('setlocal nospell')
|
||||
update_config('en-US', 'dictionary')
|
||||
update_config('en-US', 'disabledRules')
|
||||
update_config('en-US', 'hiddenFalsePositives')
|
||||
vim.keymap.set('n', 'zug', function()
|
||||
vim.cmd('normal! zug')
|
||||
update_config('en-US', 'dictionary')
|
||||
end, {
|
||||
buffer = true,
|
||||
desc = 'Remove word from spellfile and update ltex',
|
||||
})
|
||||
vim.keymap.set('n', 'zg', function()
|
||||
vim.cmd('normal! zg')
|
||||
update_config('en-US', 'dictionary')
|
||||
end, {
|
||||
buffer = true,
|
||||
desc = 'Add word to spellfile and update ltex',
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,5 +1,7 @@
|
||||
local servers = { 'pyright', 'sumneko_lua', 'eslint', 'tsserver', 'ltex' }
|
||||
|
||||
local ltex = require('lspconfig.ltex')
|
||||
|
||||
-- Mappings.
|
||||
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
|
||||
local opts = { noremap=true, silent=true }
|
||||
@@ -10,7 +12,7 @@ vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
|
||||
|
||||
-- Use an on_attach function to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
local on_attach = function(client, bufnr)
|
||||
local on_attach = function(_, bufnr)
|
||||
-- Mappings.
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
local bufopts = { noremap=true, silent=true, buffer=bufnr }
|
||||
@@ -52,6 +54,28 @@ for _, lsp in pairs(servers) do
|
||||
}
|
||||
end
|
||||
|
||||
require('lspconfig')['ltex'].setup {
|
||||
on_attach = function(client)
|
||||
on_attach(client)
|
||||
ltex.on_attach()
|
||||
end,
|
||||
capabilities = capabilities,
|
||||
flags = {
|
||||
-- This will be the default in neovim 0.7+
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
settings = {
|
||||
ltex = {
|
||||
dictionary = {},
|
||||
disabledRules = {},
|
||||
hiddenFalsePositives = {},
|
||||
additionalRules = {
|
||||
enablePickyRules = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- luasnip setup
|
||||
local luasnip = require 'luasnip'
|
||||
require('luasnip.loaders.from_vscode').lazy_load()
|
||||
|
||||
1
.config/nvim/spell/.gitignore
vendored
Normal file
1
.config/nvim/spell/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
false.txt
|
||||
1
.config/nvim/spell/disable.txt
Normal file
1
.config/nvim/spell/disable.txt
Normal file
@@ -0,0 +1 @@
|
||||
PASSIVE_VOICE
|
||||
10
.config/nvim/spell/en.utf-8.add
Normal file
10
.config/nvim/spell/en.utf-8.add
Normal file
@@ -0,0 +1,10 @@
|
||||
Read-Eval-Print-Loop
|
||||
Flexowriter
|
||||
Teitelman
|
||||
Interlisp
|
||||
JOHNNIAC
|
||||
REPLs
|
||||
Mathematica
|
||||
DSLs
|
||||
GPLs
|
||||
Plasil
|
||||
BIN
.config/nvim/spell/en.utf-8.add.spl
Normal file
BIN
.config/nvim/spell/en.utf-8.add.spl
Normal file
Binary file not shown.
Reference in New Issue
Block a user