diff --git a/init.lua b/init.lua index fd5ad0c..59cb57d 100644 --- a/init.lua +++ b/init.lua @@ -401,3 +401,4 @@ require('custom.mason') require('custom.bufferline') require('custom.kulala') require('custom.rainbow') +require('custom.none-ls') diff --git a/lua/custom/lspconfig.lua b/lua/custom/lspconfig.lua index e7fdfe7..e5d9e26 100644 --- a/lua/custom/lspconfig.lua +++ b/lua/custom/lspconfig.lua @@ -12,6 +12,17 @@ end local keymap = vim.keymap -- for conciseness +-- smart format with null-ls if aviable +local function smart_format() + vim.lsp.buf.format({ + filter = function(client) + if vim.bo.filetype == "rust" then + return client.name == "rust_analyzer" + end + return client.name == "null-ls" + end, + }) +end ---------- border >------------------------------ local orig_floating_preview = vim.lsp.util.open_floating_preview vim.lsp.util.open_floating_preview = function(contents, syntax, opts, ...) @@ -31,7 +42,8 @@ local on_attach = function(_, bufnr) -- keymap.set("n", "gr", "lua vim.lsp.buf.references()", opts) keymap.set("n", "gD", "lua vim.lsp.buf.declaration()", opts) -- got to declaration keymap.set("n", "gd", "lua vim.lsp.buf.definition()", opts) -- see definition and make edits in window keymap.set("n", "gi", "lua vim.lsp.buf.implementation()", opts) -- go to implementation - keymap.set("n", "l", "lua vim.lsp.buf.format()", opts) -- format code + -- keymap.set("n", "l", "lua vim.lsp.buf.format()", opts) -- format code + keymap.set("n", "l", smart_format, opts) -- format code keymap.set("n", "rn", "lua vim.lsp.buf.rename()", opts) -- format code -- keymap.set("n", "ca", "lua vim.lsp.buf.code_action()", opts) -- see available code actions -- keymap.set("n", "ed", "Telescope diagnostics", opts) -- jump to previous diagnostic in buffer @@ -161,6 +173,12 @@ lspconfig["lua_ls"].setup({ filetypes = { "lua" }, }) +local util = require("lspconfig.util") + +local fallback_root_dir = function(fname) + return util.root_pattern("composer.json", ".git")(fname) or util.path.dirname(fname) +end + lspconfig["phpactor"].setup({ on_attach = on_attach, capabilities = capabilities, @@ -169,12 +187,47 @@ lspconfig["phpactor"].setup({ ["language_server_psalm.enabled"] = false, }, filetypes = { "php" }, + root_dir = fallback_root_dir, }) lspconfig["intelephense"].setup({ capabilities = capabilities, on_attach = on_attach, filetypes = { "php" }, + init_options = { + licenceKey = vim.fn.readfile(vim.fn.expand("$HOME/.config/intelephense/license.txt"))[1], + }, + root_dir = fallback_root_dir, + settings = { + intelephense = { + -- ✅ Enable property inference (Pro) + telemetry = { enabled = false }, -- optional, privacy + files = { + maxSize = 5000000, -- increase if needed + associations = { "**/*.php" }, + }, + -- environment = { + -- includePaths = { + -- "/path/to/your/stubs", -- ⬅️ Your custom stub folder + -- }, + -- }, + completion = { + fullyQualifyGlobalConstantsAndFunctions = false, + triggerParameterHints = true, + maxItems = 100, + }, + -- enables smarter inference + phpdoc = { + enabled = true, + }, + diagnostics = { + enable = true, + }, + format = { + enable = false, -- you’re using `phpcbf` anyway + }, + }, + }, }) lspconfig["slint_lsp"].setup({ diff --git a/lua/custom/none-ls.lua b/lua/custom/none-ls.lua new file mode 100644 index 0000000..e71fdcd --- /dev/null +++ b/lua/custom/none-ls.lua @@ -0,0 +1,11 @@ +local null_ls = require("null-ls") + +null_ls.setup({ + sources = { + null_ls.builtins.formatting.phpcbf.with({ + command = "phpcbf", -- or full path if not in PATH + extra_args = { "--standard=PSR12" }, + }), + }, + on_attach = on_attach, +}) diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index 2e15d08..4266eaa 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -145,7 +145,9 @@ return { end persisted.setup(opts) end, - } + }, + + 'nvimtools/none-ls.nvim', -- { -- "folke/persistence.nvim", -- event = "BufReadPre", -- this will only start session saving when an actual file was opened