php.lua 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. local M = {}
  2. M.config = function()
  3. O.lang.php = {
  4. format = {
  5. format = {
  6. default = "psr12",
  7. },
  8. },
  9. environment = {
  10. php_version = "7.4",
  11. },
  12. diagnostics = {
  13. virtual_text = { spacing = 0, prefix = "" },
  14. signs = true,
  15. underline = true,
  16. },
  17. filetypes = { "php", "phtml" },
  18. formatter = {
  19. exe = "phpcbf",
  20. args = { "--standard=PSR12", vim.api.nvim_buf_get_name(0) },
  21. stdin = false,
  22. },
  23. }
  24. end
  25. M.format = function()
  26. O.formatters.filetype["php"] = {
  27. function()
  28. return {
  29. exe = O.lang.php.formatter.exe,
  30. args = O.lang.php.formatter.args,
  31. stdin = not (O.lang.php.formatter.stdin ~= nil),
  32. }
  33. end,
  34. }
  35. require("formatter.config").set_defaults {
  36. logging = false,
  37. filetype = O.formatters.filetype,
  38. }
  39. end
  40. M.lint = function()
  41. -- TODO: implement linters (if applicable)
  42. return "No linters configured!"
  43. end
  44. M.lsp = function()
  45. if require("lv-utils").check_lsp_client_active "intelephense" then
  46. return
  47. end
  48. require("lspconfig").intelephense.setup {
  49. cmd = { DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", "--stdio" },
  50. on_attach = require("lsp").common_on_attach,
  51. handlers = {
  52. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  53. virtual_text = O.lang.php.diagnostics.virtual_text,
  54. signs = O.lang.php.diagnostics.signs,
  55. underline = O.lang.php.diagnostics.underline,
  56. update_in_insert = true,
  57. }),
  58. },
  59. filetypes = O.lang.php.filetypes,
  60. settings = {
  61. intelephense = {
  62. format = {
  63. braces = O.lang.php.format.braces,
  64. },
  65. environment = {
  66. phpVersion = O.lang.php.environment.php_version,
  67. },
  68. },
  69. },
  70. }
  71. end
  72. M.dap = function()
  73. -- TODO: implement dap
  74. return "No DAP configured!"
  75. end
  76. return M