zenbones-theme / zenbones.nvim

🪨 A collection of contrast-based Vim/Neovim colorschemes
MIT License
714 stars 49 forks source link

lush.lua:55: 'bg' is not a valid color" #87

Closed nalzok closed 2 years ago

nalzok commented 2 years ago

I got the following error on startup

NnnVertSplit could not be applied, nvim returned an error: "...share/nvim/site/pack/packer/start/lush.nvim/lua/lush.lua:55: 'bg' is
not a valid color", (attributes given: {
  fg = "bg"
})
NvimTreeVertSplit could not be applied, nvim returned an error: "...share/nvim/site/pack/packer/start/lush.nvim/lua/lush.lua:55: 'bg
' is not a valid color", (attributes given: {
  fg = "bg"
})

I guess these two lines are probably the culprit? You may also want to look at light.lua due to the same issue.

https://github.com/mcchrish/zenbones.nvim/blob/main/lua/zenbones/specs/dark.lua#L366 https://github.com/mcchrish/zenbones.nvim/blob/main/lua/zenbones/specs/dark.lua#L385

mcchrish commented 2 years ago

Hey @nalzok, sorry for the late response. What's the steps to reproduce these errors?

"bg" is a valid value, and it might be related to an error I saw during testing lush v2: https://github.com/rktjmp/lush.nvim/pull/88#issuecomment-1124374418

nalzok commented 2 years ago

Here is my full configuration file. I will do a bisect to locate the specific line which causes the error if/when I can find some time (or maybe you can spot the problem with your naked eye?). To reproduce the error, store the file in ~/.config/nvim/init.lua, install packer, and run :PackerInstall.

-- Adapted from
-- https://github.com/nvim-lua/kickstart.nvim/blob/master/init.lua

-- Install packer
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'

if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
  vim.fn.execute('!git clone https://github.com/wbthomason/packer.nvim ' .. install_path)
end

vim.cmd [[
augroup Packer
autocmd!
autocmd BufWritePost init.lua PackerCompile
augroup end
]]

local use = require('packer').use
require('packer').startup(function()
  -- Package manager
  use 'wbthomason/packer.nvim'
  -- Git commands in nvim
  use 'tpope/vim-fugitive'
  -- "gc" to comment visual regions/lines
  use 'numToStr/Comment.nvim'
  -- Enhancing in-buffer search
  use 'junegunn/vim-slash'
  -- Automatic tags management
  -- -- use 'ludovicchabant/vim-gutentags'
  -- UI to select things (files, grep results, open buffers...)
  use { 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/plenary.nvim' } }
  use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }
  use { 'nvim-telescope/telescope-ui-select.nvim' }
  use { 'mcchrish/zenbones.nvim', requires = 'rktjmp/lush.nvim' }
  use 'nvim-lualine/lualine.nvim'
  -- Display interactive vertical scrollbars
  use 'dstein64/nvim-scrollview'
  -- Add git related info in the signs columns and popups
  use { 'lewis6991/gitsigns.nvim', requires = { 'nvim-lua/plenary.nvim' } }
  -- Highlight, edit, and navigate code using a fast incremental parsing library
  use 'nvim-treesitter/nvim-treesitter'
  -- Highlight definitions, navigation and rename powered by nvim-treesitter
  use 'nvim-treesitter/nvim-treesitter-textobjects'
  -- trouble.nvim
  use {
    "folke/trouble.nvim",
    config = function()
      require("trouble").setup {
        icons = false,
        fold_open = "v", -- icon used for open folds
        fold_closed = ">", -- icon used for closed folds
        indent_lines = false, -- add an indent guide below the fold icons
        signs = {
          -- icons / text used for a diagnostic
          error = "error",
          warning = "warn",
          hint = "hint",
          information = "info"
        },
        use_diagnostic_signs = false -- enabling this will use the signs defined in your lsp client
      }
    end
  }

  use 'neovim/nvim-lspconfig' -- Collection of configurations for built-in LSP client
  use 'williamboman/nvim-lsp-installer'

  use { 'f3fora/nvim-texlabconfig',
        config = function()
          require('texlabconfig').setup()
        end,
        ft = { 'tex', 'bib' },
        cmd = { 'TexlabInverseSearch' },
  }

  use 'hrsh7th/nvim-cmp' -- Autocompletion plugin
  use 'hrsh7th/cmp-nvim-lsp'
  use 'saadparwaiz1/cmp_luasnip'
  use 'L3MON4D3/LuaSnip' -- Snippets plugin
  use 'jpalardy/vim-slime'

  use 'stevearc/vim-arduino'  -- Vim plugin for compiling, uploading, and debugging arduino sketches
  use 'lervag/vimtex'
end)

