From 407b94c12b4dbc28c74ff5a23fa2a9cbba1d679f Mon Sep 17 00:00:00 2001 From: long Date: Mon, 24 Apr 2023 09:28:57 -0500 Subject: [PATCH] highlighting for python string annotations --- lua/base.lua | 28 ++++++++++++++-------------- lua/plugins/config.lua | 29 ++++++++++++++++++++++------- queries/python/injections.scm | 11 +++++++++++ 3 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 queries/python/injections.scm diff --git a/lua/base.lua b/lua/base.lua index 66cc3bf..ea9e237 100644 --- a/lua/base.lua +++ b/lua/base.lua @@ -58,20 +58,20 @@ map("n", [[\]], ":" .. term_command .. "") map("n", [[|]], ":v" .. term_command .. "") -- line-break movement -silent_map("n", "", "gk") -silent_map("n", "", "gj") -silent_map("n", "", "g") -silent_map("n", "", "g") - -silent_map("v", "", "gk") -silent_map("v", "", "gj") -silent_map("v", "", "g") -silent_map("v", "", "g") - -silent_map("i", "", "gk") -silent_map("i", "", "gj") -silent_map("i", "", "g") -silent_map("i", "", "g") +--silent_map("n", "", "gk") +--silent_map("n", "", "gj") +--silent_map("n", "", "g") +--silent_map("n", "", "g") +-- +--silent_map("v", "", "gk") +--silent_map("v", "", "gj") +--silent_map("v", "", "g") +--silent_map("v", "", "g") +-- +--silent_map("i", "", "gk") +--silent_map("i", "", "gj") +--silent_map("i", "", "g") +--silent_map("i", "", "g") -- half page movement --silent_map("n", "", "M") diff --git a/lua/plugins/config.lua b/lua/plugins/config.lua index 5738a9f..2d9797d 100644 --- a/lua/plugins/config.lua +++ b/lua/plugins/config.lua @@ -230,18 +230,29 @@ function M.nvim_treesitter() local htmldjango_path = "/home/guy/code/treesitter/tree-sitter-htmldjango-myown" if vim.fn.filereadable(htmldjango_path .. "/src/parser.c") then - local parser_config = require("nvim-treesitter.parsers").get_parser_configs() - parser_config.htmldjango = { + -- old + --local parser_config = require("nvim-treesitter.parsers").get_parser_configs() + --parser_config.htmldjango = { + -- install_info = { + -- url = htmldjango_path, + -- files = { "src/parser.c" }, + -- requires_generate_from_grammar = true, + -- }, + -- filetype = "html", + --} + --local ft_to_parser = require("nvim-treesitter.parsers").filetype_to_parsername + --ft_to_parser.html = "htmldjango" + + -- new + vim.treesitter.language.add("htmldjango", { install_info = { url = htmldjango_path, files = { "src/parser.c" }, requires_generate_from_grammar = true, }, filetype = "html", - } - - local ft_to_parser = require("nvim-treesitter.parsers").filetype_to_parsername - ft_to_parser.html = "htmldjango" + }) + vim.treesitter.language.register("htmldjango", "html") end end @@ -380,7 +391,6 @@ function M.null_ls() -- ORDER IN TABLE DETERMINES EXECUTION ORDER local sources = { -- python - null_ls.builtins.diagnostics.mypy, null_ls.builtins.diagnostics.ruff, null_ls.builtins.formatting.black, null_ls.builtins.formatting.ruff.with({ @@ -389,6 +399,7 @@ function M.null_ls() --null_ls.builtins.formatting.isort, --null_ls.builtins.diagnostics.flake8, --null_ls.builtins.diagnostics.djlint, + --null_ls.builtins.diagnostics.mypy, -- js null_ls.builtins.diagnostics.eslint, @@ -482,6 +493,10 @@ function M.lsp_zero() local lsp = require("lsp-zero") lsp.preset("recommended") + lsp.configure("pyright", { + root_dir = lsp_config_defaults().root_dir, + }) + -- (Optional) Configure lua language server for neovim lsp.nvim_workspace() diff --git a/queries/python/injections.scm b/queries/python/injections.scm new file mode 100644 index 0000000..89e054d --- /dev/null +++ b/queries/python/injections.scm @@ -0,0 +1,11 @@ +(type (string (string_content) @python)) + +((assignment + (type (identifier) @_type) + (string (string_content) @python)) +(#eq? @_type "TypeAlias")) + +((assignment + (type (string (string_content) @_type)) + (string (string_content) @python)) +(#eq? @_type "TypeAlias"))