-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use vim.lsp.config & vim.lsp.enable
- Loading branch information
1 parent
696400e
commit fe3a7e4
Showing
54 changed files
with
515 additions
and
731 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
vim.o.expandtab = false | ||
|
||
local lsp = require("pde.lsp") | ||
|
||
lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) | ||
lsp.start( | ||
require("pde.lsp.configs.efm").config_from_single("golangci_lint", bufnr), | ||
{ bufnr = bufnr } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
vim.o.expandtab = false | ||
|
||
local lsp = require("pde.lsp") | ||
lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
vim.o.expandtab = false | ||
|
||
local lsp = require("pde.lsp") | ||
lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
vim.o.expandtab = false | ||
|
||
local lsp = require("pde.lsp") | ||
lsp.start(require("pde.lsp.configs.gopls").config(bufnr), { bufnr = bufnr }) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
vim.o.shiftwidth = 2 | ||
|
||
local lsp = require("pde.lsp") | ||
lsp.start(require("pde.lsp.configs.nixd").config(bufnr), { bufnr = bufnr }) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
-- default is empty | ||
vim.o.commentstring = "// %s" | ||
|
||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
local lsp = require("pde.lsp") | ||
|
||
lsp.start(require("pde.lsp.configs.terraformls").config(bufnr), { bufnr = bufnr }) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
local bufnr = vim.api.nvim_get_current_buf() | ||
|
||
vim.o.shiftwidth = 2 | ||
|
||
local lsp = require("pde.lsp") | ||
|
||
lsp.start(require("pde.lsp.configs.efm").config_from_single("prettier", bufnr), { bufnr = bufnr }) | ||
lsp.start(require("pde.lsp.configs.yamlls").config(bufnr), { bufnr = bufnr }) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
local binaries = require("pde.binaries") | ||
|
||
vim.lsp.config("clangd", { | ||
cmd = { binaries.clangd() }, | ||
root_markers = { | ||
".clangd", | ||
".clang-tidy", | ||
".clang-format", | ||
"compile_commands.json", | ||
"compile_flags.txt", | ||
"configure.ac", | ||
}, | ||
filetypes = { "c", "cpp" }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
local config = require("pde.lsp.configs.efm").config_from_multi("efmson", { "prettier", "jq" }) | ||
config.filetypes = { "json", "jsonc" } | ||
vim.lsp.config("efmson", config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
local config = require("pde.lsp.configs.efm").config_from_single("golangci_lint") | ||
config.filetypes = { "go" } | ||
vim.lsp.config("golangci_lint", config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- https://github.com/golang/tools/tree/master/gopls | ||
local binaries = require("pde.binaries") | ||
|
||
vim.lsp.config("gopls", { | ||
cmd = { binaries.gopls() }, | ||
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md | ||
settings = { | ||
gopls = { | ||
allExperiments = true, | ||
}, | ||
}, | ||
root_markers = { "go.work", "go.mod" }, | ||
filetypes = { "go", "gomod", "gotmpl", "gowork" }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- https://github.com/hrsh7th/vscode-langservers-extracted | ||
|
||
local binaries = require("pde.binaries") | ||
local schemastore = require("schemastore") | ||
|
||
vim.lsp.config("jsonls", { | ||
cmd = { binaries.jsonls(), "--stdio" }, | ||
init_options = { | ||
provideFormatter = false, -- use prettier instead | ||
}, | ||
settings = { | ||
json = { | ||
format = false, | ||
validate = true, | ||
schemas = schemastore.json.schemas(), | ||
}, | ||
}, | ||
filetypes = { "json", "jsonc" }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
-- https://github.com/valentjn/ltex-ls | ||
|
||
local binaries = require("pde.binaries") | ||
local paths = require("pde.paths") | ||
|
||
local dictionary = {} | ||
local disabledRules = {} | ||
local hiddenFalsePositives = {} | ||
|
||
local name = "ltex" | ||
local current_language = "en-US" | ||
|
||
---@param path string | ||
---@param lines string[] | ||
local function append_to_file(path, lines) | ||
local file = io.open(path, "a") | ||
if file then | ||
for _, line in ipairs(lines) do | ||
file:write(line .. "\n") | ||
end | ||
file:close() | ||
end | ||
end | ||
|
||
---@param command lsp.Command | ||
---@return boolean | ||
local function validate_command(command) | ||
if #command.arguments ~= 1 then | ||
vim.notify("unexpected arguments: " .. vim.inspect(command.arguments), vim.log.levels.ERROR) | ||
return false | ||
end | ||
|
||
return true | ||
end | ||
|
||
---@param path string file to read | ||
---@param target string[] target to append the lines to | ||
local function read_lines_into(path, target) | ||
local file = io.open(path, "r") | ||
if file then | ||
for line in file:lines() do | ||
table.insert(target, line) | ||
end | ||
|
||
file:close() | ||
end | ||
end | ||
|
||
---@param command table | ||
---@param key string | ||
---@param tbl table<string,string[]> | ||
---@return table<string,string[]> | ||
local function handle_action(command, key, tbl) | ||
if not validate_command(command) then return {} end | ||
|
||
local entries = command.arguments[1][key] | ||
for lang, entry in pairs(entries) do | ||
if not tbl[lang] then tbl[lang] = {} end | ||
vim.list_extend(tbl[lang], entry) | ||
end | ||
return entries | ||
end | ||
|
||
local update_client_with = function(changed_settings) | ||
local client = vim.lsp.get_clients({ name = name })[1] | ||
if not client then return end | ||
client:notify("workspace/didChangeConfiguration", { settings = changed_settings }) | ||
end | ||
|
||
local function get_dictionary_file(language) return paths.get_spellfile(vim.split(language, "-")[1]) end | ||
|
||
local function get_false_positives_file(language) | ||
return paths.get_spellfile(nil) .. "/ltex_false-positives_" .. language .. ".txt" | ||
end | ||
|
||
local function get_disabled_rules_file(language) | ||
return paths.get_spellfile(nil) .. "/ltex_disabled-rules_" .. language .. ".txt" | ||
end | ||
|
||
vim.lsp.config(name, { | ||
cmd = { binaries.ltex_ls() }, | ||
filetypes = { "markdown" }, | ||
before_init = function() | ||
if not dictionary[current_language] then | ||
dictionary[current_language] = {} | ||
read_lines_into(get_dictionary_file(current_language), dictionary[current_language]) | ||
end | ||
|
||
if not hiddenFalsePositives[current_language] then | ||
hiddenFalsePositives[current_language] = {} | ||
read_lines_into( | ||
get_false_positives_file(current_language), | ||
hiddenFalsePositives[current_language] | ||
) | ||
end | ||
|
||
if not disabledRules[current_language] then | ||
disabledRules[current_language] = {} | ||
read_lines_into( | ||
get_disabled_rules_file(current_language), | ||
disabledRules[current_language] | ||
) | ||
end | ||
end, | ||
settings = { | ||
ltex = { | ||
enabled = { "html", "markdown" }, | ||
language = current_language, | ||
checkFrequency = "save", | ||
dictionary = dictionary, | ||
disabledRules = disabledRules, | ||
hiddenFalsePositives = hiddenFalsePositives, | ||
}, | ||
}, | ||
on_attach = function(_, buf) | ||
vim.api.nvim_buf_call(buf, function() vim.o.spell = false end) | ||
-- TODO: buf_command for changing the language | ||
end, | ||
commands = { | ||
["_ltex.addToDictionary"] = function(command) | ||
local new = handle_action(command, "words", dictionary) | ||
update_client_with({ ltex = { dictionary = dictionary } }) | ||
for lang, entries in pairs(new) do | ||
local path = get_dictionary_file(lang) | ||
append_to_file(path, entries) | ||
end | ||
vim.cmd("MkSpell") | ||
end, | ||
["_ltex.hideFalsePositives"] = function(command) | ||
local new = handle_action(command, "falsePositives", hiddenFalsePositives) | ||
update_client_with({ ltex = { hiddenFalsePositives = hiddenFalsePositives } }) | ||
for lang, entries in pairs(new) do | ||
local path = get_false_positives_file(lang) | ||
append_to_file(path, entries) | ||
end | ||
end, | ||
["_ltex.disableRules"] = function(command) | ||
local new = handle_action(command, "ruleIds", disabledRules) | ||
update_client_with({ ltex = { disabledRules = disabledRules } }) | ||
for lang, entries in pairs(new) do | ||
local path = get_disabled_rules_file(lang) | ||
append_to_file(path, entries) | ||
end | ||
end, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- https://github.com/LuaLS/lua-language-server | ||
local binaries = require("pde.binaries") | ||
|
||
vim.lsp.config("lua_ls", { | ||
cmd = { binaries.lua_ls() }, | ||
filetypes = { "lua" }, | ||
on_init = function(client) | ||
-- use stylua via efm, this formatter is not great and it clears diagnostic text on save | ||
client.server_capabilities.documentFormattingProvider = nil | ||
client.server_capabilities.documentRangeFormattingProvider = nil | ||
end, | ||
settings = { | ||
Lua = { | ||
addonManager = { enable = false }, | ||
-- use stylua via efm, this formatter is not great and it clears diagnostic text on save | ||
format = { enable = false }, | ||
hint = { enable = true }, | ||
runtime = { version = "LuaJIT" }, | ||
telemetry = { enable = false }, | ||
workspace = { | ||
checkThirdParty = false, | ||
}, | ||
}, | ||
}, | ||
root_markers = { ".luarc.json" }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- https://github.com/nix-community/nixd | ||
|
||
local binaries = require("pde.binaries") | ||
|
||
vim.lsp.config("nixd", { | ||
cmd = { binaries.nixd() }, | ||
filetypes = { "nix" }, | ||
settings = { | ||
nixd = { | ||
formatting = { | ||
command = { binaries.nixfmt() }, | ||
}, | ||
}, | ||
}, | ||
root_markers = { "flake.nix" }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
local config = require("pde.lsp.configs.efm").config_from_single("prettier") | ||
config.filetypes = { "markdown", "yaml" } | ||
vim.lsp.config("prettier", config) |
Oops, something went wrong.