--Set highlight on search
vim.o.hlsearch = true

--Disable mouse mode
vim.o.mouse = ''

--Configure Tab as 4 spaces
vim.bo.tabstop = 4
vim.bo.shiftwidth = 4
vim.bo.softtabstop = 4
vim.bo.expandtab = true

--Enable break indent
vim.o.breakindent = true

--Save undo history
vim.opt.undofile = true

--Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true

--Decrease update time
vim.o.updatetime = 250
vim.wo.signcolumn = 'yes'

--Set colorscheme (order is important here)
vim.o.termguicolors = true
vim.o.background = 'dark'
vim.g.seoulbones_transparent_background = true
vim.cmd [[colorscheme seoulbones]]

-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'

--Set statusbar

-- Taken from https://github.com/stevearc/vim-arduino
local function arduino_status()
  local ft = vim.api.nvim_buf_get_option(0, "ft")
  if ft ~= "arduino" then
    return ""
  end
  local line = string.format("[%s]", vim.g.arduino_board)
  if vim.g.arduino_programmer ~= "" then
    line = line .. string.format(" [%s]", vim.g.arduino_programmer)
  end
  local port = vim.fn["arduino#GetPort"]()
  if port ~= 0 then
    line = line .. string.format(" (%s:%s)", port, vim.g.arduino_serial_baud)
  end
  return line
end

require('lualine').setup {
  options = {
    icons_enabled = false,
    theme = 'seoulbones',
    section_separators = '',
    component_separators = '',
  },
  sections = {
    lualine_a = { 'mode' },
    lualine_b = { 'branch', 'diff' },
    lualine_c = { 'filename' },
    lualine_x = { arduino_status, 'diagnostics' },
    lualine_y = { 'location' },
    lualine_z = { 'filetype' },
  },
}

--Enable Comment.nvim
require('Comment').setup()

--Remap space as leader key
vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent = true })
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

--Switch tabs
--vim.api.nvim_set_keymap('n', '<C-q>', ':tabp<cr>', { noremap = true, silent = true })
--vim.api.nvim_set_keymap('n', '<C-e>', ':tabn<cr>', { noremap = true, silent = true })

--Remap for dealing with word wrap
vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap = true, expr = true, silent = true })
vim.api.nvim_set_keymap('n', 'j', "v:count == 0 ? 'gj' : 'j'", { noremap = true, expr = true, silent = true })

-- Highlight on yank
vim.cmd [[
augroup YankHighlight
autocmd!
autocmd TextYankPost * silent! lua vim.highlight.on_yank()
augroup end
]]

-- When editing a file, always jump to the last known cursor position.
-- Don't do it when the position is invalid or when inside an event handler
-- (happens when dropping a file on gvim).
-- Also don't do it when the mark is in the first line, that is the default
-- position when opening a file.
vim.cmd [[
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\   exe "normal! g`\"" |
\ endif
]]

-- Gitsigns
require('gitsigns').setup {
  signs = {
    add = { hl = 'GitGutterAdd', text = '+' },
    change = { hl = 'GitGutterChange', text = '~' },
    delete = { hl = 'GitGutterDelete', text = '_' },
    topdelete = { hl = 'GitGutterDelete', text = '‾' },
    changedelete = { hl = 'GitGutterChange', text = '~' },
  },
}

