diff --git a/ftplugin/query.lua b/ftplugin/query.lua new file mode 100644 index 0000000..319e2e5 --- /dev/null +++ b/ftplugin/query.lua @@ -0,0 +1 @@ +require("helpers").set_tab(2) diff --git a/init.lua b/init.lua index 8294297..74e3049 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,7 @@ require("base") -require("specifics") -require("plugins") -require("buffer_tools").init() + +if not vim.g.vscode then + require("specifics") + require("plugins") + require("buffer_tools").init() +end diff --git a/lua/base.lua b/lua/base/init.lua similarity index 87% rename from lua/base.lua rename to lua/base/init.lua index ea9e237..f230d57 100644 --- a/lua/base.lua +++ b/lua/base/init.lua @@ -1,7 +1,15 @@ -- SHOULD NOT CONTAIN ANY SETTINGS RELATED TO EXTERNAL PLUGINS -- OR CUSTOM CODE YOU YOURSELF WROTE. -local map = require("helpers").map +local function map(mode, lhs, rhs, opts) + local default_opts = { noremap = true } + if opts then + default_opts = vim.tbl_extend("force", default_opts, opts) + end + --vim.api.nvim_set_keymap(mode, lhs, rhs, default_opts) + vim.keymap.set(mode, lhs, rhs, default_opts) +end + local opt = vim.opt local g = vim.g @@ -95,8 +103,6 @@ silent_map("n", "", ":lua require('dynamic_tab').shift_tab()") opt.autoindent = true opt.autoread = true -opt.cursorcolumn = true -opt.cursorline = true opt.expandtab = true opt.hlsearch = true opt.ignorecase = true @@ -131,10 +137,16 @@ opt.foldlevelstart = 10 opt.mouse = "" -vim.cmd([[hi CursorLine cterm=NONE ctermbg=darkgray ctermfg=white]]) vim.cmd([[au BufRead,BufNewFile .env.* set filetype=sh]]) vim.cmd([[au BufRead,BufNewFile Dockerfile.* set filetype=dockerfile]]) -vim.cmd([[au BufRead,BufNewFile *.html set filetype=html]]) +--vim.cmd([[au BufRead,BufNewFile *.html set filetype=html]]) -- redo folds on write vim.cmd([[au BufWrite * normal zx]]) + +-- vscode doesn't like cursorline stuff +if not vim.g.vscode then + vim.cmd([[hi CursorLine cterm=NONE ctermbg=darkgray ctermfg=white]]) + opt.cursorcolumn = true + opt.cursorline = true +end diff --git a/lua/plugins/config.lua b/lua/plugins/config.lua index f303f02..843837a 100644 --- a/lua/plugins/config.lua +++ b/lua/plugins/config.lua @@ -185,14 +185,7 @@ end function M.nvim_treesitter() local highlight_disable = { cpp = true, - --javascript = true, } - --local rainbow_disable = vim.tbl_extend("force", highlight_disable, { - -- html = true, - -- typescript = true, - -- tsx = true, - -- svelte = true, - --}) local too_many_lines = function(bufnr) return vim.api.nvim_buf_line_count(bufnr) > 5000 @@ -211,22 +204,14 @@ function M.nvim_treesitter() "css", "html", "query", + "bash", }, highlight = { enable = true, disable = function(lang, bufnr) return highlight_disable[lang] or too_many_lines(bufnr) end, - --additional_vim_regex_highlighting = { "htmldjango", "html" }, }, - --rainbow = { - -- enable = true, - -- disable = function(lang, bufnr) - -- return rainbow_disable[lang] or too_many_lines(bufnr) - -- end, - -- extended_mode = false, - -- max_file_lines = nil, - --}, indent = { enable = true, }, @@ -241,37 +226,20 @@ function M.nvim_treesitter() }, }) - local version = vim.version() - if version.api_level ~= 9 then + if vim.version().api_level ~= 9 then vim.opt.foldmethod = "expr" vim.opt.foldexpr = "nvim_treesitter#foldexpr()" end - --local htmldjango_path = "/home/guy/code/treesitter/tree-sitter-htmldjango-myown" - --if vim.fn.filereadable(htmldjango_path .. "/src/parser.c") then - -- -- 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" + -- potentially load .so from this repo + --print(debug.getinfo(2, "S").source:sub(2)) + --vim.fn.getchar() - -- -- new + --local shared_lib = "/home/guy/code/treesitter/tree-sitter-htmldjango-myown/src/parser.so" + --if vim.fn.filereadable(shared_lib) == 1 then -- vim.treesitter.language.add("htmldjango", { - -- install_info = { - -- url = htmldjango_path, - -- files = { "src/parser.c" }, - -- requires_generate_from_grammar = true, - -- }, - -- filetype = "html", + -- path = shared_lib, -- }) - -- vim.treesitter.language.register("htmldjango", "html") --end end @@ -328,6 +296,12 @@ function M.null_ls() -- elixir null_ls.builtins.diagnostics.credo, null_ls.builtins.formatting.mix, + + -- zig + null_ls.builtins.formatting.zigfmt, + + -- c_sharp + null_ls.builtins.formatting.csharpier, } null_ls.setup({ sources = sources, @@ -433,6 +407,18 @@ function M.lsp_zero() root_dir = lsp_config_defaults().root_dir, }) + lsp.configure("tsserver", { + settings = { + implicitProjectConfiguration = { + checkJs = true, + }, + }, + }) + + lsp.configure("html", { + filetypes = { "html", "htmldjango" }, + }) + -- (Optional) Configure lua language server for neovim lsp.nvim_workspace() @@ -443,4 +429,8 @@ function M.undotree() nmap("u", ":UndotreeToggle") end +function M.luasnip() + require("luasnip").filetype_extend("htmldjango", { "html" }) +end + return M diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 9048e9a..031c92d 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -16,6 +16,7 @@ config.nvim_treesitter() config.rnvimr() config.tokyonight() config.gitsigns() +config.luasnip() config.lsp_zero() config.null_ls() config.undotree() diff --git a/queries/htmldjango/highlights.scm b/queries/htmldjango/highlights.scm index 8594da2..c0a7bc7 100644 --- a/queries/htmldjango/highlights.scm +++ b/queries/htmldjango/highlights.scm @@ -10,26 +10,30 @@ "}}" ] @comment +(django_empty_comment) @comment (string) @string - (integer) @number (float) @float - (true) @boolean (false) @boolean (none) @boolean - (identifier) @variable -(attribute object: (primary_expression) @variable) -(attribute attribute: (identifier) @property) -(tag_statement tag_name: (identifier) @keyword) +(attribute object: + (primary_expression) @variable) + +(attribute attribute: + (identifier) @property) + +(tag_statement tag_name: + (identifier) @function) (tag_statement tag_argument: - (keyword_argument keyword_name: - ((identifier) @parameter))) + (keyword_argument keyword_name: + ((identifier) @parameter))) -(filter filter_name: ((identifier) @function)) +(filter filter_name: + ((identifier) @function)) [ "for" @@ -39,6 +43,8 @@ "and" "is" "as" + "endfor" + "endif" + "else" + "empty" ] @keyword - -;(content) @html diff --git a/queries/htmldjango/injections.scm b/queries/htmldjango/injections.scm new file mode 100644 index 0000000..f082273 --- /dev/null +++ b/queries/htmldjango/injections.scm @@ -0,0 +1,3 @@ +((content) @injection.content + (#set! injection.language "html") + (#set! injection.combined)) diff --git a/queries/python/injections.scm b/queries/python/injections.scm index aac337f..bee3b54 100644 --- a/queries/python/injections.scm +++ b/queries/python/injections.scm @@ -1,18 +1,15 @@ (type (string (string_content) @python)) +(type (subscript (string (string_content) @python))) + ((assignment - (type - (identifier) @_type) - (string - (string_content) @python)) + (type (identifier) @_type) + (string (string_content) @python)) (#eq? @_type "TypeAlias")) ((assignment - (type - (string - (string_content) @_type)) - (string - (string_content) @python)) + (type (string (string_content) @_type)) + (string (string_content) @python)) (#eq? @_type "TypeAlias")) (class_definition @@ -23,3 +20,18 @@ (((string (string_content) @python) @_str) (#match? @_str "^r.*$")) + +((call + (identifier) @_function + (argument_list + (string + (string_content) @python))) +(#any-of? @_function "cast" "NewType" "TypeVar" "TypedDict")) + +; Too slow +;((call +; (identifier) @_function +; (argument_list +; (string +; (string_content) @htmldjango))) +;(#eq? @_function "Template"))