Repository: junnplus/nvim-lsp-setup
Branch: main
Commit: f3acd127ca0f
Files: 7
Total size: 28.9 KB
Directory structure:
gitextract_gjggy8a7/
├── .github/
│ └── FUNDING.yml
├── .luarc.json
├── LICENSE
├── README.md
└── lua/
└── lsp-setup/
├── init.lua
├── inlay_hints.lua
└── utils.lua
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/FUNDING.yml
================================================
# These are supported funding model platforms
github: [Junnplus]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
================================================
FILE: .luarc.json
================================================
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"Lua.format.defaultConfig": {
"quote_style": "single"
}
}
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================
# lsp-setup.nvim
A simple wrapper for [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) and [mason-lspconfig](https://github.com/mason-org/mason-lspconfig.nvim) (optional) to easily setup LSP servers.
## Requirements
- Neovim >= 0.11
- nvim-lspconfig >= 2.0.0
- mason.nvim & mason-lspconfig.nvim (optional)
## Installation
### [lazy.nvim](https://github.com/folke/lazy.nvim)
```
{
'junnplus/lsp-setup.nvim',
dependencies = {
'neovim/nvim-lspconfig',
'mason-org/mason.nvim', -- optional
'mason-org/mason-lspconfig.nvim', -- optional
},
---@type LspSetup.Options
opts = {
servers = {
pylsp = {},
clangd = {}
}
}
}
```
## Usage
```lua
require('lsp-setup').setup({
servers = {
pylsp = {},
clangd = {}
}
})
```
You can replace `pylsp` with the LSP server name you need, see [available LSPs](https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md).
Also support installing custom versions of LSP servers (requires mason and mason-lspconfig), for example:
```lua
require('lsp-setup').setup({
servers = {
['rust_analyzer@nightly'] = {}
}
})
```
LSP servers returns a table will automatically setup server process using lspconfig. You can also pass a nil function to setup the server manually, see [Integrations/rust-tools.nvim](#rust-toolsnvim).
### Inlay hints
```lua
require('lsp-setup').setup({
inlay_hints = {
enabled = true,
}
})
```
<details>
<summary>typescript-language-server</summary>
https://github.com/typescript-language-server/typescript-language-server#inlay-hints-textdocumentinlayhint
```lua
require('lsp-setup').setup({
servers = {
tsserver = {
settings = {
typescript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayVariableTypeHintsWhenTypeMatchesName = false,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
}
}
}
}
}
})
```
</details>
<details>
<summary>vue-language-server</summary>
```lua
require('lsp-setup').setup({
servers = {
volar = {
settings = {
typescript = {
inlayHints = {
enumMemberValues = {
enabled = true,
},
functionLikeReturnTypes = {
enabled = true,
},
propertyDeclarationTypes = {
enabled = true,
},
parameterTypes = {
enabled = true,
suppressWhenArgumentMatchesName = true,
},
variableTypes = {
enabled = true,
}
}
}
}
}
}
})
```
</details>
<details>
<summary>gopls</summary>
https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.md
```lua
require('lsp-setup').setup({
servers = {
gopls = {
settings = {
gopls = {
hints = {
rangeVariableTypes = true,
parameterNames = true,
constantValues = true,
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
functionTypeParameters = true,
}
}
}
}
}
})
```
</details>
<details>
<summary>rust-analyzer</summary>
https://github.com/simrat39/rust-tools.nvim/wiki/Server-Configuration-Schema
```lua
require('lsp-setup').setup({
servers = {
rust_analyzer = {
settings = {
['rust-analyzer'] = {
inlayHints = {
bindingModeHints = {
enable = false,
},
chainingHints = {
enable = true,
},
closingBraceHints = {
enable = true,
minLines = 25,
},
closureReturnTypeHints = {
enable = 'never',
},
lifetimeElisionHints = {
enable = 'never',
useParameterNames = false,
},
maxLength = 25,
parameterHints = {
enable = true,
},
reborrowHints = {
enable = 'never',
},
renderColons = true,
typeHints = {
enable = true,
hideClosureInitialization = false,
hideNamedConstructor = false,
}
}
}
}
}
}
})
```
</details>
<details>
<summary>
lua-language-server
</summary>
https://github.com/LuaLS/lua-language-server/wiki/Settings#hint
```lua
require('lsp-setup').setup({
servers = {
lua_ls = {
settings = {
Lua = {
hint = {
enable = false,
arrayIndex = "Auto",
await = true,
paramName = "All",
paramType = true,
semicolon = "SameLine",
setType = false,
},
},
},
},
}
})
```
</details>
<details>
<summary>zls</summary>
https://github.com/zigtools/zls
```lua
require('lsp-setup').setup({
servers = {
zls = {
settings = {
zls = {
enable_inlay_hints = true,
inlay_hints_show_builtin = true,
inlay_hints_exclude_single_argument = true,
inlay_hints_hide_redundant_param_names = false,
inlay_hints_hide_redundant_param_names_last_token = false,
}
}
},
}
})
```
</details>
### Setup structure
```lua
require('lsp-setup').setup({
-- Default mappings
-- gD = { cmd = vim.lsp.buf.declaration, opts = { desc = 'Go To Declaration' } },
-- gd = { cmd = vim.lsp.buf.definition, opts = { desc = 'Go To Definition' } },
-- gi = { cmd = vim.lsp.buf.implementation, opts = { desc = 'Go To Implementation' } },
-- gr = { cmd = vim.lsp.buf.references, opts = { desc = 'Go To References' } },
-- K = { cmd = vim.lsp.buf.hover, opts = { desc = 'Hover' } },
-- ['<C-k>'] = { cmd = vim.lsp.buf.signature_help, opts = { desc = 'Show Signature Help' } },
-- ['<space>rn'] = { cmd = vim.lsp.buf.rename, opts = { desc = 'Rename' } },
-- ['<space>ca'] = { cmd = vim.lsp.buf.code_action, opts = { desc = 'Code Action' } },
-- ['<space>f'] = { cmd = vim.lsp.buf.formatting, opts = { desc = 'Format' } },
-- ['<space>e'] = { cmd = vim.diagnostic.open_float, opts = { desc = 'Show Diagnostics' } },
-- ['[d'] = { cmd = function() vim.diagnostic.jump({ count = -1, float = true }) end, opts = { desc = 'Prev Diagnostic' } },
-- [']d'] = { cmd = function() vim.diagnostic.jump({ count = 1, float = true }) end, opts = { desc = 'Next Diagnostic' } },
default_mappings = true,
-- Custom mappings, will overwrite the default mappings for the same key
-- Example mappings for telescope pickers:
-- gd = 'lua require"telescope.builtin".lsp_definitions()',
-- gi = 'lua require"telescope.builtin".lsp_implementations()',
-- gr = 'lua require"telescope.builtin".lsp_references()',
mappings = {},
-- Global on_attach
on_attach = function(client, bufnr)
-- Support custom the on_attach function for global
-- Formatting on save as default
require('lsp-setup.utils').format_on_save(client)
end,
-- Global capabilities
capabilities = vim.lsp.protocol.make_client_capabilities(),
-- Configuration of LSP servers
servers = {
-- Install LSP servers automatically (requires mason and mason-lspconfig)
-- LSP server configuration please see: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
-- pylsp = {},
-- rust_analyzer = {
-- settings = {
-- ['rust-analyzer'] = {
-- cargo = {
-- loadOutDirsFromCheck = true,
-- },
-- procMacro = {
-- enable = true,
-- },
-- },
-- },
-- },
},
-- Configuration of LSP inlay hints
inlay_hints = {
enabled = false,
highlight = 'Comment',
}
})
```
## Integrations
### [cmp-nvim-lsp](https://github.com/hrsh7th/cmp-nvim-lsp) or [coq_nvim](https://github.com/ms-jpq/coq_nvim) or [blink.cmp](https://github.com/Saghen/blink.cmp)
If installed, will auto advertise capabilities to LSP servers.
### [lazydev](https://github.com/folke/lazydev.nvim)
```lua
-- Setup lua_ls with lazydev
require('lazydev').setup()
require('lsp-setup').setup({
servers = {
lua_ls = {}
}
})
```
### [rust-tools.nvim](https://github.com/simrat39/rust-tools.nvim)
```lua
require('lsp-setup').setup({
servers = {
rust_analyzer = function()
require('rust-tools').setup({
server = {
settings = {
['rust-analyzer'] = {
cargo = {
loadOutDirsFromCheck = true,
},
procMacro = {
enable = true,
},
},
},
},
})
-- no need to return anything
end,
}
})
```
## Contributing
Bug reports and feature requests are welcome! PRs are doubly welcome!
================================================
FILE: lua/lsp-setup/init.lua
================================================
local utils = require('lsp-setup.utils')
local inlay_hints = require('lsp-setup.inlay_hints')
---@param opts LspSetup.Options
---@return table<string, LspSetup.ServerConfig>
local function lsp_servers(opts)
local servers = {}
for server, config in pairs(opts.servers) do
local server_name, _ = utils.parse_server(server)
if type(config) == 'function' then
config = config()
end
if type(config) == 'table' then
config = vim.tbl_deep_extend('keep', config, {
on_attach = opts.on_attach,
capabilities = opts.capabilities,
settings = {},
})
local ok1, cmp = pcall(require, 'cmp_nvim_lsp')
if ok1 then
config.capabilities = cmp.default_capabilities(config.capabilities)
end
local ok2, coq = pcall(require, 'coq')
if ok2 then
config = coq.lsp_ensure_capabilities(config)
end
local ok3, blink_cmp = pcall(require, 'blink.cmp')
if ok3 then
config.capabilities = blink_cmp.get_lsp_capabilities(opts.capabilities)
end
-- if opts.inlay_hints.enabled == true then
-- config.capabilities.textDocument = {
-- inlayHint = {
-- dynamicRegistration = false,
-- resolveSupport = {
-- properties = {},
-- },
-- },
-- }
-- end
end
servers[server_name] = config
end
return servers
end
---@type table<string, string|function|{ cmd: string|function, opts: vim.keymap.set.Opts? }>
local default_mappings = {
gD = { cmd = vim.lsp.buf.declaration, opts = { desc = 'Go To Declaration' } },
gd = { cmd = vim.lsp.buf.definition, opts = { desc = 'Go To Definition' } },
gi = { cmd = vim.lsp.buf.implementation, opts = { desc = 'Go To Implementation' } },
gr = { cmd = vim.lsp.buf.references, opts = { desc = 'Go To References' } },
K = { cmd = vim.lsp.buf.hover, opts = { desc = 'Hover' } },
['<C-k>'] = { cmd = vim.lsp.buf.signature_help, opts = { desc = 'Show Signature Help' } },
['<space>rn'] = { cmd = vim.lsp.buf.rename, opts = { desc = 'Rename' } },
['<space>ca'] = { cmd = vim.lsp.buf.code_action, opts = { desc = 'Code Action' } },
['<space>f'] = { cmd = vim.lsp.buf.format, opts = { desc = 'Format Code' } },
['<space>e'] = { cmd = vim.diagnostic.open_float, opts = { desc = 'Show Diagnostics' } },
['[d'] = { cmd = function() vim.diagnostic.jump({ count = -1, float = true }) end, opts = { desc = 'Prev Diagnostic' } },
[']d'] = { cmd = function() vim.diagnostic.jump({ count = 1, float = true }) end, opts = { desc = 'Next Diagnostic' } },
}
local M = {}
---@class LspSetup.ServerConfig : vim.lsp.ClientConfig
---@field cmd? string[]|fun(dispatchers: vim.lsp.rpc.Dispatchers): vim.lsp.rpc.PublicClient
---@class LspSetup.Options
---Enable default key mappings.
---@field default_mappings? boolean
---Custom key mappings for LSP.
---@field mappings? table<string, string|function|{ cmd: string|function, opts: vim.keymap.set.Opts? }>
---Defines the capabilities provided by the client.
---@field capabilities? lsp.ClientCapabilities
---Callback invoked when client attaches to a buffer.
---@field on_attach? fun(client: vim.lsp.Client, bufnr: number)
---Configurations for LSP servers.
---@field servers table<string, LspSetup.ServerConfig|function>
---Configurations for inlay hints.
---@field inlay_hints? InlayHints.Options
M.defaults = {
default_mappings = true,
mappings = {},
capabilities = vim.lsp.protocol.make_client_capabilities(),
on_attach = function(client, _)
utils.format_on_save(client)
end,
servers = {},
inlay_hints = inlay_hints.opts,
}
---@param opts LspSetup.Options
---@return nil
function M.setup(opts)
if vim.fn.has('nvim-0.11') ~= 1 then
vim.notify_once('LSP setup requires Neovim 0.11.0+', vim.log.levels.ERROR)
return
end
opts = vim.tbl_deep_extend('keep', opts, M.defaults)
vim.api.nvim_create_augroup('LspSetup', {})
vim.api.nvim_create_autocmd('LspAttach', {
group = 'LspSetup',
callback = function(args)
local bufnr = args.buf
local mappings = opts.mappings or {}
if opts.default_mappings then
mappings = vim.tbl_deep_extend('keep', mappings, default_mappings)
end
utils.mappings(bufnr, mappings)
end
})
inlay_hints.setup(opts.inlay_hints)
local servers = lsp_servers(opts)
local ok1, mason = pcall(require, 'mason')
local ok2, mason_lspconfig = pcall(require, 'mason-lspconfig')
if ok1 and ok2 then
if vim.api.nvim_get_commands({})['Mason'] == nil then
mason.setup()
end
mason_lspconfig.setup({
ensure_installed = utils.get_keys(opts.servers),
automatic_enable = false,
})
end
for server_name, config in pairs(servers) do
local ok, lsp_config = pcall(require, ('mason-lspconfig.lsp.%s'):format(server_name))
if ok then
config = vim.tbl_deep_extend('keep', config, lsp_config)
end
vim.lsp.config(server_name, config)
vim.lsp.enable(server_name)
end
end
return M
================================================
FILE: lua/lsp-setup/inlay_hints.lua
================================================
local M = {}
---@class InlayHints.Options
---@field enabled? boolean Enable inlay hints
---@field highlight? string Highlight group for inlay hints
M.opts = {
enabled = false,
highlight = 'Comment',
}
M.state = setmetatable({}, { __index = nil })
---@param opts InlayHints.Options
function M.setup(opts)
M.opts = vim.tbl_deep_extend('keep', opts, M.opts)
if not opts.enabled then
return
end
if vim.fn.has('nvim-0.11') ~= 1 then
vim.notify_once('LSP Inlayhints requires Neovim 0.11.0+', vim.log.levels.ERROR)
return
end
vim.cmd.highlight('default link LspInlayHint ' .. M.opts.highlight)
vim.api.nvim_create_augroup('LspSetup_Inlayhints', {})
vim.api.nvim_create_autocmd('LspAttach', {
group = 'LspSetup_Inlayhints',
callback = function(args)
if not (args.data and args.data.client_id) then
return
end
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
M.on_attach(client, bufnr)
end,
})
end
---@param client vim.lsp.Client|nil
---@param bufnr number
---@return nil
function M.on_attach(client, bufnr)
if not client then
vim.notify_once('LSP Inlayhints attached failed: nil client.', vim.log.levels.ERROR)
return
end
if not client.server_capabilities.inlayHintProvider then
return
end
if M.state[bufnr] then
return
end
M.state[bufnr] = client.id
if client.name == 'zls' then
vim.g.zig_fmt_autosave = 0
end
vim.lsp.inlay_hint.enable(true)
end
return M
================================================
FILE: lua/lsp-setup/utils.lua
================================================
local M = {}
---@param bufnr number
---@param mappings table<string, string|function|{ cmd: string|function, opts: vim.keymap.set.Opts? }>
function M.mappings(bufnr, mappings)
---@type vim.keymap.set.Opts
local _opts = { noremap = true, silent = true, buffer = bufnr }
for key, mapping in pairs(mappings or {}) do
---@type string|function
local cmd = nil
---@type vim.keymap.set.Opts
local opts = nil
if type(mapping) == 'table' then
cmd = mapping.cmd
opts = vim.tbl_deep_extend('force', _opts, mapping.opts or {})
else
cmd = mapping
opts = _opts
end
if type(cmd) == 'string' and cmd:find('^lua') ~= nil then
cmd = ':' .. cmd .. '<cr>'
end
vim.keymap.set('n', key, cmd, opts)
end
end
---@param client vim.lsp.Client
function M.disable_formatting(client)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
end
---@param client vim.lsp.Client
function M.format_on_save(client)
if client:supports_method('textDocument/formatting') then
local lsp_format_augroup = vim.api.nvim_create_augroup('LspFormat', { clear = true })
vim.api.nvim_create_autocmd('BufWritePre', {
group = lsp_format_augroup,
callback = function()
vim.lsp.buf.format()
end,
})
end
end
---@param server string
function M.parse_server(server)
return unpack(vim.split(server, '@'))
end
---@param t table
---@return table
function M.get_keys(t)
local keys = {}
for key, _ in pairs(t) do
table.insert(keys, key)
end
return keys
end
return M
gitextract_gjggy8a7/
├── .github/
│ └── FUNDING.yml
├── .luarc.json
├── LICENSE
├── README.md
└── lua/
└── lsp-setup/
├── init.lua
├── inlay_hints.lua
└── utils.lua
Condensed preview — 7 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (31K chars).
[
{
"path": ".github/FUNDING.yml",
"chars": 644,
"preview": "# These are supported funding model platforms\n\ngithub: [Junnplus]\npatreon: # Replace with a single Patreon username\nopen"
},
{
"path": ".luarc.json",
"chars": 164,
"preview": "{\n \"$schema\": \"https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json\",\n \"Lua.format.defaultC"
},
{
"path": "LICENSE",
"chars": 11357,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "README.md",
"chars": 9227,
"preview": "# lsp-setup.nvim\n\nA simple wrapper for [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) and [mason-lspconfig]("
},
{
"path": "lua/lsp-setup/init.lua",
"chars": 5067,
"preview": "local utils = require('lsp-setup.utils')\nlocal inlay_hints = require('lsp-setup.inlay_hints')\n\n---@param opts LspSetup.O"
},
{
"path": "lua/lsp-setup/inlay_hints.lua",
"chars": 1520,
"preview": "local M = {}\n\n---@class InlayHints.Options\n---@field enabled? boolean Enable inlay hints\n---@field highlight? string Hig"
},
{
"path": "lua/lsp-setup/utils.lua",
"chars": 1624,
"preview": "local M = {}\n\n---@param bufnr number\n---@param mappings table<string, string|function|{ cmd: string|function, opts: vim."
}
]
About this extraction
This page contains the full source code of the junnplus/nvim-lsp-setup GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 7 files (28.9 KB), approximately 7.3k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.