lukas-reineke / headlines.nvim

This plugin adds horizontal highlights for text filetypes, like markdown, orgmode, and neorg.
MIT License
699 stars 28 forks source link

Can't get this plugin to work #43

Closed AndOrangutan closed 1 year ago

AndOrangutan commented 1 year ago

Forgive me if I made a stupid error, but I have been up all night trying to figure this out.

I had this plugin working in my previous config and love it, especially for the code blocks. Can't seem to get it to work. Here is what I am working with: image

The print('test') is a python block. in a python block that I think TS conceals. image

I have tried reinstalling all plugins (deleting all plugins and packer_compile), and minimizing my config to track down the issue. Here are the relevant Lua files:

plugins.lua


------------------------------------------- Autoinstall and autoupdate for Packer --
-------------------------------------------
-- Automatically install packer
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
    PACKER_BOOTSTRAP = fn.system({
        "git",
        "clone",
        "--depth",
        "1",
        "https://github.com/wbthomason/packer.nvim",
        install_path, }) print("Installing packer close and reopen Neovim...")
    vim.cmd([[packadd packer.nvim]])
end

-- Autocommand that reloads neovim whenever you save the plugins.lua file
--vim.cmd([[
--    augroup packer_user_config
--        autocmd!
--        autocmd BufWritePost plugins.lua source <afile> | PackerSync
--    augroup end
--]])

-- Use a protected call so we don't error out on first use
local status_ok, packer = pcall(require, "packer")
if not status_ok then
    return
end

-- Have packer use a popup window
packer.init({
    display = {
        open_fn = function()
            return require("packer.util").float({ border = vim.g.quboid_border })
        end,
    },
})

---------------------
-- Install plugins --
----------------------
return packer.startup(function(use)

    ------------------
    -- Core Plugins --
    -------------------

    -- Startup
    use { 'wbthomason/packer.nvim', -- A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config.
        --opt = true,
    }
    -- Treesitter for highlighting and syntax parsing
    use { 'nvim-treesitter/nvim-treesitter', -- Neovim Treesitter configurations and abstraction layer.
        requires = {
            --"nvim-treesitter/nvim-treesitter-textobjects",  -- TODO: Setup textobjects
            --'lukas-reineke/headlines.nvim',
            "MDeiml/tree-sitter-markdown", -- A markdown grammar for tree-sitter 'RRethy/nvim-treesitter-endwise', -- Wisely add "end" in Ruby, Vimscript, Lua, etc. Tree-sitter aware alternative to tpope's vim-endwise.
            --'JoosepAlviste/nvim-ts-context-commentstring', -- Neovim treesitter plugin for setting the commentstring based on the cursor location in a file.
            --{ 'nvim-treesitter/playground', --Treesitter playground integrated into Neovim
            --    cmd = { 'TSPlaygroundToggle', 'TSHighlightCapturesUnderCursor' }
            --},
        },
        --event = 'BufRead',
        run = ':TSUpdate',
        config = function() require('plugins.nvim-treesitter') end,
    }
    -- Git
    --use { 'preservim/vim-markdown', -- Markdown Vim Mode
    --    ft = 'markdown',
    --    setup = function () require('plugins.vim-markdown') end,
    --}

    use { 'lukas-reineke/headlines.nvim', -- This plugin adds horizontal highlights for text filetypes, like markdown, orgmode, and neorg.
        --ft =  'markdown',
        confug = function ()  require('headlines').setup() end,
    }

end)

nvim-treesitter.lua

require("nvim-treesitter.configs").setup({
    ensure_installed = "all",
    auto_install = true,
    highlight = {
        enable = true,
        --disable = function(lang, buf)
        --    local max_filesize = 100 * 1024 -- 100 KB
        --    local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
        --    if ok and stats and stats.size > max_filesize then
        --        return true
        --    end
        --end,
        additional_vim_regex_highlighting = { "markdown" },
    },
    --indent = { enable = true },
    --context_commentstring = { enable = true },
    --endwise = { enable = true },
    --playground = {
    --    enable = true,
    --    disable = {},
    --    updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
    --    persist_queries = false, -- Whether the query persists across vim sessions
    --    keybindings = {
    --        toggle_query_editor = 'o',
    --        toggle_hl_groups = 'i',
    --        toggle_injected_languages = 't',
    --        toggle_anonymous_nodes = 'a',
    --        toggle_language_display = 'I',
    --        focus_language = 'f',
    --        unfocus_language = 'F',
    --        update = 'R',
    --        goto_node = '<cr>',
    --        show_help = '?',
    --    },
    --},
})

image

Again, my deepest apologies if this is user error, I just can't figure it out for the life of me.

lukas-reineke commented 1 year ago

Can you run :lua print(require('headlines').namespace), to check if the plugin is installed correctly? It should print a number.

If that works, check if treesitter can parse the current buffer with :lua print(vim.inspect(vim.treesitter.get_parser(0, 'markdown'):parse())). This should print something like { <userdata 1> }.

Also check that the highlight groups are defined correctly with :highlight CodeBlock

dmnkf commented 1 year ago

I got the same problem and it turns out that I don't have a markdown parser currently installed. How do I fix this?

## Parser/Features H L F I J
  - typescript     ✓ ✓ ✓ ✓ ✓
  - python         ✓ ✓ ✓ ✓ ✓
  - lua            ✓ ✓ ✓ ✓ ✓
  - yaml           ✓ ✓ ✓ ✓ ✓
  - css            ✓ . ✓ ✓ ✓
  - bash           ✓ ✓ ✓ . ✓
  - vim            ✓ ✓ ✓ . ✓
  - rust           x x ✓ ✓ ✓
  - html           ✓ ✓ ✓ ✓ ✓
  - c              ✓ ✓ ✓ ✓ ✓
  - javascript     ✓ ✓ ✓ ✓ ✓
  - json           ✓ ✓ ✓ ✓ .
  - cpp            ✓ ✓ ✓ ✓ ✓

EDIT: I managed to install it with :TSInstallFromGrammer markdown, however now all is just grey.

Screenshot 2022-11-12 at 16 44 37

here the print for :highlight CodeBlock

Screenshot 2022-11-12 at 16 45 47
lukas-reineke commented 1 year ago

@DM1NIK please open a new issue

wasden commented 1 year ago

try this:

use {
  'lukas-reineke/headlines.nvim',
   after = "nvim-treesitter",
   config = function()
       require('headlines').setup()
    end,
}

pcall will not report errors

AndOrangutan commented 1 year ago

Sorry, it has been a minute, but I still can't get this to work.

Here is trying what you suggested.

image

image

image

So it just doesn't seem to be creating the highlights.

:PackerSync shows it's installed, so I don't really know what to do. I have tried installing and uninstalling it.

image

lukas-reineke commented 1 year ago

If the highlight group is not found, it means setup is not called.

In your config above, you have confug = function () require('headlines').setup() end. There is a typo, it should be config. Maybe that is the problem?

AndOrangutan commented 1 year ago

Gosh, I fill quite silly for that one.