diff --git a/README.md b/README.md index 058ece0..493edcf 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -# starter.lvim +# JS-TS-REACT IDE (starter.lvim) -A great starting point for your LunarVim journey! +A great starting point for your `Javascript`, `Typescript` and `React` LunarVim journey! -## Submission Guidelines +# Configuration -- Ideally one file! -- IDE config must be added to its own branch named `lang-ide` -- try to keep it focused on the language and not your biased keybindings/options +In order to get started with this IDE setup please remember to run the following command: +`:MasonInstall typescript-language-server` diff --git a/config.lua b/config.lua new file mode 100644 index 0000000..a8a4585 --- /dev/null +++ b/config.lua @@ -0,0 +1,35 @@ +-- This whole setup assumes you are using LunarVim Nightly with Lazy as the plugin manager +-- LSP +-- For me the default LSP setup automatically installed by LunarVim is fine + +-- FORMATTER +lvim.format_on_save = true -- Change this to false if you prefer + +local formatters = require "lvim.lsp.null-ls.formatters" +formatters.setup { + { + command = "prettier", + extra_args = { "--print-width", "100" }, + filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact" }, + }, +} + +-- LINTER +local linters = require "lvim.lsp.null-ls.linters" +linters.setup { + { command = "eslint_d", filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "vue" } }, +} + +-- DEBUGGER CONFIG +reload "user.debugger" + +-- DEBUGGER PLUGINS +lvim.plugins = { + -- I prefer to install the plugins for the debugger this way following the official nvim-dap-vscode-js documentation on github by msxdev instead of using mason + { "mxsdev/nvim-dap-vscode-js" }, + { + "microsoft/vscode-js-debug", + lazy = true, + build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out" + }, +} diff --git a/lua/user/debugger/init.lua b/lua/user/debugger/init.lua new file mode 100644 index 0000000..3c591a3 --- /dev/null +++ b/lua/user/debugger/init.lua @@ -0,0 +1 @@ +require "user.debugger.languages.js-ts" diff --git a/lua/user/debugger/languages/js-ts-react.lua b/lua/user/debugger/languages/js-ts-react.lua new file mode 100644 index 0000000..79cb9ee --- /dev/null +++ b/lua/user/debugger/languages/js-ts-react.lua @@ -0,0 +1,64 @@ +local debugger_path = os.getenv("LUNARVIM_RUNTIME_DIR") .. "/site/pack/lazy/opt/vscode-js-debug" + +require("dap-vscode-js").setup { + node_path = "node", + debugger_path = debugger_path, + -- debugger_cmd = { "js-debug-adapter" }, + adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" }, -- which adapters to register in nvim-dap +} + +for _, language in ipairs { "typescript", "javascript" } do + require("dap").configurations[language] = { + { + type = "pwa-node", + request = "launch", + name = "Launch file", + program = "${file}", + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "attach", + name = "Attach", + processId = require("dap.utils").pick_process, + cwd = "${workspaceFolder}", + }, + { + type = "pwa-node", + request = "launch", + name = "Debug Jest Tests", + -- trace = true, -- include debugger info + runtimeExecutable = "node", + runtimeArgs = { + "./node_modules/jest/bin/jest.js", + "--runInBand", + }, + rootPath = "${workspaceFolder}", + cwd = "${workspaceFolder}", + console = "integratedTerminal", + internalConsoleOptions = "neverOpen", + }, + } +end + +for _, language in ipairs { "typescriptreact", "javascriptreact" } do + require("dap").configurations[language] = { + { + type = "pwa-chrome", + name = "Attach - Remote Debugging", + request = "attach", + program = "${file}", + cwd = vim.fn.getcwd(), + sourceMaps = true, + protocol = "inspector", + port = 9222, + webRoot = "${workspaceFolder}", + }, + { + type = "pwa-chrome", + name = "Launch Chrome", + request = "launch", + url = "http://localhost:3000", + }, + } +end