feat(python): Added the python support to the code

pull/2788/head
n-s-s-p-k 1 month ago
parent 7801448908
commit aa3475476b

@ -5,8 +5,8 @@ local M = {}
local highlights = require "custom.highlights"
M.ui = {
theme = "aquarium",
theme_toggle = { "aquarium", "aquarium" },
theme = "tokyonight",
theme_toggle = { "tokyonight", "tokyonight" },
hl_override = highlights.override,
hl_add = highlights.add,

@ -0,0 +1,161 @@
local js_based_languages = {
"typescript",
"javascript",
"typescriptreact",
"javascriptreact",
"vue",
}
return {
{ "nvim-neotest/nvim-nio" },
{
"mfussenegger/nvim-dap",
config = function()
local dap = require "dap"
local Config = require "lazyvim.config"
vim.api.nvim_set_hl(0, "DapStoppedLine", { default = true, link = "Visual" })
for name, sign in pairs(Config.icons.dap) do
sign = type(sign) == "table" and sign or { sign }
vim.fn.sign_define(
"Dap" .. name,
{ text = sign[1], texthl = sign[2] or "DiagnosticInfo", linehl = sign[3], numhl = sign[3] }
)
end
for _, language in ipairs(js_based_languages) do
dap.configurations[language] = {
-- Debug single nodejs files
{
type = "pwa-node",
request = "launch",
name = "Launch file",
program = "${file}",
cwd = vim.fn.getcwd(),
sourceMaps = true,
},
-- Debug nodejs processes (make sure to add --inspect when you run the process)
{
type = "pwa-node",
request = "attach",
name = "Attach",
processId = require("dap.utils").pick_process,
cwd = vim.fn.getcwd(),
sourceMaps = true,
},
-- Debug web applications (client side)
{
type = "pwa-chrome",
request = "launch",
name = "Launch & Debug Chrome",
url = function()
local co = coroutine.running()
return coroutine.create(function()
vim.ui.input({
prompt = "Enter URL: ",
default = "http://localhost:3000",
}, function(url)
if url == nil or url == "" then
return
else
coroutine.resume(co, url)
end
end)
end)
end,
webRoot = vim.fn.getcwd(),
protocol = "inspector",
sourceMaps = true,
userDataDir = false,
},
-- Divider for the launch.json derived configs
{
name = "----- ↓ launch.json configs ↓ -----",
type = "",
request = "launch",
},
}
end
end,
keys = {
{
"<leader>dO",
function()
require("dap").step_out()
end,
desc = "Step Out",
},
{
"<leader>do",
function()
require("dap").step_over()
end,
desc = "Step Over",
},
{
"<leader>da",
function()
if vim.fn.filereadable ".vscode/launch.json" then
local dap_vscode = require "dap.ext.vscode"
dap_vscode.load_launchjs(nil, {
["pwa-node"] = js_based_languages,
["chrome"] = js_based_languages,
["pwa-chrome"] = js_based_languages,
})
end
require("dap").continue()
end,
desc = "Run with Args",
},
},
dependencies = {
-- Install the vscode-js-debug adapter
{
"microsoft/vscode-js-debug",
-- After install, build it and rename the dist directory to out
build = "npm install --legacy-peer-deps --no-save && npx gulp vsDebugServerBundle && rm -rf out && mv dist out",
version = "1.*",
},
{
"mxsdev/nvim-dap-vscode-js",
config = function()
---@diagnostic disable-next-line: missing-fields
require("dap-vscode-js").setup {
-- Path of node executable. Defaults to $NODE_PATH, and then "node"
-- node_path = "node",
-- Path to vscode-js-debug installation.
debugger_path = vim.fn.resolve(vim.fn.stdpath "data" .. "/lazy/vscode-js-debug"),
-- Command to use to launch the debug server. Takes precedence over "node_path" and "debugger_path"
-- debugger_cmd = { "js-debug-adapter" },
-- which adapters to register in nvim-dap
adapters = {
"chrome",
"pwa-node",
"pwa-chrome",
"pwa-msedge",
"pwa-extensionHost",
"node-terminal",
},
-- Path for file logging
-- log_file_path = "(stdpath cache)/dap_vscode_js.log",
-- Logging level for output to file. Set to false to disable logging.
-- log_file_level = false,
-- Logging level for output to console. Set to false to disable console output.
-- log_console_level = vim.log.levels.ERROR,
}
end,
},
{
"Joakker/lua-json5",
build = "./install.sh",
},
},
},
}

@ -4,7 +4,7 @@ local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require "lspconfig"
-- if you just want default config for the servers then put them in a table
local servers = { "html", "cssls", "tsserver", "clangd", "pyright" , "yamlls", "gopls" , "bashls", "terraformls"}
local servers = { "html", "cssls", "tsserver", "clangd", "pyright", "yamlls", "gopls", "bashls", "terraformls" }
for _, lsp in ipairs(servers) do
lspconfig[lsp].setup {
@ -16,7 +16,7 @@ local util = require "lspconfig/util"
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = {"gopls"},
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
settings = {
@ -29,5 +29,5 @@ lspconfig.gopls.setup {
},
},
}
--
--
-- lspconfig.pyright.setup { blabla}

@ -7,8 +7,8 @@ local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local sources = {
-- webdev stuff
b.formatting.deno_fmt, -- choosed deno for ts/js files cuz its very fast!
b.formatting.prettier.with { filetypes = { "html", "markdown", "css", "yaml", "json"} }, -- so prettier works only on these filetypes
b.formatting.deno_fmt, -- choosed deno for ts/js files cuz its very fast!
b.formatting.prettier.with { filetypes = { "html", "markdown", "css", "yaml", "json" } }, -- so prettier works only on these filetypes
-- Lua
b.formatting.stylua,
@ -17,35 +17,43 @@ local sources = {
b.formatting.clang_format,
-- golang
b.formatting.gofumpt,
b.formatting.goimports_reviser,
b.formatting.golines,
-- Shell
b.formatting.shfmt,
b.diagnostics.shellcheck.with { diagnostics_format = "#{m} [#{c}]" },
-- terraform
b.formatting.terraform_fmt,
b.formatting.gofumpt,
b.formatting.goimports_reviser,
b.formatting.golines,
-- Shell
b.formatting.shfmt,
b.diagnostics.shellcheck.with { diagnostics_format = "#{m} [#{c}]" },
-- terraform
b.formatting.terraform_fmt,
--python
null_ls.builtins.formatting.black,
null_ls.builtins.diagnostics.mypy.with {
extra_args = function()
local virtual = os.getenv "VIRTUAL_ENV" or os.getenv "CONDA_PREFIX" or "/usr"
return { "--python-executable", virtual .. "/bin/python3" }
end,
},
}
null_ls.setup {
debug = true,
sources = sources,
-- auto format on save
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({
-- auto format on save
on_attach = function(client, bufnr)
if client.supports_method "textDocument/formatting" then
vim.api.nvim_clear_autocmds {
group = augroup,
buffer = bufnr,
})
}
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
vim.lsp.buf.format { bufnr = bufnr }
end,
})
end

@ -37,6 +37,21 @@ M.mason = {
-- c/cpp stuff
"clangd",
"clang-format",
--python stff
"black",
"debugpy",
"mypy",
"ruff",
"pyright",
--golang stff
"gopls",
"gofumpt",
"delve",
"revive",
"golines",
"goimports-reviser",
},
}

