Skip to content

Commit

Permalink
Merge pull request #10 from alpha2phi/09-refactor
Browse files Browse the repository at this point in the history
09 refactor
  • Loading branch information
mengwangk authored Jul 22, 2023
2 parents 5e381e2 + 53c610d commit 4379238
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 66 deletions.
9 changes: 9 additions & 0 deletions lua/base/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,13 @@ return {
end
end,
},
{
"folke/edgy.nvim",
event = "VeryLazy",
opts = {
left = {
{ ft = "hydra_hint", title = "Hydra", size = { height = 0.5 }, pinned = true },
},
},
},
}
9 changes: 6 additions & 3 deletions lua/base/lsp/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ local M = {}
function M.on_attach(client, buffer)
local self = M.new(client, buffer)

self:map("gd", "Telescope lsp_definitions", { desc = "Goto Definition" })
-- stylua: ignore
self:map("gd", function() require("telescope.builtin").lsp_definitions({ reuse_win = true }) end, { desc = "Goto Definition" })
self:map("gr", "Telescope lsp_references", { desc = "References" })
self:map("gI", "Telescope lsp_implementations", { desc = "Goto Implementation" })
self:map("gb", "Telescope lsp_type_definitions", { desc = "Goto Type Definition" })
-- stylua: ignore
self:map("gI", function() require("telescope.builtin").lsp_implementations({ reuse_win = true }) end, { desc = "Goto Implementation" })
-- stylua: ignore
self:map("gy", function() require("telescope.builtin").lsp_type_definitions({ reuse_win = true }) end, { desc = "Goto Type Definition" })
self:map("K", vim.lsp.buf.hover, { desc = "Hover" })
self:map("gK", vim.lsp.buf.signature_help, { desc = "Signature Help", has = "signatureHelp" })
self:map("]d", M.diagnostic_goto(true), { desc = "Next Diagnostic" })
Expand Down
2 changes: 1 addition & 1 deletion lua/pde/jupyter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ local function repl_menu()
invoke_on_body = true,
hint = {
border = "rounded",
position = "top-middle",
position = "bottom-middle",
},
},
mode = "n",
Expand Down
2 changes: 1 addition & 1 deletion lua/pde/rust.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ return {
},
},
},
taplo = {},
},
setup = {
taplo = {},
rust_analyzer = function(_, opts)
local codelldb_path, liblldb_path = get_codelldb()
local lsp_utils = require "base.lsp.utils"
Expand Down
102 changes: 41 additions & 61 deletions lua/pde/typescript.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,36 @@ return {
vim.list_extend(opts.ensure_installed, { "javascript", "typescript", "tsx" })
end,
},
-- {
-- "williamboman/mason.nvim",
-- opts = function(_, opts)
-- table.insert(opts.ensure_installed, "js-debug-adapter")
-- end,
-- },
{
"williamboman/mason.nvim",
opts = function(_, opts)
vim.list_extend(opts.ensure_installed, { "typescript-language-server", "js-debug-adapter" })
end,
},
{
"pmizio/typescript-tools.nvim",
opts = {},
config = function(_, opts)
require("base.lsp.utils").on_attach(function(client, bufnr)
if client.name == "tsserver" then
vim.keymap.set("n", "<leader>lo", "<cmd>TSToolsOrganizeImports<cr>", { buffer = bufnr, desc = "Organize Imports" })
vim.keymap.set("n", "<leader>lO", "<cmd>TSToolsSortImports<cr>", { buffer = bufnr, desc = "Sort Imports" })
vim.keymap.set("n", "<leader>lu", "<cmd>TSToolsRemoveUnused<cr>", { buffer = bufnr, desc = "Removed Unused" })
vim.keymap.set("n", "<leader>lz", "<cmd>TSToolsGoToSourceDefinition<cr>", { buffer = bufnr, desc = "Go To Source Definition" })
vim.keymap.set("n", "<leader>lR", "<cmd>TSToolsRemoveUnusedImports<cr>", { buffer = bufnr, desc = "Removed Unused Imports" })
vim.keymap.set("n", "<leader>lF", "<cmd>TSToolsFixAll<cr>", { buffer = bufnr, desc = "Fix All" })
vim.keymap.set("n", "<leader>lA", "<cmd>TSToolsAddMissingImports<cr>", { buffer = bufnr, desc = "Add Missing Imports" })
end
end)
require("typescript-tools").setup(opts)
end,
},
{
"neovim/nvim-lspconfig",
dependencies = { "jose-elias-alvarez/typescript.nvim" },
dependencies = { "pmizio/typescript-tools.nvim" },
opts = {
-- make sure mason installs the server
servers = {
---Typescript
tsserver = {
settings = {
typescript = {
format = {
indentSize = vim.o.shiftwidth,
convertTabsToSpaces = vim.o.expandtab,
tabSize = vim.o.tabstop,
},
},
javascript = {
format = {
indentSize = vim.o.shiftwidth,
convertTabsToSpaces = vim.o.expandtab,
tabSize = vim.o.tabstop,
},
},
completions = {
completeFunctionCalls = true,
},
},
},
-- ESLint
eslint = {
settings = {
Expand All @@ -52,18 +48,6 @@ return {
},
},
setup = {
tsserver = function(_, opts)
require("base.lsp.utils").on_attach(function(client, bufnr)
if client.name == "tsserver" then
-- stylua: ignore
vim.keymap.set("n", "<leader>lo", "<cmd>TypescriptOrganizeImports<CR>", { buffer = bufnr, desc = "Organize Imports" })
-- stylua: ignore
vim.keymap.set("n", "<leader>lR", "<cmd>TypescriptRenameFile<CR>", { desc = "Rename File", buffer = bufnr })
end
end)
require("typescript").setup { server = opts }
return true
end,
eslint = function()
vim.api.nvim_create_autocmd("BufWritePre", {
callback = function(event)
Expand All @@ -80,34 +64,30 @@ return {
},
},
},
{
"jose-elias-alvarez/null-ls.nvim",
opts = function(_, opts)
table.insert(opts.sources, require "typescript.extensions.null-ls.code-actions")
end,
},
{
"mfussenegger/nvim-dap",
dependencies = {
{ "mxsdev/nvim-dap-vscode-js" },
{
"microsoft/vscode-js-debug",
build = "npm install --legacy-peer-deps && npx gulp vsDebugServerBundle && mv dist out",
},
},
opts = {
setup = {
vscode_js_debug = function()
local function get_js_debug()
local path = vim.fn.stdpath "data"
return path .. "/lazy/vscode-js-debug"
local install_path = require("mason-registry").get_package("js-debug-adapter"):get_install_path()
return install_path .. "/js-debug/src/dapDebugServer.js"
end

require("dap-vscode-js").setup {
node_path = "node",
debugger_path = get_js_debug(),
adapters = { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" },
}
for _, adapter in ipairs { "pwa-node", "pwa-chrome", "pwa-msedge", "node-terminal", "pwa-extensionHost" } do
require("dap").adapters[adapter] = {
type = "server",
host = "localhost",
port = "${port}",
executable = {
command = "node",
args = {
get_js_debug(),
"${port}",
},
},
}
end

for _, language in ipairs { "typescript", "javascript" } do
require("dap").configurations[language] = {
Expand Down

0 comments on commit 4379238

Please sign in to comment.