comments(nvim): add tsserver variable annotation

This commit is contained in:
sankalp committed 2024-02-25 21:01:25 +05:45
1 parent 3f062011c5
commit 3be72c24bc
7 files changed
+134 -78

No files matched your search

+8 -6
View File
@@ -96,12 +96,14 @@ ac({ "BufNewFile", "BufRead" }, {
ac("ModeChanged", {
pattern = "*",
callback = function()
if
((vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i")
and require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
and not require("luasnip").session.jump_active
then
require("luasnip").unlink_current()
if not vim.g.vscode then
if
((vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i")
and require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
and not require("luasnip").session.jump_active
then
require("luasnip").unlink_current()
end
end
end,
})
+21 -1
View File
@@ -17,7 +17,8 @@ map("n", "<leader>l", "<Nop>")
map("n", "<leader>ll", "<cmd>Lazy<cr>", { desc = "Lazy" })
-- stylua: ignore start
map("n", "<leader>ld", function() vim.fn.system({ "xdg-open", "https://lazyvim.org" }) end, { desc = "LazyVim Docs" })
map("n", "<leader>lr", function() vim.fn.system({ "xdg-open", "https://github.com/LazyVim/LazyVim" }) end, { desc = "LazyVim Repo" })
map("n", "<leader>lr", function() vim.fn.system({ "xdg-open", "https://github.com/LazyVim/LazyVim" }) end,
{ desc = "LazyVim Repo" })
map("n", "<leader>lx", "<cmd>LazyExtras<cr>", { desc = "Extras" })
map("n", "<leader>lc", function() Util.news.changelog() end, { desc = "LazyVim Changelog" })
map("n", "<leader>lu", function() require("lazy").update() end, { desc = "Lazy Update" })
@@ -91,6 +92,25 @@ map("n", "[/", "?\\S\\zs\\s*╭<CR>zt", { desc = "Prev block comment" })
-- Plugin Info
map("n", "<leader>cif", "<cmd>LazyFormatInfo<cr>", { desc = "Formatting" })
map("n", "<leader>cic", "<cmd>ConformInfo<cr>", { desc = "Conform" })
local linters = function()
local linters_attached = require("lint").linters_by_ft[vim.bo.filetype]
local buf_linters = {}
if not linters_attached then
vim.notify("No linters attached", vim.log.levels.WARN, { title = "Linter" })
return
end
for _, linter in pairs(linters_attached) do
table.insert(buf_linters, linter)
end
local unique_client_names = table.concat(buf_linters, ", ")
local linters = string.format("%s", unique_client_names)
vim.notify(linters, vim.log.levels.INFO, { title = "Linter" })
end
map("n", "<leader>ciL", linters, { desc = "Lint" })
map("n", "<leader>cir", "<cmd>LazyRoot<cr>", { desc = "Root" })
-- U for redo
@@ -1,12 +1,5 @@
return {
{
"nvim-treesitter/nvim-treesitter",
opts = function(_, opts)
if type(opts.ensure_installed) == "table" then
vim.list_extend(opts.ensure_installed, { "yaml" })
end
end,
},
{ import = "lazyvim.plugins.extras.lang.yaml" },
{
"williamboman/mason.nvim",
opts = function(_, opts)
@@ -49,14 +49,38 @@ return {
"cssmodules-language-server",
"css-lsp",
"htmlhint",
"stylelint",
})
end,
},
{
"mfussenegger/nvim-lint",
opts = function(_, opts)
opts.linters_by_ft.html = opts.linters_by_ft.html or {}
table.insert(opts.linters_by_ft.html, "htmlhint")
local stylelint = "stylelint"
local function add_linters(tbl)
for ft, linters in pairs(tbl) do
if opts.linters_by_ft[ft] == nil then
opts.linters_by_ft[ft] = linters
else
vim.list_extend(opts.linters_by_ft[ft], linters)
end
end
end
add_linters({
["html"] = { "htmlhint" },
["css"] = { stylelint },
["scss"] = { stylelint },
["less"] = { stylelint },
["sugarss"] = { stylelint },
["vue"] = { stylelint },
["wxss"] = { stylelint },
["javascript"] = { stylelint },
["javascriptreact"] = { stylelint },
["typescript"] = { stylelint },
["typescriptreact"] = { stylelint },
})
return opts
end,
},
@@ -1,14 +1,5 @@
local source_action = function(name)
return function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { string.format("source.%s.ts", name) },
diagnostics = {},
},
})
end
end
local ts_server_activated = true -- Change this variable to false if you want to use typescript-tools instead of lspconfig tsserver implementation
local ft = { "typescript", "typescriptreact", "javascript", "javascriptreact" }
local inlayHints = {
includeInlayParameterNameHints = "all",
@@ -21,17 +12,16 @@ local inlayHints = {
includeInlayEnumMemberValueHints = true,
}
local function denoConfigExists()
local configs = { "deno.json", "deno.jsonc" }
local root = require("lazyvim.util.root").get()
for _, config in ipairs(configs) do
if vim.fn.filereadable(root .. "/" .. config) == 1 then
return true
end
local source_action = function(name)
return function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { string.format("source.%s.ts", name) },
diagnostics = {},
},
})
end
return false
end
return {
@@ -49,6 +39,7 @@ return {
opts = {
servers = {
tsserver = {
enabled = ts_server_activated,
init_options = {
preferences = {
disableSuggestions = true,
@@ -82,13 +73,44 @@ return {
},
denols = {},
},
setup = {
tsserver = function(_, opts)
-- Disable tsserver if denols is present
return denoConfigExists()
end,
},
},
{
"pmizio/typescript-tools.nvim",
dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" },
enabled = not ts_server_activated,
ft = ft,
opts = {
cmd = { "typescript-language-server", "--stdio" },
settings = {
code_lens = "all",
expose_as_code_action = "all",
tsserver_plugins = {
"@styled/typescript-styled-plugin",
},
tsserver_file_preferences = {
completions = {
completeFunctionCalls = true,
},
init_options = {
preferences = {
disableSuggestions = true,
},
},
includeInlayParameterNameHints = "all",
includeInlayEnumMemberValueHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayFunctionParameterTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayVariableTypeHints = true,
},
},
},
keys = {
{ "<leader>co", ft = ft, "<cmd>TSToolsOrganizeImports<cr>", desc = "Organize Imports" },
{ "<leader>cR", ft = ft, "<cmd>TSToolsRemoveUnusedImports<cr>", desc = "Remove Unused Imports" },
{ "<leader>cM", ft = ft, "<cmd>TSToolsAddMissingImports<cr>", desc = "Add Missing Imports" },
},
},
{
"nvim-treesitter/nvim-treesitter",
@@ -1,35 +0,0 @@
local stylelint = "stylelint"
return {
{
"williamboman/mason.nvim",
opts = function(_, opts)
opts.ensure_installed = opts.ensure_installed or {}
vim.list_extend(opts.ensure_installed, { stylelint })
end,
},
{
"mfussenegger/nvim-lint",
opts = function(_, opts)
local function add_linters(tbl)
for ft, linters in pairs(tbl) do
if opts.linters_by_ft[ft] == nil then
opts.linters_by_ft[ft] = linters
else
vim.list_extend(opts.linters_by_ft[ft], linters)
end
end
end
add_linters({
["html"] = { "stylelint" },
["css"] = { "stylelint" },
["scss"] = { "stylelint" },
["sass"] = { "stylelint" },
["less"] = { "stylelint" },
})
return opts
end,
},
}
+30
View File
@@ -1,3 +1,30 @@
local lsp = function()
local buf_clients = vim.lsp.get_clients({ bufnr = 0 })
if #buf_clients == 0 then
return ""
else
return ""
end
end
local formatter = function()
local formatters = require("conform").list_formatters(0)
if #formatters == 0 then
return ""
else
return "󰛖 "
end
end
local linter = function()
local linters = require("lint").linters_by_ft[vim.bo.filetype]
if #linters == 0 then
return ""
else
return "󱉶 "
end
end
return {
"nvim-lualine/lualine.nvim",
opts = function(_, opts)
@@ -5,6 +32,9 @@ return {
opts.options.section_separators = { left = "", right = "" }
table.remove(opts.sections.lualine_x, 1)
table.insert(opts.sections.lualine_x, 2, lsp)
table.insert(opts.sections.lualine_x, 2, formatter)
table.insert(opts.sections.lualine_x, 2, linter)
opts.sections.lualine_a = { { "mode", icon = "" } }
opts.sections.lualine_y = { { "progress", icon = "", separator = " ", padding = { left = 1, right = 1 } } }
opts.sections.lualine_z = { { "location", icon = "", padding = { left = 1, right = 1 } } }