css.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. local M = {}
  2. M.config = function()
  3. -- TODO: implement config for language
  4. return "No config available!"
  5. end
  6. M.format = function()
  7. vim.cmd "let proj = FindRootDirectory()"
  8. local root_dir = vim.api.nvim_get_var "proj"
  9. -- use the global prettier if you didn't find the local one
  10. local prettier_instance = root_dir .. "/node_modules/.bin/prettier"
  11. if vim.fn.executable(prettier_instance) ~= 1 then
  12. prettier_instance = O.lang.tsserver.formatter.exe
  13. end
  14. local ft = vim.bo.filetype
  15. O.formatters.filetype[ft] = {
  16. function()
  17. local args = { "--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) }
  18. -- TODO: O.lang.[ft].formatter.args
  19. local extend_args = O.lang.css.formatter.args
  20. for i = 1, #extend_args do
  21. table.insert(args, extend_args[i])
  22. end
  23. return {
  24. exe = prettier_instance,
  25. args = args,
  26. stdin = true,
  27. }
  28. end,
  29. }
  30. require("formatter.config").set_defaults {
  31. logging = false,
  32. filetype = O.formatters.filetype,
  33. }
  34. end
  35. M.lint = function()
  36. -- TODO: implement linters (if applicable)
  37. return "No linters configured!"
  38. end
  39. M.lsp = function()
  40. if not require("lv-utils").check_lsp_client_active "cssls" then
  41. local capabilities = vim.lsp.protocol.make_client_capabilities()
  42. capabilities.textDocument.completion.completionItem.snippetSupport = true
  43. -- npm install -g vscode-css-languageserver-bin
  44. require("lspconfig").cssls.setup {
  45. cmd = {
  46. "node",
  47. DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js",
  48. "--stdio",
  49. },
  50. on_attach = require("lsp").common_on_attach,
  51. capabilities = capabilities,
  52. }
  53. end
  54. end
  55. M.dap = function()
  56. -- TODO: implement dap
  57. return "No DAP configured!"
  58. end
  59. return M