Merge branch 'master' into lsp-settings

This commit is contained in:
Dionisio E Alonso 2024-03-23 19:44:07 -03:00
commit b09e254961
29 changed files with 345 additions and 107 deletions

3
clangd/config.yaml Normal file
View File

@ -0,0 +1,3 @@
CompileFlags:
Add: [-Wall, -Wextra, -Wpedantic, -std=c2x]
Compiler: gcc # Until clang supports the whole C23 standard

View File

@ -1,10 +1,37 @@
(custom-set-variables
'(custom-enabled-themes '(tango-dark))
'(display-line-numbers-type 'relative)
'(column-number-mode t)
'(truncate-lines t)
'(tool-bar-mode nil))
(custom-set-faces
'(default ((t (:family "Iosevka Curly Slab" :foundry "UKWN" :slant normal :weight regular :height 113 :width normal)))))
(load-theme 'tango-dark t)
(setq display-line-numbers-type 'relative)
(save-place-mode 1)
(setq column-number-mode t)
(setq-default truncate-lines t)
(tool-bar-mode -1)
(set-face-attribute 'default nil
:family "Iosevka Curly Slab"
:slant 'normal
:weight 'regular
:height 113
:width 'normal)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(add-hook 'prog-mode-hook 'eglot-ensure) ; Requires LSP servers in PATH
(setq-default eglot-workspace-configuration
'(:pylsp (:configurationSources ["flake8"]
:plugins (:flake8 (:enabled t)
:pylint (:enabled t
:executable "pylint")
:pylsp_mypy (:overrides [t "--no-pretty"])
:pycodestyle (:enabled :json-false)
:pyflakes (:enabled :json-false)))))
(when window-system (set-frame-size (selected-frame) 85 60))
; After dealing with some nice defaults setup packages
(with-eval-after-load 'package
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))
(use-package vscode-dark-plus-theme
:ensure t
:config
(load-theme 'vscode-dark-plus t))
(use-package rust-mode :ensure t)
(use-package haskell-mode :ensure t)

View File

@ -2,3 +2,5 @@ if status is-interactive
# Commands to run in interactive sessions can go here
[ -r $HOME/.sh.d/aliases ] && . $HOME/.sh.d/aliases
end
set -gx EDITOR nvim

4
flake8
View File

@ -1,4 +1,6 @@
# Not in official documentation, but it can be placed in $XDG_CONFIG_HOME
# This does not work from $XDG_CONFIG_HOME, but python-lsp-server looks for it
# in that location anyways. This is explicitly achieved here:
# https://github.com/python-lsp/python-lsp-server/blob/fc2851a/pylsp/config/flake8_conf.py#L52
[flake8]
max-line-length = 79
#extend-ignore = E501, W293, W391, E402, W503 # Those are also checked by pylint

1
fourmolu.yaml Normal file
View File

@ -0,0 +1 @@
column-limit: 80

View File

@ -10,3 +10,5 @@
lg = less -S
[tar "tar.xz"]
command = xz -c
[blame]
date = relative

View File

@ -1,19 +1,19 @@
[mypy]
ignore_missing_imports = True
show_column_numbers = true
pretty = true
ignore_missing_imports = true
follow_imports = silent
show_column_numbers = True
show_error_codes = True
warn_unused_configs = True
allow_any_generics = False
allow_subclassing_any = False
allow_untyped_calls = False
allow_untyped_defs = False
allow_incomplete_defs = False
check_untyped_defs = True
allow_untyped_decorators = False
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
implicit_reexport = False
warn_unused_configs = true
allow_any_generics = false
allow_subclassing_any = false
allow_untyped_calls = false
allow_untyped_defs = false
allow_incomplete_defs = false
check_untyped_defs = true
allow_untyped_decorators = false
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
implicit_reexport = false

View File

@ -1,5 +1,5 @@
current_width = 777
current_height = 1000
current_width = 782 # for Iosevka Curly Slab 11.5; 96col
current_height = 1044
is_maximized = false
show_sidebar = false
sidebar_width = 174

View File

@ -1,3 +1,5 @@
; extends
; Correct coloring group for class keyword:
; https://github.com/nvim-treesitter/nvim-treesitter/pull/3177#issuecomment-1186027468
"class" @keyword.function

View File

@ -1,4 +1,4 @@
call rpcnotify(1, 'Gui', 'Font', 'Iosevka Curly Slab 8.4')
call rpcnotify(1, 'Gui', 'Font', 'Iosevka Curly Slab 11.5')
" Iosevka customizations: Haskell ligations; JetBrains Mono Style variant;
" cv-a-single-storey-serifed; cv-g-double-storey-open;
" cv-lig-ltgteq-slanted; cv-tilde-high; cv-underscore-low; cv-dollar-open;

View File

@ -52,6 +52,13 @@ command -nargs=? Terminal rightbelow 16split +terminal\ <args>
nnoremap <silent> <leader>tt :rightbelow 16split +terminal<cr>
tnoremap <Esc> <C-\><C-n><C-w>p
set foldcolumn=auto:4
set foldlevelstart=99
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set foldtext=""
set nofoldenable
" Theming
let g:aldmeris_transparent = v:true
let g:aldmeris_termcolors = 'tango'

View File

@ -1,3 +1,9 @@
if vim.fn.has("nvim-0.10") == 0 then -- Remove block for v0.10+ release. Covered by vim.diagnostic.config()
vim.fn.sign_define("DiagnosticSignError", { text="", texthl="DiagnosticSignError", linehl="", numhl="" })
vim.fn.sign_define("DiagnosticSignWarn", { text="", texthl="DiagnosticSignWarn", linehl="", numhl="" })
vim.fn.sign_define("DiagnosticSignInfo", { text="", texthl="DiagnosticSignInfo", linehl="", numhl="" })
vim.fn.sign_define("DiagnosticSignHint", { text="", texthl="DiagnosticSignHint", linehl="", numhl="" })
end
vim.diagnostic.config({
signs = {
text = {
@ -5,31 +11,26 @@ vim.diagnostic.config({
[vim.diagnostic.severity.WARN] = "",
[vim.diagnostic.severity.INFO] = "",
[vim.diagnostic.severity.HINT] = "",
}
}
},
},
update_in_insert = true,
virtual_text = { source = "if_many", spacing = 24 },
float = { source = "if_many", border = "rounded" },
})
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", { clear = false }),
callback = function(args)
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
vim.api.nvim_create_autocmd("CursorHoldI", {
callback = function()
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
group = vim.api.nvim_create_augroup("Diagnostics", { clear = true }),
buffer = bufnr,
callback = function()
vim.diagnostic.open_float({ focusable = false, header = "" })
end
})
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
update_in_insert = true,
virtual_text = { source = "if_many", spacing = 24 },
}
)
vim.diagnostic.config({
float = { source = "if_many", border = "rounded" }
vim.diagnostic.open_float({
focusable = false,
header = "",
scope = "cursor",
})
end,
})
end,
})

