diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-22 00:08:36 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-07-22 00:08:36 +0200 |
commit | b51f1ae28924a752258e7607fbc3210f9b18eaac (patch) | |
tree | 8c8c095528990b3f6eb499dbcca15e9720e636d1 /.config/nvim/lua/lsp/tsserver-ls.lua | |
parent | da936b0ed9ac4c171d3c7908e41af1875a82b08b (diff) |
Updates based on Chris's lunarvim
Diffstat (limited to '.config/nvim/lua/lsp/tsserver-ls.lua')
-rw-r--r-- | .config/nvim/lua/lsp/tsserver-ls.lua | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/.config/nvim/lua/lsp/tsserver-ls.lua b/.config/nvim/lua/lsp/tsserver-ls.lua new file mode 100644 index 0000000..c687dfc --- /dev/null +++ b/.config/nvim/lua/lsp/tsserver-ls.lua @@ -0,0 +1,83 @@ +vim.cmd "let proj = FindRootDirectory()" +local root_dir = vim.api.nvim_get_var "proj" + +-- use the global prettier if you didn't find the local one +local prettier_instance = root_dir .. "/node_modules/.bin/prettier" +if vim.fn.executable(prettier_instance) ~= 1 then + prettier_instance = O.lang.tsserver.formatter.exe +end + +O.formatters.filetype["javascriptreact"] = { + function() + local args = { "--stdin-filepath", vim.fn.fnameescape(vim.api.nvim_buf_get_name(0)) } + local extend_args = O.lang.tsserver.formatter.args + + if extend_args then + for i = 1, #extend_args do + table.insert(args, extend_args[i]) + end + end + + return { + exe = prettier_instance, + args = args, + stdin = true, + } + end, +} +O.formatters.filetype["javascript"] = O.formatters.filetype["javascriptreact"] +O.formatters.filetype["typescript"] = O.formatters.filetype["javascriptreact"] +O.formatters.filetype["typescriptreact"] = O.formatters.filetype["javascriptreact"] + +require("formatter.config").set_defaults { + logging = false, + filetype = O.formatters.filetype, +} + +if require("utils").check_lsp_client_active "tsserver" then + return +end + +-- npm install -g typescript typescript-language-server +-- require'snippets'.use_suggested_mappings() +-- local capabilities = vim.lsp.protocol.make_client_capabilities() +-- capabilities.textDocument.completion.completionItem.snippetSupport = true; +-- local on_attach_common = function(client) +-- print("LSP Initialized") +-- require'completion'.on_attach(client) +-- require'illuminate'.on_attach(client) +-- end + +local on_attach = function(client, bufnr) + local lsp = require "lsp" + lsp.common_on_attach(client, bufnr) + lsp.tsserver_on_attach(client, bufnr) +end + +require("lspconfig").tsserver.setup { + cmd = { + DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + "--stdio", + }, + filetypes = { + "javascript", + "javascriptreact", + "javascript.jsx", + "typescript", + "typescriptreact", + "typescript.tsx", + }, + on_attach = on_attach, + -- This makes sure tsserver is not used for formatting (I prefer prettier) + settings = { documentFormatting = false }, + handlers = { + -- ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { + -- virtual_text = O.lang.tsserver.diagnostics.virtual_text, + -- signs = O.lang.tsserver.diagnostics.signs, + -- underline = O.lang.tsserver.diagnostics.underline, + -- update_in_insert = true, + -- }), + }, +} + +require("lsp.ts-fmt-lint").setup() |