@ -6,7 +6,7 @@ M.general = {
[";"] = { ":", "enter command mode", opts = { nowait = true } },
},
v = {
[">"] = { ">gv", "indent"},
[">"] = { ">gv", "indent" },
},
}
@ -55,11 +55,29 @@ M.harpoon = {
},
}
-- project Manager
M.projects = {
n = {
["<leader>fp"] = { "<cmd> ProjectMgr<CR>", "Open Projects"}
["<leader>fp"] = { "<cmd> ProjectMgr<CR>", "Open Projects" },
},
}
-- dap
M.dap = {
plugin = true,
n = {
["<leader>db"] = { "<cmd> DapToggleBreakpoint <CR>" },
},
}
M.dap_python = {
plugin = true,
n = {
["<leader>dpr"] = {
function()
require("dap-python").test_method()
end,
},
},
}
return M

@ -142,6 +142,47 @@ local plugins = {
require("core.utils").load_mappings "dap_go"
end,
},
{
"nvim-neotest/nvim-nio",
},
{
"rcarriga/nvim-dap-ui",
dependencies = "mfussenegger/nvim-dap",
config = function()
local dap = require "dap"
local dapui = require "dapui"
dapui.setup()
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
end
end,
},
{
"mfussenegger/nvim-dap",
config = function(_, opts)
require("core.utils").load_mappings "dap"
end,
},
{
"mfussenegger/nvim-dap-python",
ft = "python",
dependencies = {
"mfussenegger/nvim-dap",
"rcarriga/nvim-dap-ui",
"nvim-neotest/nvim-nio",
},
config = function(_, opts)
local path = "~/.local/share/nvim/mason/packages/debugpy/venv/bin/python"
require("dap-python").setup(path)
require("core.utils").load_mappings "dap_python"
end,
},
-- To make a plugin not be loaded
-- {

Loading…
Cancel
Save