View File

@ -16,4 +16,6 @@ lspconfig.fortls.setup(vim.tbl_deep_extend("error", default_opts, opts.fortls))
require("lsp.keymaps")
require("lsp.completion")
require("lsp.diagnostics")
require("lsp.inlay")
if vim.lsp.inlay_hint then -- Remove condition for v0.10+ release
require("lsp.inlay")
end

View File

@ -11,7 +11,9 @@ vim.api.nvim_create_autocmd("LspAttach", {
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function() vim.pretty_print(vim.lsp.buf.list_workspace_folders()) end, opts)
vim.keymap.set("n", "<space>wl", function()
vim.print(vim.lsp.buf.list_workspace_folders())
end, opts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)

View File

@ -1,29 +1,3 @@
--if vim.fn.exists(":PylspInstall") then
-- vim.cmd("PylspInstall pylsp-mypy")
--end
-- https://github.com/williamboman/mason.nvim/discussions/908
local pylsp = require("mason-registry").get_package("python-lsp-server")
pylsp:on("install:success", function ()
local mason_package_path = function(package)
local path = vim.fn.resolve(vim.fn.stdpath("data") .. "/mason/packages/" .. package)
return path
end
local path = mason_package_path("python-lsp-server")
local command = path .. "/venv/bin/python"
local install_cmd = { command, "-m", "pip", "install" }
local pylsp_plugins = { "python-lsp-ruff", "pylsp-mypy" }
vim.schedule(function()
vim.fn.system(vim.list_extend(install_cmd, pylsp_plugins))
end)
local flake8_plugins = { "flake8-pyproject", "flake8-pylint" }
vim.schedule(function()
vim.fn.system(vim.list_extend(install_cmd, flake8_plugins))
end)
end)
local opts = {}
opts.pylsp = require("lsp.server_settings.pylsp")
opts.hls = require("lsp.server_settings.hls")

View File

@ -1,3 +1,29 @@
--if vim.fn.exists(":PylspInstall") then
-- vim.cmd("PylspInstall pylsp-mypy")
--end
-- https://github.com/williamboman/mason.nvim/discussions/908
local pylsp = require("mason-registry").get_package("python-lsp-server")
pylsp:on("install:success", function ()
local mason_package_path = function(package)
local path = vim.fn.resolve(vim.fn.stdpath("data") .. "/mason/packages/" .. package)
return path
end
local path = mason_package_path("python-lsp-server")
local command = path .. "/venv/bin/python"
local install_cmd = { command, "-m", "pip", "install" }
local pylsp_plugins = { "python-lsp-ruff", "pylsp-mypy" }
vim.schedule(function()
vim.fn.system(vim.list_extend(install_cmd, pylsp_plugins))
end)
local flake8_plugins = { "flake8-pyproject", "flake8-pylint" }
vim.schedule(function()
vim.fn.system(vim.list_extend(install_cmd, flake8_plugins))
end)
end)
local pylsp_settings = {
configurationSources = { "flake8" }, -- tool's config files to override settings from
plugins = {
@ -9,32 +35,32 @@ local pylsp_settings = {
jedi_symbols = { enabled = false },
-- Linting
ruff = { enabled = true }, -- Settings come from $XDG_CONFIG_HOME/ruff/ruff.toml
flake8 = { enabled = true },
pylint = { enabled = true },
pylsp_mypy = { enabled = true },
pylsp_mypy = { overrides = { true, "--no-pretty" } },
pycodestyle = { enabled = false }, -- covered in flake8
pyflakes = { enabled = false }, -- covered in flake8
-- mccabe = { enabled = false }, -- not covered in flake8 by default; PyLSP doesn't handle the option
},
}
local venv_dir = vim.fn.finddir(".venv/", vim.fn.expand("%:p:h") .. ";")
local python_exec = vim.fn.findfile("python3", venv_dir .. "/bin;")
if venv_dir ~= "" and python_exec ~= "" then
local venv_dir = vim.env.VIRTUAL_ENV
if venv_dir ~= nil then
local python_exec = vim.fn.findfile("python", venv_dir .. "/bin;")
if python_exec ~= "" then
pylsp_settings.plugins.jedi = {environment = python_exec}
end
local flake8_exec = vim.fn.findfile("flake8", venv_dir .. "/bin;")
if flake8_exec ~= "" then
end
local flake8_exec = vim.fn.findfile("flake8", venv_dir .. "/bin;")
if flake8_exec ~= "" then
pylsp_settings.plugins.flake8.executable = flake8_exec
end
local pylint_exec = vim.fn.findfile("pylint", venv_dir .. "/bin;")
if pylint_exec ~= "" then
end
local pylint_exec = vim.fn.findfile("pylint", venv_dir .. "/bin;")
if pylint_exec ~= "" then
pylsp_settings.plugins.pylint.executable = pylint_exec
end
local mypy_exec = vim.fn.findfile("mypy", venv_dir .. "/bin;")
if mypy_exec ~= "" or python_exec ~= "" then
end
local mypy_exec = vim.fn.findfile("mypy", venv_dir .. "/bin;")
if mypy_exec ~= "" or python_exec ~= "" then
pylsp_settings.plugins.pylsp_mypy.overrides = {"--python-executable", python_exec, true}
end
end
return { settings = { pylsp = pylsp_settings } }

View File

@ -3,7 +3,16 @@
[tool.pylint.format]
max-line-length = 79
[tool.pylint."messages control"]
#disable = [
# "missing-docstring", "invalid-name", "redefined-outer-name", "logging-format-interpolation",
# "line-too-long", "trailing-whitespace", "trailing-newlines", "wrong-import-position",
#] # Covered in flake8
disable = [
# Covered in flake8 according to https://pylint.rtfd.io/en/latest/faq.html#which-messages-should-i-disable-to-avoid-duplicates-if-i-use-other-popular-linters
"unnecessary-semicolon", "bad-indentation", "bare-except", # pycodestyle
"unnecessary-negation", "singleton-comparison", "line-too-long", # pycodestyle
"trailing-whitespace", "missing-final-newline", "trailing-newlines", # pycodestyle
"multiple-statements", "wrong-import-position", # pycodestyle
"undefined-variable", "unused-import", "unused-variable", # pyflakes
"too-many-branches", # mccabe
# other stuff
# Unfold "missing-docstring" (https://pylint.rtfd.io/en/latest/user_guide/messages/convention/missing-docstring.html)
"missing-module-docstring", "missing-class-docstring", "missing-function-docstring",
]

3
pytest.ini Normal file
View File

@ -0,0 +1,3 @@
[pytest]
addopts = --pdbcls=IPython.terminal.debugger:TerminalPdb --tb=short --quiet
--disable-pytest-warnings --no-cov

View File

@ -1,4 +1,5 @@
line-length = 79
[lint]
extend-select = [
"E", "W", "F", "C90", # Pycodestyle + Pyflakes + McCabe = Flake8
"PL", # Pylint

View File

@ -2,5 +2,6 @@ alias ls="ls --color=auto"
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"
alias vi=nvim
alias grep="grep --color=auto"
alias less="less --LONG-PROMPT --LINE-NUMBERS"

4
templates/Makefile Normal file
View File

@ -0,0 +1,4 @@
-include base.mk
TARGET = appname
all: $(TARGET)

16
templates/README.rst Normal file
View File

@ -0,0 +1,16 @@
Templates
=========
This directory bundles templates of config files for different kind of
projects.
The purpose of files here, is that for these tools there is no global/user
configuration that can be used as a common base, but instead, these tools can
only be configured per-project adding config files to the base dir of the
corresponding project.
Therefore, here are a bunch of files that with minimum or non changes can be
copied into project's base directories for configuring them.
There are templates for tools for different technologies. Depending on
technologies used in each project is which files should be copied.

8
templates/_clang-format Normal file
View File

@ -0,0 +1,8 @@
BasedOnStyle: llvm
IndentWidth: 4
TabWidth: 4
UseTab: ForIndentation
BreakBeforeBinaryOperators: NonAssignment
SpaceAfterCStyleCast: true
AlignTrailingComments: false
SpacesBeforeTrailingComments: 2

View File

@ -0,0 +1,73 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-toml
- id: check-yaml
exclude: .chart/
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
args: [--config=./backoffice/ceg/pyproject.toml]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [--toml-config=./pyproject.toml]
additional_dependencies: [Flake8-pyproject]
language: system # don't commit!!
- repo: https://github.com/PyCQA/pylint
rev: v3.0.3
hooks:
- id: pylint
args: [--rcfile=./pyproject.toml]
# disabled plugins: pylint.extensions.mccabe
exclude: tests|tests/input|tests/extensions/data|tests/regrtest_data|tests/data|doc
language: system # don't commit!!
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
args: [--show-column-numbers, --pretty, --ignore-missing-imports, --follow-imports=silent]
additional_dependencies: [types-all]
#exclude: migrations/
language: system # don't commit!!
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py311-plus]
args: [--py37-plus]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: [--check-only, --line-length=120, --diff]
args: [--check-only, --profile=django, --line-length=120, --diff, --py=37, --src=ceg/]
- repo: https://github.com/jazzband/pip-tools
rev: 7.3.0
hooks:
- id: pip-compile
name: pip-compile requirements.txt
files: ^requirements\.(in|txt)$
args: [requirements.txt]
- id: pip-compile
name: pip-compile requirements-dev.in
files: ^requirements-dev\.(in|txt)$
args: [requirements-dev.in]
- id: pip-compile
name: pip-compile requirements-lint.in
files: ^requirements-lint\.(in|txt)$
args: [requirements-lint.in]

6
templates/base.mk Normal file
View File

@ -0,0 +1,6 @@
BUILD ?= debug
CFLAGS ?= -Wall -Wextra -std=c23 -Wpedantic
cflags.debug = -g -DDEBUG
cflags.release = -O2 -Werror
CFLAGS += ${cflags.${BUILD}}

53
templates/pyproject.toml Normal file
View File

@ -0,0 +1,53 @@
[tool.ruff]
line-length = 120
[tool.ruff.lint]
extend-select = [
"E", "W", "F", # Pycodestyle + Pyflakes - McCabe (C90) = Flake8
"PL", # Pylint
]
extend-ignore = [
"PLW2901", "PLR2004", # From Pylint plugin, not enabled by default
"PLR0912", # Already covered: mccabe (C90)
]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
[tool.flake8]
# This category requires “Flake8-pyproject” plugin to take effect
max-line-length = 120
per-file-ignores = [
"__init__.py:F401",
]
[tool.pylint.format]
max-line-length = 120
[tool.pylint."messages control"]
disable = [
# Covered in flake8 according to https://pylint.rtfd.io/en/latest/faq.html#which-messages-should-i-disable-to-avoid-duplicates-if-i-use-other-popular-linters
"unnecessary-semicolon", "bad-indentation", "bare-except", # pycodestyle
"unnecessary-negation", "singleton-comparison", "line-too-long", # pycodestyle
"trailing-whitespace", "missing-final-newline", "trailing-newlines", # pycodestyle
"multiple-statements", "wrong-import-position", # pycodestyle
"undefined-variable", "unused-import", "unused-variable", # pyflakes
"too-many-branches", # mccabe
# other stuff
"missing-module-docstring", "missing-class-docstring", "missing-function-docstring",
#"logging-format-interpolation",
#"redefined-outer-name", # Pytest fixtures in tests
#"invalid-name", # Class-attributes in Django-commands (.help)
]
[tool.mypy]
show_column_numbers = true
pretty = true
ignore_missing_imports = true
follow_imports = "silent"
[tool.pytest.ini_options]
addopts = """
--pdbcls=IPython.terminal.debugger:TerminalPdb --tb=short --quiet
--disable-pytest-warnings --no-cov
"""
log_level = "INFO"
python_files = ["*_tests.py", "tests.py"]

View File

@ -6,10 +6,10 @@
// https://microsoft.github.io/vscode-codicons/dist/codicon.html
// Unicode symbols taken from VS Code source code (search symbol- entries):
// https://github.com/microsoft/vscode/blob/main/src/vs/base/common/codicons.ts#L113-L556
"diagnostic.errorSign": "",
"diagnostic.warningSign": "",
"diagnostic.infoSign": "",
"diagnostic.hintSign": "",
"diagnostic.errorSign": "",
"diagnostic.warningSign": "",
"diagnostic.infoSign": "",
"diagnostic.hintSign": "",
"suggest.completionItemKindLabels": {
"keyword": "",
@ -40,14 +40,17 @@
"default": ""
},
// coc-diagnostic
"diagnostic-languageserver.filetypes": {
"python": ["flake8", "pylint", "mypy", "pycodestyle"]
},
"diagnostic-languageserver.linters": {
"pycodestyle": {
"sourceName": "pycodestyle",
"command": "pycodestyle"
"languageserver": {
"haskell": {
"command": "haskell-language-server-wrapper",
"args": ["--lsp"],
"rootPatterns": ["*.cabal", "stack.yaml", "cabal.project", "package.yaml", "hie.yaml"],
"filetypes": ["haskell", "lhaskell"],
"settings": {
"haskell": {
"formattingProvider": "formolu"
}
}
}
}
}

View File

@ -1,5 +1,8 @@
" Default extensions
let g:coc_global_extensions = ["coc-diagnostic", "coc-jedi", "coc-clangd"]
let g:coc_global_extensions = [
\ "coc-diagnostic",
\ "@yaegassy/coc-ruff", "@yaegassy/coc-pylsp", "@yaegassy/coc-mypy", "coc-clangd", "coc-rust-analyzer"
\ ]
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)

View File

@ -45,6 +45,13 @@ command -nargs=? Terminal rightbelow terminal ++rows=16 <args>
nnoremap <silent> <leader>tt :rightbelow terminal ++rows=16<CR>
tnoremap <Esc> <C-\><C-n><C-w>p
set foldcolumn=4
set foldlevelstart=99
set foldmethod=expr
set foldexpr=coc#util#refactor_foldlevel(v:lnum)
set foldtext=coc#util#refactor_fold_text(v:foldstart)
set nofoldenable
" Theming
let g:aldmeris_transparent = v:true
let g:aldmeris_termcolors = 'tango'