php.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. tempfile_prefix = ".formatter",
  33. }
  34. end,
  35. }
  36. require("formatter.config").set_defaults {
  37. logging = false,
  38. filetype = O.formatters.filetype,
  39. }
  40. end
  41. M.lint = function()
  42. -- TODO: implement linters (if applicable)
  43. return "No linters configured!"
  44. end
  45. M.lsp = function()
  46. if require("lv-utils").check_lsp_client_active "intelephense" then
  47. return
  48. end
  49. require("lspconfig").intelephense.setup {
  50. cmd = { DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", "--stdio" },
  51. on_attach = require("lsp").common_on_attach,
  52. handlers = {
  53. ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
  54. virtual_text = O.lang.php.diagnostics.virtual_text,
  55. signs = O.lang.php.diagnostics.signs,
  56. underline = O.lang.php.diagnostics.underline,
  57. update_in_insert = true,
  58. }),
  59. },
  60. filetypes = O.lang.php.filetypes,
  61. settings = {
  62. intelephense = {
  63. format = {
  64. braces = O.lang.php.format.braces,
  65. },
  66. environment = {
  67. phpVersion = O.lang.php.environment.php_version,
  68. },
  69. },
  70. },
  71. }
  72. end
  73. M.dap = function()
  74. -- TODO: implement dap
  75. return "No DAP configured!"
  76. end
  77. return M