Skip to content

Commit e8e64bc

Browse files
committed
added cspell
1 parent fcc66c3 commit e8e64bc

11 files changed

+291
-39
lines changed

Diff for: ftdetect/css.lua

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vim.api.nvim_create_autocmd("BufWinEnter", {
2+
pattern = "*.css",
3+
command = "setlocal syntax=css tabstop=2 shiftwidth=2 softtabstop=2",
4+
})

Diff for: init.lua

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-- for keymap
2-
L_DEVORAK = true
2+
L_DVORAK = true
3+
4+
-- AI auto complete
5+
vim.g.ai_auto = false
36

47
-- providers
58
vim.g.python3_host_prog = "/usr/bin/python3"
@@ -13,9 +16,27 @@ require("core.lualine-config")
1316
require("core.normalcmds")
1417
require("core.cmp-src") -- dictionary
1518

19+
require("utils.cspell") -- spelling
20+
require("utils.path") -- path utils like getting rot dir of a git repo
1621
-- language servers
17-
require("lspconfig").jedi_language_server.setup({}) -- python
22+
local lsp_conf = require("lspconfig")
23+
24+
--Enable (broadcasting) snippet capability for completion
25+
local capabilities = vim.lsp.protocol.make_client_capabilities()
26+
capabilities.textDocument.completion.completionItem.snippetSupport = true
27+
28+
lsp_conf.cssls.setup({
29+
capabilities = capabilities,
30+
})
31+
32+
lsp_conf.jedi_language_server.setup({}) -- python
33+
34+
lsp_conf.pylsp.setup({}) -- python
35+
36+
lsp_conf.clangd.setup({}) -- c++
37+
38+
lsp_conf.cmake.setup({}) -- cmake
1839

19-
require("lspconfig").pylsp.setup({}) -- python
40+
lsp_conf.html.setup({}) -- html
2041

21-
require("lspconfig").clangd.setup({}) -- c++
42+
lsp_conf.tsserver.setup({}) -- type script

Diff for: keymap_doc.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@
88
"<A->>", "<cmd>BufferMoveNext<CR>"
99
"<A-c>", "<cmd>BufferClose<CR>"
1010
"<A-f>", "<cmd>BufferPick<CR>"
11+
12+
## cspell
13+
14+
<Leader>aw - add word to cspell config

