php.lua 2.0 KB

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