all repos

init.lua @ efe99e3d573d8a6eb9b814a1286a9589d046e025

my nvim config
4 files changed, 57 insertions(+), 2 deletions(-)
feat(lsp): configure typescript language server
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2025-05-28 02:55:21 +0300
Parent: e921538
M lazy-lock.json

@@ -47,7 +47,6 @@ "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },

"telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }, "tokyonight.nvim": { "branch": "main", "commit": "b262293ef481b0d1f7a14c708ea7ca649672e200" }, - "typescript-tools.nvim": { "branch": "master", "commit": "3c501d7c7f79457932a8750a2a1476a004c5c1a9" }, "undotree": { "branch": "master", "commit": "b951b87b46c34356d44aa71886aecf9dd7f5788a" }, "vim-illuminate": { "branch": "master", "commit": "fbc16dee336d8cc0d3d2382ea4a53f4a29725abf" }, "vim-repeat": { "branch": "master", "commit": "8106e142dfdc278ff3eaaadd7b362ad7949d4357" },
A lsp/ts_ls.lua

@@ -0,0 +1,56 @@

+local u = require("core.utils").lsp + +---@return vim.lsp.Config +return { + cmd = { "typescript-language-server", "--stdio" }, + init_options = { hostInfo = "neovim" }, + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + root_markers = u.root_marker { + "tsconfig.json", + "jsconfig.json", + "package.json", + }, + handlers = { + -- handle rename request for certain code actions like extracting functions / types + ["_typescript.rename"] = function(_, result, ctx) + local client = assert(vim.lsp.get_client_by_id(ctx.client_id)) + vim.lsp.util.show_document({ + uri = result.textDocument.uri, + range = { + start = result.position, + ["end"] = result.position, + }, + }, client.offset_encoding) + vim.lsp.buf.rename() + return vim.NIL + end, + }, + + on_attach = function(client) + -- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in + -- `vim.lsp.buf.code_action()` if specified in `context.only`. + vim.api.nvim_buf_create_user_command( + 0, + "LspTypescriptSourceAction", + function() + local source_actions = vim.tbl_filter(function(action) + return vim.startswith(action, "source.") + end, client.server_capabilities.codeActionProvider.codeActionKinds) + + vim.lsp.buf.code_action { + context = { + only = source_actions, + }, + } + end, + {} + ) + end, +}
M lua/core/lsp.lua

@@ -11,6 +11,7 @@ "gopls",

"jsonls", "lua_ls", "markdown_oxide", + "ts_ls", "yamlls", }
M lua/plugins/core.lua

@@ -7,7 +7,6 @@ { "tpope/vim-repeat", event = "VeryLazy" },

{ "tpope/vim-speeddating", keys = { "<C-a>", "<C-x>" } }, { "tweekmonster/helpful.vim", cmd = "HelpfulVersion" }, { "wakatime/vim-wakatime", event = "VeryLazy" }, - { "pmizio/typescript-tools.nvim", ft = { "typescript" }, config = true }, { "OXY2DEV/markview.nvim", ft = { "markdown" }, version = false }, { "folke/tokyonight.nvim",