Diff for: lazy-lock.json

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
{
2-
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
2+
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
33
"FTerm.nvim": { "branch": "master", "commit": "d1320892cc2ebab472935242d9d992a2c9570180" },
4-
"LuaSnip": { "branch": "master", "commit": "8f3d3465ba5c7ade0a8adb41eca5736f291a3fa8" },
5-
"alpha-nvim": { "branch": "main", "commit": "41283fb402713fc8b327e60907f74e46166f4cfd" },
6-
"barbar.nvim": { "branch": "master", "commit": "88fe247ba6453b6ac422f26eb047acaac1a6000a" },
4+
"LuaSnip": { "branch": "master", "commit": "45db5addf8d0a201e1cf247cae4cdce605ad3768" },
5+
"alpha-nvim": { "branch": "main", "commit": "b6f4129302db197a7249e67a90de3f2b676de13e" },
6+
"barbar.nvim": { "branch": "master", "commit": "c20691d686addb0d6ea87896d186c082324b01f8" },
77
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
88
"cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" },
99
"cmp-dictionary": { "branch": "main", "commit": "c5ffc6afb7f3a68da981ed9c56f3d9d8f3d907b7" },
1010
"cmp-git": { "branch": "main", "commit": "50d526dff0f6bc441b51fc269d9fdc99a50c76af" },
11-
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
11+
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
1212
"cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
1313
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
1414
"cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
15-
"codeium.nvim": { "branch": "main", "commit": "f6a2ef32a9e923cb0104a19d3e426b0e40e49505" },
16-
"conform.nvim": { "branch": "master", "commit": "12b3995537f52ba2810a9857e8ca256881febbda" },
17-
"gitsigns.nvim": { "branch": "main", "commit": "035da036e68e509ed158414416c827d022d914bd" },
18-
"harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" },
19-
"indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" },
20-
"lazy.nvim": { "branch": "main", "commit": "3f13f080434ac942b150679223d54f5ca91e0d52" },
21-
"lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" },
15+
"conform.nvim": { "branch": "master", "commit": "62eba813b7501b39612146cbf29cd07f1d4ac29c" },
16+
"gitsigns.nvim": { "branch": "main", "commit": "899e993850084ea33d001ec229d237bc020c19ae" },
17+
"harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" },
18+
"indent-blankline.nvim": { "branch": "master", "commit": "db926997af951da38e5004ec7b9fbdc480b48f5d" },
19+
"lazy.nvim": { "branch": "main", "commit": "077102c5bfc578693f12377846d427f49bc50076" },
20+
"lualine.nvim": { "branch": "master", "commit": "b431d228b7bbcdaea818bdc3e25b8cdbe861f056" },
2221
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
23-
"mason.nvim": { "branch": "main", "commit": "751b1fcbf3d3b783fcf8d48865264a9bcd8f9b10" },
24-
"neoscroll.nvim": { "branch": "master", "commit": "0a86b3dc2555cb7872feedca64ef036b8417fb73" },
25-
"nvim-cmp": { "branch": "main", "commit": "8f3c541407e691af6163e2447f3af1bd6e17f9a3" },
26-
"nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" },
27-
"nvim-dap": { "branch": "master", "commit": "6ae8a14828b0f3bff1721a35a1dfd604b6a933bb" },
28-
"nvim-lspconfig": { "branch": "master", "commit": "9eb6d866840df0f3fb1d2e8f34a7e0cfdf80f980" },
29-
"nvim-metals": { "branch": "main", "commit": "c6268555d0b471262af78818f11a086ddf30688b" },
30-
"nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" },
31-
"nvim-tree.lua": { "branch": "master", "commit": "5a18b9827491aa1aea710bc9b85c6b63ed0dad14" },
32-
"nvim-treesitter": { "branch": "master", "commit": "160e5d52c841dc9261c0b2dc6f253bddbcf3d766" },
33-
"nvim-web-devicons": { "branch": "master", "commit": "794bba734ec95eaff9bb82fbd112473be2087283" },
34-
"plenary.nvim": { "branch": "master", "commit": "08e301982b9a057110ede7a735dd1b5285eb341f" },
35-
"rainbow_csv": { "branch": "master", "commit": "6b914b420fd390103d9d98b3d6a67648ebe59274" },
36-
"telescope.nvim": { "branch": "master", "commit": "35f94f0ef32d70e3664a703cefbe71bd1456d899" },
37-
"todo-comments.nvim": { "branch": "main", "commit": "a7e39ae9e74f2c8c6dc4eea6d40c3971ae84752d" },
38-
"vim-fugitive": { "branch": "master", "commit": "dac8e5c2d85926df92672bf2afb4fc48656d96c7" }
39-
}
22+
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
23+
"neoscroll.nvim": { "branch": "master", "commit": "532dcc8cea4287c4cad6bb77532989a8217cfc7b" },
24+
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
25+
"nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" },
26+
"nvim-dap": { "branch": "master", "commit": "281a2e4cd1e7a17cea7ecb1745d84a8ab1249925" },
27+
"nvim-lint": { "branch": "master", "commit": "a7ce9c78a7c710c28bee56dfab10a5c0c80b7fb5" },
28+
"nvim-lspconfig": { "branch": "master", "commit": "6bfd9210e312af6cfedba05d272e85618c93ab0d" },
29+
"nvim-metals": { "branch": "main", "commit": "1b87e6bfa4174b5fbaee9ca7ec79d8eae8df7f18" },
30+
"nvim-notify": { "branch": "master", "commit": "d333b6f167900f6d9d42a59005d82919830626bf" },
31+
"nvim-tree.lua": { "branch": "master", "commit": "d43ab67d0eb4317961c5e9d15fffe908519debe0" },
32+
"nvim-treesitter": { "branch": "master", "commit": "585860a1865853d2c287c8ef534297da8115818e" },
33+
"nvim-web-devicons": { "branch": "master", "commit": "3722e3d1fb5fe1896a104eb489e8f8651260b520" },
34+
"plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" },
35+
"rainbow_csv": { "branch": "master", "commit": "3dbbfd7d17536aebfb80f571255548495574c32b" },
36+
"telescope.nvim": { "branch": "master", "commit": "5972437de807c3bc101565175da66a1aa4f8707a" },
37+
"todo-comments.nvim": { "branch": "main", "commit": "8f45f353dc3649cb9b44cecda96827ea88128584" },
38+
"vim-fugitive": { "branch": "master", "commit": "0444df68cd1cdabc7453d6bd84099458327e5513" }
39+
}