-- Telescope
local actions = require("telescope.actions")
require('telescope').setup {
  defaults = {
    mappings = {
      i = {
        ["<esc>"] = actions.close,
      },
    },
  },
  extensions = {
    fzf = {
      fuzzy = true,                    -- false will only do exact matching
      override_generic_sorter = true,  -- override the generic sorter
      override_file_sorter = true,     -- override the file sorter
      case_mode = "smart_case",        -- or "ignore_case" or "respect_case"
      -- the default case_mode is "smart_case"
    },
    ["ui-select"] = {
      require("telescope.themes").get_dropdown {
        -- even more opts
      }
    }
  },
}

-- Enable telescope fzf native
require('telescope').load_extension 'fzf'

-- To get fzf loaded and working with telescope, you need to call
-- load_extension, somewhere after setup function:
require("telescope").load_extension("ui-select")

--Add leader shortcuts
vim.api.nvim_set_keymap('n', '<leader><space>', [[<cmd>lua require('telescope.builtin').buffers()<CR>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>sf', [[<cmd>lua require('telescope.builtin').find_files({previewer = false})<CR>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>sb', [[<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<CR>]], { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('n', '<leader>st', [[<cmd>lua require('telescope.builtin').tags()<CR>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>sh', [[<cmd>lua require('telescope.builtin').help_tags()<CR>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>?', [[<cmd>lua require('telescope.builtin').oldfiles()<CR>]], { noremap = true, silent = true })

-- Treesitter configuration
-- Parsers must be installed manually via :TSInstall
require("nvim-treesitter.install").prefer_git = true
require('nvim-treesitter.configs').setup {
  highlight = {
    enable = true, -- false will disable the whole extension
  },
  textobjects = {
    select = {
      enable = true,
      lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
      keymaps = {
        -- You can use the capture groups defined in textobjects.scm
        ['af'] = '@function.outer',
        ['if'] = '@function.inner',
        ['ac'] = '@class.outer',
        ['ic'] = '@class.inner',
      },
    },
    move = {
      enable = true,
      set_jumps = true, -- whether to set jumps in the jumplist
      goto_next_start = {
        [']m'] = '@function.outer',
        [']]'] = '@class.outer',
      },
      goto_next_end = {
        [']M'] = '@function.outer',
        [']['] = '@class.outer',
      },
      goto_previous_start = {
        ['[m'] = '@function.outer',
        ['[['] = '@class.outer',
      },
      goto_previous_end = {
        ['[M'] = '@function.outer',
        ['[]'] = '@class.outer',
      },
    },
    lsp_interop = {
      enable = true,
      border = 'none',
      peek_definition_code = {
        ["<leader>df"] = "@function.outer",
        ["<leader>dF"] = "@class.outer",
      },
    },
  },
}

-- Diagnostic keymaps
vim.api.nvim_set_keymap('n', '<leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', { noremap = true, silent = true }
)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', { noremap = true, silent = true })

-- LSP settings
local on_attach = function(_, bufnr)
  local opts = { noremap = true, silent = true }
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)

  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>so', [[<cmd>lua require('telescope.builtin').lsp_document_symbols()<CR>]], opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>sO', [[<cmd>lua require('telescope.builtin').lsp_workspace_symbols()<CR>]], opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>gw', '<cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>gW', '<cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)

  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]
end

-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

local lsp_installer = require 'nvim-lsp-installer'
lsp_installer.on_server_ready(function(server)
  local opts = {}
  opts.on_attach = on_attach
  opts.capabilities = capabilities
  if server.name == 'sumneko_lua' then
    -- Example custom server
    -- Make runtime files discoverable to the server
    local runtime_path = vim.split(package.path, ';')
    table.insert(runtime_path, 'lua/?.lua')
    table.insert(runtime_path, 'lua/?/init.lua')

    opts.settings = {
      Lua = {
        runtime = {
          -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
          version = 'LuaJIT',
          -- Setup your lua path
          path = runtime_path,
        },
        diagnostics = {
          -- Get the language server to recognize the `vim` global
          globals = { 'vim' },
        },
        workspace = {
          -- Make the server aware of Neovim runtime files
          library = vim.api.nvim_get_runtime_file('', true),
        },
        -- Do not send telemetry data containing a randomized but unique identifier
        telemetry = {
          enable = false,
        },
      },
    }
  elseif server.name == "arduino_language_server" then
    opts.on_new_config = function (config, root_dir)
      root_dir = root_dir -- NOP

      local FQBN = "esp32:esp32:adafruit_feather_esp32s2_tft"
      -- local partial_cmd = server:get_default_options().cmd
      -- local cmd = vim.list_extend(partial_cmd, { "-fqbn", FQBN })
      local cmd = {
        "arduino-language-server",
        "-cli", "/opt/local/bin/arduino-cli",
        "-cli-config", "Library/Arduino15/arduino-cli.yaml",
        "-clangd", "/usr/bin/clangd",
        "-fqbn", FQBN,
      }

      config.cmd = cmd
    end
  elseif server.name == "texlab" then
    opts.settings = {
      texlab = {
        build = {
          args = {"-X", "compile", "%f", "--synctex", "--keep-logs", "--keep-intermediates"},
          executable = "tectonic",
          forwardSearchAfter = true,
          onSave = true,
        },
        forwardSearch = {
          executable = "/Applications/Skim.app/Contents/SharedSupport/displayline",
          args = {"-background", "%l", "%p", "%f"},
        }
      }
    }
  end

  server:setup(opts)
end)

-- luasnip setup
local luasnip = require 'luasnip'

-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
  snippet = {
    expand = function(args)
      luasnip.lsp_expand(args.body)
    end,
  },
  mapping = {
    ['<C-p>'] = cmp.mapping.select_prev_item(),
    ['<C-n>'] = cmp.mapping.select_next_item(),
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.close(),
    ['<CR>'] = cmp.mapping.confirm {
      behavior = cmp.ConfirmBehavior.Replace,
      select = true,
    },
    ['<Tab>'] = function(fallback)
      if cmp.visible() then
        cmp.select_next_item()
      elseif luasnip.expand_or_jumpable() then
        luasnip.expand_or_jump()
      else
        fallback()
      end
    end,
    ['<S-Tab>'] = function(fallback)
      if cmp.visible() then
        cmp.select_prev_item()
      elseif luasnip.jumpable(-1) then
        luasnip.jump(-1)
      else
        fallback()
      end
    end,
  },
  sources = {
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
  },
}

-- Vim-slime setup
vim.g.slime_target = 'tmux'
vim.g.slime_paste_file = vim.fn.tempname()
vim.g.slime_default_config = {
  socket_name = 'default',
  target_pane = '{last}'
}
vim.g.slime_bracketed_paste = true

-- VimTeX setup
vim.g.vimtex_view_method = 'skim'
vim.g.vimtex_compiler_method = 'tectonic'

-- vim: ts=2 sts=2 sw=2 et
vardister commented 2 years ago

I'm getting the exact same error when setting the background to be transparent. Here's what I'm setting up:

set termguicolors

let g:zenbones_transparent_background = v:true
set background=dark
colorscheme zenbones

And here's the error I'm getting after launching Neovim

NnnVertSplit could not be applied, nvim returned an error: "...share/nvim/site/pack/packer/start/lush.nvim/lua/lush.lua:55: 'bg' is not a valid color", (attributes given: {
  fg = "bg"
})
NvimTreeVertSplit could not be applied, nvim returned an error: "...share/nvim/site/pack/packer/start/lush.nvim/lua/lush.lua:55: 'bg' is not a valid color", (attributes given: {
  fg = "bg"
})
mcchrish commented 2 years ago

I think this is an upstream bug on neovim. nvim_set_hl probably does not work properly with transparent background and using bg as a value.

For now, I think we can work around this via https://github.com/mcchrish/zenbones.nvim/pull/88

mcchrish commented 2 years ago

@nalzok thanks for the PR! I extended your solution here: https://github.com/mcchrish/zenbones.nvim/commit/dc48976135b9af11b2d4899b16563131d0dedcf5