Selaa lähdekoodia

nvim-treesitter syntax highlightin works

Noah Vogt 3 päivää sitten
vanhempi
sitoutus
abcf0fe011

+ 8 - 6
dot-config/nvim/init.vim

@@ -9,13 +9,13 @@ local ts_runtime = vim.fn.expand("~/.cache/vim/plugged/nvim-treesitter/runtime/"
 vim.opt.runtimepath:prepend(site)
 vim.opt.runtimepath:prepend(ts_runtime)
 
--- Disable built-in LSP mappings (using native LSP in lsp.lua)
+-- Disable built-in LSP mappings
 local builtins = { 'grn', 'gra', 'grr', 'gri', 'grt' }
 for _, k in ipairs(builtins) do
   pcall(vim.keymap.del, 'n', k, { builtin = true })
 end
 
--- Disable built-in commentary to favor tpope/vim-commentary
+-- Disable built-in commentary
 vim.g.loaded_commentary = 1
 EOF
 
@@ -24,7 +24,10 @@ source $XDG_CONFIG_HOME/nvim/general/basic.vim
 " get plugins
 source $XDG_CONFIG_HOME/nvim/vim-plug/plugins.vim
 
-" 3. get plugin configs
+" 3. Load Theme FIRST (important for Treesitter highlight groups)
+source $XDG_CONFIG_HOME/nvim/theme/theme.vim
+
+" 4. get plugin configs
 source $XDG_CONFIG_HOME/nvim/plug-conf/fern.vim
 source $XDG_CONFIG_HOME/nvim/plug-conf/emmet.vim
 source $XDG_CONFIG_HOME/nvim/plug-conf/ctrlp.vim
@@ -36,7 +39,7 @@ source $XDG_CONFIG_HOME/nvim/plug-conf/vcoolor.vim
 source $XDG_CONFIG_HOME/nvim/plug-conf/better-whitespace.vim
 source $XDG_CONFIG_HOME/nvim/plug-conf/vimspector.vim
 
-" 4. Lua configurations
+" 5. Lua configurations (LSP and Treesitter)
 lua require 'treesitter'
 lua require 'lsp'
 lua require 'telescope-conf'
@@ -46,8 +49,7 @@ lua require 'indent-blankline'
 lua require 'whichkey'
 lua require 'colorizer'.setup()
 
-" 5. get theme, keybinds, and autocommands
-source $XDG_CONFIG_HOME/nvim/theme/theme.vim
+" 6. get keybinds and autocommands
 source $XDG_CONFIG_HOME/nvim/keys/bindings.vim
 source $XDG_CONFIG_HOME/nvim/keys/tex-macros.vim
 source $XDG_CONFIG_HOME/nvim/general/auto.vim

+ 28 - 30
dot-config/nvim/lua/treesitter.lua

@@ -1,33 +1,31 @@
-local status, configs = pcall(require, "nvim-treesitter.configs")
-if not status then
-    return
-end
-
-require('nvim-treesitter.install').prefer_git = true
-
-configs.setup {
-    ensure_installed = {
-        "c", "lua", "java", "python", "bash", "html", "css", "javascript",
-        "bibtex", "cmake", "cpp", "latex", "perl", "regex", "toml", "yaml"
-    },
-
-    highlight = {
-        enable = true,
-        -- Merges Treesitter with Regex highlighting for maximum color richness
-        additional_vim_regex_highlighting = { "python" },
-    },
-
-    indent = {
-        enable = true
-    },
+-- Minimal setup (optional but recommended)
+require('nvim-treesitter').setup {
+  install_dir = vim.fn.stdpath('data') .. '/site',
 }
 
--- Force Treesitter to start for major filetypes to bypass any legacy syntax overrides
-vim.api.nvim_create_autocmd({ "FileType" }, {
-    callback = function()
-        local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
-        if lang then
-            pcall(vim.treesitter.start)
-        end
-    end,
+-- Ensure that Treesitter starts on every buffer
+vim.api.nvim_create_autocmd({ "FileType", "BufEnter", "BufWinEnter" }, {
+  callback = function()
+    local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
+    if lang and vim.api.nvim_buf_is_valid(0) then
+      vim.schedule(function()
+        pcall(vim.treesitter.start, 0, lang)
+      end)
+    end
+  end,
+  desc = "Auto-start Treesitter (current main branch)",
 })
+
+-- Manual command to force it if it fails
+vim.api.nvim_create_user_command("TSToggle", function()
+    local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
+    if lang then
+        pcall(vim.treesitter.start, 0, lang)
+        print("Treesitter forced start for " .. lang)
+    else
+        print("No Treesitter parser found for this filetype.")
+    end
+end, {})
+
+-- NOTE: To install parsers you previously had in ensure_installed, run:
+-- :TSInstall c lua java python bash html css javascript bibtex cmake cpp latex perl regex toml yaml

+ 4 - 13
dot-config/nvim/theme/theme.vim

@@ -1,19 +1,16 @@
 lua << EOF
 require('onedark').setup {
-    style = 'darker',
+    style = 'cool', -- 'cool' or 'vibrant' are usually better for TS
     transparent = false,
     term_colors = true,
+    -- Remove overrides to use theme defaults
     code_style = {
         comments = 'italic',
-        keywords = 'none',
-        functions = 'none',
-        strings = 'none',
-        variables = 'none'
     },
 }
 require('onedark').load()
 
--- Force colors for diagnostics and spell check underlines
+-- Force colors for diagnostics and spell check underlines ONLY
 vim.api.nvim_set_hl(0, 'DiagnosticUnderlineError', { undercurl = true, sp = '#ff0000' })
 vim.api.nvim_set_hl(0, 'DiagnosticUnderlineWarn',  { undercurl = true, sp = '#ff8800' })
 vim.api.nvim_set_hl(0, 'SpellBad',   { undercurl = true, sp = '#ffff00' })
@@ -21,16 +18,10 @@ vim.api.nvim_set_hl(0, 'SpellCap',   { undercurl = true, sp = '#ffff00' })
 vim.api.nvim_set_hl(0, 'SpellLocal', { undercurl = true, sp = '#ffff00' })
 vim.api.nvim_set_hl(0, 'SpellRare',  { undercurl = true, sp = '#ffff00' })
 
--- GitSigns with background colors for better visibility
--- (Colors adjusted for onedark darker palette)
+-- GitSigns
 vim.api.nvim_set_hl(0, 'GitSignsAdd', { fg = '#98c379', bg = '#2e3f34' })
 vim.api.nvim_set_hl(0, 'GitSignsChange', { fg = '#e5c07b', bg = '#3e3d32' })
 vim.api.nvim_set_hl(0, 'GitSignsDelete', { fg = '#e06c75', bg = '#3f2e2e' })
-
--- Also color the line numbers for git changes (numhl)
-vim.api.nvim_set_hl(0, 'GitSignsAddNr', { fg = '#98c379', bold = true })
-vim.api.nvim_set_hl(0, 'GitSignsChangeNr', { fg = '#e5c07b', bold = true })
-vim.api.nvim_set_hl(0, 'GitSignsDeleteNr', { fg = '#e06c75', bold = true })
 EOF
 
 let g:airline_theme='onedark'

+ 1 - 1
dot-config/nvim/vim-plug/plugins.vim

@@ -74,7 +74,7 @@ Plug 'csch0/vim-startify-renderer-nerdfont'
 Plug 'tpope/vim-surround'
 
 " use treesitter inside nvim
-Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
+Plug 'nvim-treesitter/nvim-treesitter', { 'branch': 'main', 'do': ':TSUpdate' }
 
 " adds indentation guides to all lines
 Plug 'lukas-reineke/indent-blankline.nvim'