Diff for: lua/core/keymaps.lua

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,23 @@ vim.keymap.set("!", "<F10>", "<Cmd>x<CR>")
2222
-----------------
2323
-- normal mode --
2424
-----------------
25+
26+
-- map leader to <Space>
27+
vim.keymap.set("n", " ", "<Nop>", { silent = true, remap = false })
28+
vim.g.mapleader = " "
2529
-- Resize with arrows
2630
-- delta: 2 lines
2731
vim.keymap.set("n", "<C-Up>", ":resize -2<CR>", opts)
2832
vim.keymap.set("n", "<C-Down>", ":resize +2<CR>", opts)
2933
vim.keymap.set("n", "<C-Left>", ":vertical resize -2<CR>", opts)
3034
vim.keymap.set("n", "<C-Right>", ":vertical resize +2<CR>", opts)
31-
35+
-- add word to cspell dict
36+
vim.keymap.set(
37+
"n",
38+
"<leader>aw",
39+
"<cmd>lua require('utils.cspell').add_word_to_c_spell_dictionary()<CR>",
40+
{ noremap = true, silent = true, desc = "Add unknown word to cspell dictionary" }
41+
)
3242
-----------------
3343
-- Visual mode --
3444
-----------------
@@ -37,8 +47,8 @@ vim.keymap.set("n", "<C-Right>", ":vertical resize +2<CR>", opts)
3747
vim.keymap.set("v", "<", "<gv", opts)
3848
vim.keymap.set("v", ">", ">gv", opts)
3949

40-
-- l-devorak area
41-
if L_DEVORAK then
50+
-- l-dvorak area
51+
if L_DVORAK then
4252
-- normal mode
4353
vim.keymap.set("n", "d", "h")
4454
vim.keymap.set("n", "t", "j")

Diff for: lua/core/normalcmds.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ vim.cmd("command Bc BufferClose")
77
-- quit all with Qa
88
vim.cmd("command Qa quitall")
99

10-
-- ConformInfo wit Ci
10+
-- ConformInfo with Ci
1111
vim.cmd("command Ci ConformInfo")

Diff for: lua/plugins/codium-AI-autocomplete.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ local M = {
88
require("codeium").setup({})
99
end,
1010
}
11-
12-
return M
11+
-- check if ai_auto is true, set in init.lua
12+
if vim.g.ai_auto then
13+
return M
14+
else
15+
return {}
16+
end

Diff for: lua/plugins/cspell.lua

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--- plugins/cspell.lua
2+
return {
3+
--- Install cspell with mason
4+
{
5+
"williamboman/mason.nvim",
6+
opts = {
7+
ensure_installed = {
8+
"cspell",
9+
},
10+
},
11+
},
12+
-- Lint file
13+
{
14+
"mfussenegger/nvim-lint",
15+
event = "VeryLazy",
16+
opts = {
17+
linters_by_ft = {
18+
["*"] = { "cspell", "codespell" }, -- Install with: pip install codespell
19+
},
20+
},
21+
config = function(_, opts)
22+
local lint = require("lint")
23+
lint.linters_by_ft = opts.linters_by_ft
24+
25+
vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave" }, {
26+
callback = function()
27+
local names = lint._resolve_linter_by_ft(vim.bo.filetype)
28+
29+
-- Create a copy of the names table to avoid modifying the original.
30+
names = vim.list_extend({}, names)
31+
32+
-- Add fallback linters.
33+
if #names == 0 then
34+
vim.list_extend(names, lint.linters_by_ft["_"] or {})
35+
end
36+
37+
-- Add global linters.
38+
vim.list_extend(names, lint.linters_by_ft["*"] or {})
39+
40+
-- Run linters.
41+
if #names > 0 then
42+
-- Check if the linter is available, otherwise it will throw an error.
43+
for _, name in ipairs(names) do
44+
local cmd = vim.fn.executable(name)
45+
if cmd == 0 then
46+
vim.notify("Linter " .. name .. " is not available", vim.log.levels.INFO)
47+
return
48+
else
49+
-- Run the linter
50+
lint.try_lint(name)
51+
end
52+
end
53+
end
54+
end,
55+
})
56+
end,
57+
},
58+
}

