-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinit.lua
More file actions
97 lines (87 loc) · 2.69 KB
/
init.lua
File metadata and controls
97 lines (87 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require "config.options"
-- Load project setting if available, e.g: .nvim-config.lua
-- This file is not tracked by git
-- It can be used to set project specific settings
local project_setting = vim.fn.getcwd() .. "/.nvim-config.lua"
-- Check if the file exists and load it
if vim.loop.fs_stat(project_setting) then
-- Read the file and run it with pcall to catch any errors
local ok, err = pcall(dofile, project_setting)
if not ok then
vim.notify("Error loading project setting: " .. err, vim.log.levels.ERROR)
end
end
require "config.autocmds"
require "config.lazy"
require "config.keymaps"
require "config.project"
-- Only load the theme if not in VSCode
if vim.g.vscode then
-- Trigger vscode keymap
local pattern = "NvimIdeKeymaps"
vim.api.nvim_exec_autocmds("User", { pattern = pattern, modeline = false })
else
-- Load the theme
local theme = require "config.theme"
theme.setup()
theme.apply()
local ts_server = vim.g.lsp_typescript_server or "ts_ls" -- "ts_ls" or "vtsls" for TypeScript
-- Enable LSP servers per filetype (Neovim 0.11+)
local lsp_by_ft = {
lua = { "lua_ls" },
json = { "json", "biome" },
jsonc = { "json", "biome" },
json5 = { "json", "biome" },
python = { "basedpyright", "ruff" },
go = { "gopls" },
gomod = { "gopls" },
gowork = { "gopls" },
gotmpl = { "gopls" },
rust = { "rust-analyzer" },
javascript = { ts_server, "biome" },
javascriptreact = { ts_server, "biome" },
typescript = { ts_server, "biome" },
typescriptreact = { ts_server, "biome" },
html = { "tailwindcss" },
css = { "tailwindcss" },
scss = { "tailwindcss" },
sass = { "tailwindcss" },
less = { "tailwindcss" },
postcss = { "tailwindcss" },
}
local enabled_lsp = {}
local on_demands = vim.g.lsp_on_demands or {}
local js_ts_filetypes = {
javascript = true,
javascriptreact = true,
typescript = true,
typescriptreact = true,
json = true,
jsonc = true,
json5 = true,
}
local function enable_lsp(servers)
if not servers or #servers == 0 then
return
end
for _, server in ipairs(servers) do
if not enabled_lsp[server] then
enabled_lsp[server] = true
vim.lsp.enable(server)
end
end
end
vim.api.nvim_create_autocmd("FileType", {
group = vim.api.nvim_create_augroup("my_nvim_lsp_by_ft", { clear = true }),
callback = function(event)
local filetype = vim.bo[event.buf].filetype
local servers = lsp_by_ft[filetype] or {}
if js_ts_filetypes[filetype] and #on_demands > 0 then
for _, server in ipairs(on_demands) do
table.insert(servers, server)
end
end
enable_lsp(servers)
end,
})
end