default-config.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. CONFIG_PATH = os.getenv "HOME" .. "/.local/share/lunarvim/lvim"
  2. DATA_PATH = vim.fn.stdpath "data"
  3. CACHE_PATH = vim.fn.stdpath "cache"
  4. TERMINAL = vim.fn.expand "$TERMINAL"
  5. USER = vim.fn.expand "$USER"
  6. lvim = {
  7. leader = "space",
  8. colorscheme = "spacegray",
  9. line_wrap_cursor_movement = true,
  10. transparent_window = false,
  11. format_on_save = true,
  12. vsnip_dir = os.getenv "HOME" .. "/.config/snippets",
  13. database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 },
  14. keys = {},
  15. -- TODO why do we need this?
  16. builtin = {
  17. lspinstall = {},
  18. telescope = {},
  19. compe = {},
  20. autopairs = {},
  21. treesitter = {},
  22. nvimtree = {},
  23. gitsigns = {},
  24. which_key = {},
  25. comment = {},
  26. rooter = {},
  27. galaxyline = {},
  28. bufferline = {},
  29. dap = {},
  30. dashboard = {},
  31. terminal = {},
  32. },
  33. lsp = {
  34. diagnostics = {
  35. virtual_text = {
  36. prefix = "",
  37. spacing = 0,
  38. },
  39. signs = true,
  40. underline = true,
  41. },
  42. document_highlight = true,
  43. popup_border = "single",
  44. default_keybinds = true,
  45. on_attach_callback = nil,
  46. },
  47. plugins = {
  48. -- use lv-config.lua for this not put here
  49. },
  50. autocommands = {
  51. { "FileType", "qf", "set nobuflisted" },
  52. },
  53. }
  54. local schemas = nil
  55. local common_on_attach = require("lsp").common_on_attach
  56. local common_capabilities = require("lsp").common_capabilities()
  57. local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls")
  58. if status_ok then
  59. schemas = jsonls_settings.get_default_schemas()
  60. end
  61. -- TODO move all of this into lang specific files, only require when using
  62. lvim.lang = {
  63. c = {
  64. formatter = {
  65. exe = "clang_format",
  66. args = {},
  67. stdin = true,
  68. },
  69. linters = {
  70. "clangtidy",
  71. },
  72. lsp = {
  73. provider = "clangd",
  74. setup = {
  75. cmd = {
  76. DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd",
  77. "--background-index",
  78. "--header-insertion=never",
  79. "--cross-file-rename",
  80. "--clang-tidy",
  81. "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*",
  82. },
  83. on_attach = common_on_attach,
  84. capabilities = common_capabilities,
  85. },
  86. },
  87. },
  88. cpp = {
  89. formatter = {
  90. exe = "clang_format",
  91. args = {},
  92. stdin = true,
  93. },
  94. linters = {
  95. "cppcheck",
  96. "clangtidy",
  97. },
  98. lsp = {
  99. provider = "clangd",
  100. setup = {
  101. cmd = {
  102. DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd",
  103. "--background-index",
  104. "--header-insertion=never",
  105. "--cross-file-rename",
  106. "--clang-tidy",
  107. "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*",
  108. },
  109. on_attach = common_on_attach,
  110. capabilities = common_capabilities,
  111. },
  112. },
  113. },
  114. csharp = {
  115. lsp = {
  116. provider = "omnisharp",
  117. setup = {
  118. cmd = {
  119. DATA_PATH .. "/lspinstall/csharp/omnisharp/run",
  120. "--stdio",
  121. },
  122. on_attach = common_on_attach,
  123. capabilities = common_capabilities,
  124. },
  125. },
  126. },
  127. cmake = {
  128. formatter = {
  129. exe = "clang-format",
  130. args = {},
  131. },
  132. lsp = {
  133. provider = "cmake",
  134. setup = {
  135. cmd = {
  136. DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server",
  137. "--stdio",
  138. },
  139. on_attach = common_on_attach,
  140. capabilities = common_capabilities,
  141. },
  142. },
  143. },
  144. clojure = {
  145. lsp = {
  146. provider = "clojure_lsp",
  147. setup = {
  148. cmd = {
  149. DATA_PATH .. "/lspinstall/clojure/clojure-lsp",
  150. "--stdio",
  151. },
  152. on_attach = common_on_attach,
  153. capabilities = common_capabilities,
  154. },
  155. },
  156. },
  157. css = {
  158. formatter = {
  159. exe = "prettier",
  160. args = {},
  161. },
  162. lsp = {
  163. provider = "cssls",
  164. setup = {
  165. cmd = {
  166. "node",
  167. DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js",
  168. "--stdio",
  169. },
  170. on_attach = common_on_attach,
  171. capabilities = common_capabilities,
  172. },
  173. },
  174. },
  175. dart = {
  176. lsp = {
  177. provider = "dartls",
  178. setup = {
  179. cmd = {
  180. "dart",
  181. "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot",
  182. "--lsp",
  183. },
  184. on_attach = common_on_attach,
  185. capabilities = common_capabilities,
  186. },
  187. },
  188. formatter = {
  189. exe = "dart",
  190. args = { "format" },
  191. stdin = true,
  192. },
  193. },
  194. docker = {
  195. lsp = {
  196. provider = "dockerls",
  197. setup = {
  198. cmd = {
  199. DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver",
  200. "--stdio",
  201. },
  202. on_attach = common_on_attach,
  203. capabilities = common_capabilities,
  204. },
  205. },
  206. },
  207. elixir = {
  208. formatter = {
  209. exe = "mix",
  210. args = { "format" },
  211. stdin = true,
  212. },
  213. lsp = {
  214. provider = "elixirls",
  215. setup = {
  216. cmd = {
  217. DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh",
  218. },
  219. on_attach = common_on_attach,
  220. capabilities = common_capabilities,
  221. },
  222. },
  223. },
  224. elm = {
  225. lsp = {
  226. provider = "elmls",
  227. setup = {
  228. cmd = {
  229. DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server",
  230. },
  231. on_attach = common_on_attach,
  232. init_options = {
  233. elmAnalyseTrigger = "change",
  234. elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format",
  235. elmPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/",
  236. elmTestPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-test",
  237. },
  238. },
  239. },
  240. },
  241. erlang = {
  242. lsp = {
  243. provider = "erlangls",
  244. setup = {
  245. cmd = {
  246. "erlang_ls",
  247. },
  248. on_attach = common_on_attach,
  249. capabilities = common_capabilities,
  250. },
  251. },
  252. },
  253. emmet = { active = false },
  254. go = {
  255. formatter = {
  256. exe = "gofmt",
  257. args = {},
  258. stdin = true,
  259. },
  260. linters = {
  261. "golangcilint",
  262. "revive",
  263. },
  264. lsp = {
  265. provider = "gopls",
  266. setup = {
  267. cmd = {
  268. DATA_PATH .. "/lspinstall/go/gopls",
  269. },
  270. on_attach = common_on_attach,
  271. capabilities = common_capabilities,
  272. },
  273. },
  274. },
  275. graphql = {
  276. lsp = {
  277. provider = "graphql",
  278. setup = {
  279. cmd = {
  280. "graphql-lsp",
  281. "server",
  282. "-m",
  283. "stream",
  284. },
  285. on_attach = common_on_attach,
  286. capabilities = common_capabilities,
  287. },
  288. },
  289. },
  290. html = {
  291. linters = {
  292. "tidy",
  293. -- https://docs.errata.ai/vale/scoping#html
  294. "vale",
  295. },
  296. lsp = {
  297. provider = "html",
  298. setup = {
  299. cmd = {
  300. "node",
  301. DATA_PATH .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js",
  302. "--stdio",
  303. },
  304. on_attach = common_on_attach,
  305. capabilities = common_capabilities,
  306. },
  307. },
  308. },
  309. java = {
  310. formatter = {
  311. exe = "prettier",
  312. args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0) },
  313. },
  314. lsp = {
  315. provider = "jdtls",
  316. setup = {
  317. cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" },
  318. on_attach = common_on_attach,
  319. capabilities = common_capabilities,
  320. },
  321. },
  322. },
  323. json = {
  324. formatter = {
  325. exe = "python",
  326. args = { "-m", "json.tool" },
  327. stdin = true,
  328. },
  329. lsp = {
  330. provider = "jsonls",
  331. setup = {
  332. cmd = {
  333. "node",
  334. DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js",
  335. "--stdio",
  336. },
  337. on_attach = common_on_attach,
  338. capabilities = common_capabilities,
  339. settings = {
  340. json = {
  341. schemas = schemas,
  342. -- = {
  343. -- {
  344. -- fileMatch = { "package.json" },
  345. -- url = "https://json.schemastore.org/package.json",
  346. -- },
  347. -- },
  348. },
  349. },
  350. commands = {
  351. Format = {
  352. function()
  353. vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 })
  354. end,
  355. },
  356. },
  357. },
  358. },
  359. },
  360. julia = {
  361. lsp = {
  362. provider = "julials",
  363. setup = {
  364. {
  365. "julia",
  366. "--startup-file=no",
  367. "--history-file=no",
  368. -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl",
  369. CONFIG_PATH .. "/utils/julia/run.jl",
  370. },
  371. on_attach = common_on_attach,
  372. capabilities = common_capabilities,
  373. },
  374. },
  375. },
  376. kotlin = {
  377. lsp = {
  378. provider = "kotlin_language_server",
  379. setup = {
  380. cmd = {
  381. DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server",
  382. },
  383. on_attach = common_on_attach,
  384. root_dir = function(fname)
  385. local util = require "lspconfig/util"
  386. local root_files = {
  387. "settings.gradle", -- Gradle (multi-project)
  388. "settings.gradle.kts", -- Gradle (multi-project)
  389. "build.xml", -- Ant
  390. "pom.xml", -- Maven
  391. }
  392. local fallback_root_files = {
  393. "build.gradle", -- Gradle
  394. "build.gradle.kts", -- Gradle
  395. }
  396. return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname)
  397. end,
  398. },
  399. },
  400. },
  401. lua = {
  402. formatter = {
  403. exe = "stylua",
  404. args = {},
  405. },
  406. linters = { "luacheck" },
  407. lsp = {
  408. provider = "sumneko_lua",
  409. setup = {
  410. cmd = {
  411. DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server",
  412. "-E",
  413. DATA_PATH .. "/lspinstall/lua/main.lua",
  414. },
  415. on_attach = common_on_attach,
  416. settings = {
  417. Lua = {
  418. runtime = {
  419. -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
  420. version = "LuaJIT",
  421. -- Setup your lua path
  422. path = vim.split(package.path, ";"),
  423. },
  424. diagnostics = {
  425. -- Get the language server to recognize the `vim` global
  426. globals = { "vim", "O" },
  427. },
  428. workspace = {
  429. -- Make the server aware of Neovim runtime files
  430. library = {
  431. [vim.fn.expand "~/.local/share/lunarvim/lvim/lua"] = true,
  432. [vim.fn.expand "$VIMRUNTIME/lua"] = true,
  433. [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
  434. },
  435. maxPreload = 100000,
  436. preloadFileSize = 1000,
  437. },
  438. },
  439. },
  440. },
  441. },
  442. },
  443. php = {
  444. formatter = {
  445. exe = "phpcbf",
  446. args = { "--standard=PSR12", vim.api.nvim_buf_get_name(0) },
  447. },
  448. linters = {},
  449. lsp = {
  450. provider = "intelephense",
  451. setup = {
  452. cmd = {
  453. DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense",
  454. "--stdio",
  455. },
  456. on_attach = common_on_attach,
  457. filetypes = { "php", "phtml" },
  458. settings = {
  459. intelephense = {
  460. environment = {
  461. phpVersion = "7.4",
  462. },
  463. },
  464. },
  465. },
  466. },
  467. },
  468. javascript = {
  469. -- @usage can be prettier or eslint
  470. formatter = {
  471. exe = "prettier",
  472. args = {},
  473. },
  474. linters = {
  475. "eslint",
  476. },
  477. lsp = {
  478. provider = "tsserver",
  479. setup = {
  480. cmd = {
  481. -- TODO:
  482. DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server",
  483. "--stdio",
  484. },
  485. on_attach = require("lsp").common_on_attach,
  486. capabilities = require("lsp").common_capabilities(),
  487. },
  488. },
  489. },
  490. python = {
  491. -- @usage can be flake8 or yapf
  492. formatter = {
  493. exe = "black",
  494. args = {},
  495. },
  496. linters = {
  497. "flake8",
  498. "pylint",
  499. "mypy",
  500. },
  501. lsp = {
  502. provider = "pyright",
  503. setup = {
  504. cmd = {
  505. DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
  506. "--stdio",
  507. },
  508. on_attach = common_on_attach,
  509. capabilities = common_capabilities,
  510. },
  511. },
  512. },
  513. -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")'
  514. -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")'
  515. r = {
  516. formatter = {
  517. exe = "R",
  518. args = {
  519. "--slave",
  520. "--no-restore",
  521. "--no-save",
  522. '-e "formatR::tidy_source(text=readr::read_file(file(\\"stdin\\")), arrow=FALSE)"',
  523. },
  524. stdin = true,
  525. },
  526. lsp = {
  527. provider = "r_language_server",
  528. setup = {
  529. cmd = {
  530. "R",
  531. "--slave",
  532. "-e",
  533. "languageserver::run()",
  534. },
  535. on_attach = common_on_attach,
  536. capabilities = common_capabilities,
  537. },
  538. },
  539. },
  540. ruby = {
  541. formatter = {
  542. exe = "rufo",
  543. args = { "-x" },
  544. stdin = true,
  545. },
  546. linters = { "ruby" },
  547. lsp = {
  548. provider = "solargraph",
  549. setup = {
  550. cmd = {
  551. DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph",
  552. "stdio",
  553. },
  554. on_attach = common_on_attach,
  555. capabilities = common_capabilities,
  556. },
  557. },
  558. },
  559. rust = {
  560. formatter = {
  561. exe = "rustfmt",
  562. args = { "--emit=stdout", "--edition=2018" },
  563. stdin = true,
  564. },
  565. lsp = {
  566. provider = "rust_analyzer",
  567. setup = {
  568. cmd = {
  569. DATA_PATH .. "/lspinstall/rust/rust-analyzer",
  570. },
  571. on_attach = common_on_attach,
  572. capabilities = common_capabilities,
  573. },
  574. },
  575. },
  576. sh = {
  577. -- @usage can be 'shfmt'
  578. formatter = {
  579. exe = "shfmt",
  580. args = {},
  581. },
  582. -- @usage can be 'shellcheck'
  583. linters = { "shellcheck" },
  584. lsp = {
  585. provider = "bashls",
  586. setup = {
  587. cmd = {
  588. DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server",
  589. "start",
  590. },
  591. on_attach = common_on_attach,
  592. capabilities = common_capabilities,
  593. },
  594. },
  595. },
  596. svelte = {
  597. lsp = {
  598. provider = "svelte",
  599. setup = {
  600. cmd = {
  601. DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver",
  602. "--stdio",
  603. },
  604. on_attach = common_on_attach,
  605. capabilities = common_capabilities,
  606. },
  607. },
  608. },
  609. swift = {
  610. formatter = {
  611. exe = "swiftformat",
  612. args = {},
  613. stdin = true,
  614. },
  615. lsp = {
  616. provider = "sourcekit",
  617. setup = {
  618. cmd = {
  619. "xcrun",
  620. "sourcekit-lsp",
  621. },
  622. on_attach = common_on_attach,
  623. capabilities = common_capabilities,
  624. },
  625. },
  626. },
  627. tailwindcss = {
  628. active = false,
  629. filetypes = {
  630. "html",
  631. "css",
  632. "scss",
  633. "javascript",
  634. "javascriptreact",
  635. "typescript",
  636. "typescriptreact",
  637. },
  638. },
  639. terraform = {
  640. formatter = {
  641. exe = "terraform",
  642. args = { "fmt" },
  643. stdin = false,
  644. },
  645. lsp = {
  646. provider = "terraformls",
  647. setup = {
  648. cmd = {
  649. DATA_PATH .. "/lspinstall/terraform/terraform-ls",
  650. "serve",
  651. },
  652. on_attach = common_on_attach,
  653. capabilities = common_capabilities,
  654. },
  655. },
  656. },
  657. vim = {
  658. linters = { "vint" },
  659. lsp = {
  660. provider = "vimls",
  661. setup = {
  662. cmd = {
  663. DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server",
  664. "--stdio",
  665. },
  666. on_attach = common_on_attach,
  667. capabilities = common_capabilities,
  668. },
  669. },
  670. },
  671. vue = {
  672. formatter = {
  673. exe = "prettier",
  674. args = {
  675. "--stdin-filepath",
  676. "${FILEPATH}",
  677. },
  678. stdin = true,
  679. },
  680. lsp = {
  681. provider = "vetur",
  682. setup = {
  683. cmd = {
  684. DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls",
  685. },
  686. on_attach = common_on_attach,
  687. capabilities = common_capabilities,
  688. },
  689. },
  690. },
  691. yaml = {
  692. formatter = {
  693. exe = "prettier",
  694. args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
  695. stdin = true,
  696. },
  697. lsp = {
  698. provider = "yamlls",
  699. setup = {
  700. cmd = {
  701. DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server",
  702. "--stdio",
  703. },
  704. on_attach = common_on_attach,
  705. capabilities = common_capabilities,
  706. },
  707. },
  708. },
  709. zig = {
  710. formatter = {
  711. exe = "zig",
  712. args = { "fmt" },
  713. stdin = false,
  714. },
  715. lsp = {
  716. provider = "zls",
  717. setup = {
  718. cmd = {
  719. "zls",
  720. },
  721. on_attach = common_on_attach,
  722. capabilities = common_capabilities,
  723. },
  724. },
  725. },
  726. }
  727. require("core.which-key").config()
  728. require "core.status_colors"
  729. require("core.gitsigns").config()
  730. require("core.compe").config()
  731. require("core.dashboard").config()
  732. require("core.dap").config()
  733. require("core.terminal").config()
  734. require("core.telescope").config()
  735. require("core.treesitter").config()
  736. require("core.nvimtree").config()