Skip to content

Commit 7918a04

Browse files
committed
python-setup-nodeb
1 parent 3338d39 commit 7918a04

File tree

3 files changed

+104
-49
lines changed

3 files changed

+104
-49
lines changed

example.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import http.client
2+
import json
3+
4+
5+
def x(y):
6+
z = y + 1
7+
return z
8+
9+
10+
def fetch(s):
11+
pass
12+
13+
14+
# gd go to definition not working
15+
def fetch_weather_data(latitude, longitude):
16+
conn = http.client.HTTPSConnection("api.open-meteo.com")
17+
endpoint = (
18+
f"/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true"
19+
)
20+
conn.request("GET", endpoint)
21+
response = conn.getresponse()
22+
data = response.read().decode("utf-8")
23+
return json.loads(data)

init.lua

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ require('lazy').setup({
298298
-- Then, because we use the `opts` key (recommended), the configuration runs
299299
-- after the plugin has been loaded as `require(MODULE).setup(opts)`.
300300

301-
{ -- Useful plugin to show you pending keybinds.
301+
{ -- Useful plugin to show you pending keybinds.
302302
'folke/which-key.nvim',
303303
event = 'VimEnter', -- Sets the loading event to 'VimEnter'
304304
opts = {
@@ -379,7 +379,7 @@ require('lazy').setup({
379379
{ 'nvim-telescope/telescope-ui-select.nvim' },
380380

381381
-- Useful for getting pretty icons, but requires a Nerd Font.
382-
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
382+
{ 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
383383
},
384384
config = function()
385385
-- Telescope is a fuzzy finder that comes with a lot of different things that
@@ -487,7 +487,7 @@ require('lazy').setup({
487487
'WhoIsSethDaniel/mason-tool-installer.nvim',
488488

489489
-- Useful status updates for LSP.
490-
{ 'j-hui/fidget.nvim', opts = {} },
490+
{ 'j-hui/fidget.nvim', opts = {} },
491491

492492
-- Allows extra capabilities provided by blink.cmp
493493
'saghen/blink.cmp',
@@ -683,6 +683,22 @@ require('lazy').setup({
683683
-- But for many setups, the LSP (`ts_ls`) will work just fine
684684
-- ts_ls = {},
685685
--
686+
pylsp = {
687+
settings = {
688+
pylsp = {
689+
plugins = {
690+
pyflakes = { enabled = false },
691+
pycodestyle = { enabled = false },
692+
autopep8 = { enabled = false },
693+
yapf = { enabled = false },
694+
mccabe = { enabled = false },
695+
pylsp_mypy = { enabled = false },
696+
pylsp_black = { enabled = false },
697+
pylsp_isort = { enabled = false },
698+
},
699+
},
700+
},
701+
},
686702

687703
lua_ls = {
688704
-- cmd = { ... },
@@ -736,47 +752,6 @@ require('lazy').setup({
736752
end,
737753
},
738754

739-
{ -- Autoformat
740-
'stevearc/conform.nvim',
741-
event = { 'BufWritePre' },
742-
cmd = { 'ConformInfo' },
743-
keys = {
744-
{
745-
'<leader>f',
746-
function()
747-
require('conform').format { async = true, lsp_format = 'fallback' }
748-
end,
749-
mode = '',
750-
desc = '[F]ormat buffer',
751-
},
752-
},
753-
opts = {
754-
notify_on_error = false,
755-
format_on_save = function(bufnr)
756-
-- Disable "format_on_save lsp_fallback" for languages that don't
757-
-- have a well standardized coding style. You can add additional
758-
-- languages here or re-enable it for the disabled ones.
759-
local disable_filetypes = { c = true, cpp = true }
760-
if disable_filetypes[vim.bo[bufnr].filetype] then
761-
return nil
762-
else
763-
return {
764-
timeout_ms = 500,
765-
lsp_format = 'fallback',
766-
}
767-
end
768-
end,
769-
formatters_by_ft = {
770-
lua = { 'stylua' },
771-
-- Conform can also run multiple formatters sequentially
772-
-- python = { "isort", "black" },
773-
--
774-
-- You can use 'stop_after_first' to run the first available formatter from the list
775-
-- javascript = { "prettierd", "prettier", stop_after_first = true },
776-
},
777-
},
778-
},
779-
780755
{ -- Autocompletion
781756
'saghen/blink.cmp',
782757
event = 'VimEnter',
@@ -944,7 +919,7 @@ require('lazy').setup({
944919
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
945920
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
946921
opts = {
947-
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
922+
ensure_installed = { 'python', 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
948923
-- Autoinstall languages that are not installed
949924
auto_install = true,
950925
highlight = {
@@ -973,18 +948,18 @@ require('lazy').setup({
973948
-- Here are some example plugins that I've included in the Kickstart repository.
974949
-- Uncomment any of the lines below to enable them (you will need to restart nvim).
975950
--
976-
-- require 'kickstart.plugins.debug',
951+
require 'kickstart.plugins.debug',
977952
-- require 'kickstart.plugins.indent_line',
978953
-- require 'kickstart.plugins.lint',
979954
-- require 'kickstart.plugins.autopairs',
980-
-- require 'kickstart.plugins.neo-tree',
955+
require 'kickstart.plugins.neo-tree',
981956
-- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps
982957

983958
-- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
984959
-- This is the easiest way to modularize your config.
985960
--
986961
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going.
987-
-- { import = 'custom.plugins' },
962+
{ import = 'custom.plugins' },
988963
--
989964
-- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec`
990965
-- Or use telescope!

lua/custom/plugins/init.lua

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,61 @@
22
-- I promise not to create any merge conflicts in this directory :)
33
--
44
-- See the kickstart.nvim README for more information
5-
return {}
5+
---- Format on save and linters
6+
return {
7+
{
8+
'nvimtools/none-ls.nvim',
9+
dependencies = {
10+
'nvimtools/none-ls-extras.nvim',
11+
'jayp0521/mason-null-ls.nvim', -- ensure dependencies are installed
12+
},
13+
config = function()
14+
local null_ls = require 'null-ls'
15+
local formatting = null_ls.builtins.formatting -- to setup formatters
16+
local diagnostics = null_ls.builtins.diagnostics -- to setup linters
17+
18+
-- list of formatters & linters for mason to install
19+
require('mason-null-ls').setup {
20+
ensure_installed = {
21+
'checkmake',
22+
'prettier', -- ts/js formatter
23+
'eslint_d', -- ts/js linter
24+
'shfmt',
25+
-- 'stylua', -- lua formatter; Already installed via Mason
26+
'ruff', -- Python linter and formatter; Already installed via Mason
27+
},
28+
-- auto-install configured formatters & linters (with null-ls)
29+
automatic_installation = true,
30+
}
31+
32+
local sources = {
33+
diagnostics.checkmake,
34+
formatting.prettier.with { filetypes = { 'html', 'json', 'yaml', 'markdown' } },
35+
formatting.stylua,
36+
formatting.shfmt.with { args = { '-i', '4' } },
37+
formatting.terraform_fmt,
38+
require('none-ls.formatting.ruff').with { extra_args = { '--extend-select', 'I' } },
39+
require 'none-ls.formatting.ruff_format',
40+
}
41+
42+
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})
43+
null_ls.setup {
44+
-- debug = true, -- Enable debug mode. Inspect logs with :NullLsLog.
45+
sources = sources,
46+
-- you can reuse a shared lspconfig on_attach callback here
47+
on_attach = function(client, bufnr)
48+
if client.supports_method 'textDocument/formatting' then
49+
vim.api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
50+
vim.api.nvim_create_autocmd('BufWritePre', {
51+
group = augroup,
52+
buffer = bufnr,
53+
callback = function()
54+
vim.lsp.buf.format { async = false }
55+
end,
56+
})
57+
end
58+
end,
59+
}
60+
end,
61+
},
62+
}

0 commit comments

Comments
 (0)