Diff for: lua/plugins/nvim-cmp.lua

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ M.config = function()
6565
{ name = "nvim_lsp" },
6666
{ name = "nvim_lua" },
6767
{ name = "luasnip" }, -- For luasnip users.
68+
{ name = "css" },
6869
}, {
6970
{ name = "buffer" },
7071
{ name = "dictionary", keyword_length = 2 },

Diff for: lua/utils/cspell.lua

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
local Path = require("utils.path")
2+
3+
local M = {}
4+
5+
function M.create_cspell_json_if_not_exist()
6+
local cspell_json_path = Path.get_root_directory() .. "/cspell.json"
7+
8+
if vim.fn.filereadable(cspell_json_path) == 0 then
9+
local file = io.open(cspell_json_path, "w")
10+
if file then
11+
local default_content = [[
12+
{
13+
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
14+
"version": "0.2",
15+
"language": "en",
16+
"globRoot": ".",
17+
"dictionaryDefinitions": [
18+
{
19+
"name": "cspell-tool",
20+
"path": "./cspell-tool.txt",
21+
"addWords": true
22+
}
23+
],
24+
"dictionaries": [
25+
"cspell-tool"
26+
],
27+
"ignorePaths": [
28+
"node_modules",
29+
"dist",
30+
"build",
31+
"/cspell-tool.txt"
32+
]
33+
}
34+
]]
35+
file:write(default_content)
36+
file:close()
37+
else
38+
vim.notify("Could not create cSpell.json", vim.log.levels.WARN, { title = "cSpell" })
39+
end
40+
end
41+
end
42+
43+
-- Add unknown word under cursor to dictionary
44+
function M.add_word_to_c_spell_dictionary()
45+
local word = vim.fn.expand("<cword>")
46+
47+
-- Show popup to confirm the action
48+
local confirm = vim.fn.confirm("Add '" .. word .. "' to cSpell dictionary?", "&Yes\n&No", 2)
49+
if confirm ~= 1 then
50+
M.add_word_from_diagnostics_to_c_spell_dictionary()
51+
return
52+
end
53+
54+
M.create_cspell_json_if_not_exist()
55+
local dictionary_path = Path.get_root_directory() .. "/cspell-tool.txt"
56+
57+
-- Append the word to the dictionary file
58+
local file = io.open(dictionary_path, "a")
59+
if file then
60+
-- Detect new line at the end of the file or not
61+
local last_char = file:seek("end", -1)
62+
if last_char ~= nil and last_char ~= "\n" then
63+
word = "\n" .. word
64+
end
65+
66+
file:write(word .. "")
67+
file:close()
68+
-- Reload buffer to update the dictionary
69+
vim.cmd("e!")
70+
else
71+
vim.notify("Could not open cSpell dictionary", vim.log.levels.WARN, { title = "cSpell" })
72+
end
73+
end
74+
75+
-- Add unknown word from cspell diagnostics source to dictionary
76+
function M.add_word_from_diagnostics_to_c_spell_dictionary()
77+
-- Get diagnostics source and only get from cspell
78+
local bufnr = vim.api.nvim_get_current_buf()
79+
local winnr = vim.api.nvim_get_current_win()
80+
local cursor = vim.api.nvim_win_get_cursor(winnr)
81+
local diagnostics = vim.lsp.diagnostic.get_line_diagnostics(bufnr, cursor[1] - 1)
82+
local cspell_diagnostics = {}
83+
for _, diagnostic in ipairs(diagnostics) do
84+
if diagnostic.source == "cspell" then
85+
table.insert(cspell_diagnostics, diagnostic)
86+
end
87+
end
88+
89+
-- Get the first word from the first cspell diagnostic
90+
-- E.g. "Unknown word ( word )"
91+
local word = cspell_diagnostics[1].message:match("%((.+)%)")
92+
if word == nil then
93+
vim.notify("Could not find unknown word", vim.log.levels.WARN, { title = "cSpell" })
94+
return
95+
end
96+
97+
-- Show popup to confirm the action
98+
local confirm = vim.fn.confirm("Add '" .. word .. "' to cSpell dictionary?", "&Yes\n&No", 2)
99+
if confirm ~= 1 then
100+
return
101+
end
102+
103+
M.create_cspell_json_if_not_exist()
104+
local dictionary_path = Path.get_root_directory() .. "/cspell-tool.txt"
105+
106+
-- Append the word to the dictionary file
107+
local file = io.open(dictionary_path, "a")
108+
if file then
109+
-- Detect new line at the end of the file or not
110+
local last_char = file:seek("end", -1)
111+
if last_char ~= nil and last_char ~= "\n" then
112+
word = "\n" .. word
113+
end
114+
115+
file:write(word .. "")
116+
file:close()
117+
-- Reload buffer to update the dictionary
118+
vim.cmd("e!")
119+
else
120+
vim.notify("Could not open cSpell dictionary", vim.log.levels.WARN, { title = "cSpell" })
121+
end
122+
end
123+
124+
return M

Diff for: lua/utils/path.lua

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
local M = {}
2+
3+
--- Check if current directory is a git repo
4+
---@return boolean
5+
function M.is_git_repo()
6+
vim.fn.system("git rev-parse --is-inside-work-tree")
7+
return vim.v.shell_error == 0
8+
end
9+
10+
--- Get root directory of git project
11+
---@return string|nil
12+
function M.get_git_root()
13+
return vim.fn.systemlist("git rev-parse --show-toplevel")[1]
14+
end
15+
16+
--- Get root directory of git project or fallback to current directory
17+
---@return string|nil
18+
function M.get_root_directory()
19+
if M.is_git_repo() then
20+
return M.get_git_root()
21+
end
22+
23+
return vim.fn.getcwd()
24+
end
25+
26+
return M

0 commit comments

Comments
 (0)