From cfe0e4902e18e08d2427031ccca969123fd51bc0 Mon Sep 17 00:00:00 2001 From: mk1121 Date: Tue, 23 Aug 2022 04:49:52 +0600 Subject: [PATCH] add tsserver and javascript.log --- lua/user/lsp/configs.lua | 2 +- lua/user/lsp/settings/tsserver.lua | 56 ++++++++++++++++++++++++++++++ lua/user/whichkey.lua | 5 ++- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 lua/user/lsp/settings/tsserver.lua diff --git a/lua/user/lsp/configs.lua b/lua/user/lsp/configs.lua index 95bfcea..155e377 100644 --- a/lua/user/lsp/configs.lua +++ b/lua/user/lsp/configs.lua @@ -5,7 +5,7 @@ end local lspconfig = require("lspconfig") -local servers = { "jsonls", "sumneko_lua" } +local servers = { "jsonls", "sumneko_lua","tsserver" } lsp_installer.setup({ ensure_installed = servers, diff --git a/lua/user/lsp/settings/tsserver.lua b/lua/user/lsp/settings/tsserver.lua new file mode 100644 index 0000000..0af4cb6 --- /dev/null +++ b/lua/user/lsp/settings/tsserver.lua @@ -0,0 +1,56 @@ +local util = require 'lspconfig.util' + +local bin_name = 'typescript-language-server' +local cmd = { bin_name, '--stdio' } + +if vim.fn.has 'win32' == 1 then + cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } +end + +return { + default_config = { + init_options = { hostInfo = 'neovim' }, + cmd = cmd, + filetypes = { + 'javascript', + 'javascriptreact', + 'javascript.jsx', + 'typescript', + 'typescriptreact', + 'typescript.tsx', + }, + root_dir = function(fname) + return util.root_pattern 'tsconfig.json'(fname) + or util.root_pattern('package.json', 'jsconfig.json', '.git')(fname) + end, + }, + docs = { + description = [[ +https://github.com/theia-ide/typescript-language-server +`typescript-language-server` depends on `typescript`. Both packages can be installed via `npm`: +```sh +npm install -g typescript typescript-language-server +``` +To configure typescript language server, add a +[`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) or +[`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) to the root of your +project. +Here's an example that disables type checking in JavaScript files. +```json +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "checkJs": false + }, + "exclude": [ + "node_modules" + ] +} +``` +]], + default_config = { + root_dir = [[root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git")]], + }, + }, +} diff --git a/lua/user/whichkey.lua b/lua/user/whichkey.lua index 0dc591a..401d4b5 100644 --- a/lua/user/whichkey.lua +++ b/lua/user/whichkey.lua @@ -95,7 +95,10 @@ local mappings = { }, ["F"] = { "Telescope live_grep theme=ivy", "Find Text" }, ["P"] = { "lua require('telescope').extensions.projects.projects()", "Projects" }, - + L = { + ":put =printf('console.log('' 🔔 %s 👉 %s 👉 %s:'', %s);', line('.'), expand('%:t'), expand(''), expand(''))", + "Javascript Log", + }, p = { name = "Packer", c = { "PackerCompile", "Compile" },