Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for [doc('some comment')] syntax #97

Closed
miguno opened this issue Jun 16, 2024 · 12 comments
Closed

Support for [doc('some comment')] syntax #97

miguno opened this issue Jun 16, 2024 · 12 comments
Labels
documentation Improvements or additions to documentation external The cause of the issue is external to this project support This issue is a support question

Comments

@miguno
Copy link

miguno commented Jun 16, 2024

I saw that support for the recently introduced doc attribute is mentioned in the issue #88, which was already marked as completed.

However, vim-just seems to fail when parsing a justfile that includes the new doc syntax.

Environment:

  • macOS 14.5 Sonoma
  • neovim 0.10.0
  • vim-just commit 665ef24
  • wezterm 20240203-110809-5046fc22

Actual behavior

Example justfile:

# Correct syntax highlighting by vim-just
foo:
    echo "Foo"

# Some hidden comment
[doc('vim-just syntax highlighting will be broken past this line')]
default:
    just --list


# Broken syntax highlighting here.
bar:
    echo "Bar"

# And broken here.
quux:
    echo "Quux"

Result:
Screenshot 2024-06-16 at 11 24 08

Expected behavior

When I remove the doc attribute, vim-just parses correctly. This is what I would have expected for the original justfile above.

Updated justfile:

# Correct syntax highlighting by vim-just
foo:
    echo "Foo"

# No more `doc` attribute here.
default:
    just --list


# Broken syntax highlighting here.
bar:
    echo "Bar"

# And broken here.
quux:
    echo "Quux"

Result:
Screenshot 2024-06-16 at 11 22 03

@laniakea64 laniakea64 added support This issue is a support question needinfo More information is needed from someone labels Jun 16, 2024
@laniakea64
Copy link
Collaborator

  • vim-just commit 665ef24

😕 We don't have this commit in our repo.

Support for [doc(...)] was added in 65f66b0 and our latest commit on main is 68581811260d782d656dc311454ace4524a24ba7 as of this writing.

How have you installed vim-just?
Do you also see this problem with the instances of [doc(...)] in our test suite (tests/cases/recipes-with-extras.just)?

@miguno
Copy link
Author

miguno commented Jun 16, 2024

I install vim-just via lazy.nvim:

return {
  {
    "NoahTheDuke/vim-just",
    ft = "just",
  },
}

Yes, I also see this problem with tests/cases/recipes-with-extras.just. However, the syntax highlighting already breaks at lines prior to the doc examples in that file, somewhere around here: https://github.com/NoahTheDuke/vim-just/blob/main/tests/cases/recipes-with-extras.just#L63-L70

Screenshot 2024-06-16 at 14 40 09

@laniakea64
Copy link
Collaborator

Weird, your install code is working as expected for me & that problem isn't occurring in testing.

It will be hard to troubleshoot this much further without knowing where the 665ef24 commit is coming from. How did you determine this is the commit hash of vim-just you're using?

Are you able to use commit 6858181 ?

Also, just now noticed the working portions of your screenshots have highlighting of non-quoted command-line arguments in recipe bodies (--list, -c, unreachable). vim-just does not have such highlighting. On a broken file, does :set syn? show syntax=just?

@miguno
Copy link
Author

miguno commented Jun 16, 2024

Doh, the commit was a typo—it was the commit for vim-go, which is just a line above vim-just in lazy.nvim's plugin manager. Sorry for the confusion!

My vim-just has commit 6858181, too, i.e., the one you mentioned in your last comment.

@miguno
Copy link
Author

miguno commented Jun 16, 2024

First, thanks a lot for investigating this!

On a broken file, does :set syn? show syntax=just?

I think you are on the right track. :set syn? returns syntax=.

When I manually do :set syntax=just, then the syntax highlighting of the original example (see all the way above) looks like so:

Screenshot 2024-06-16 at 15 31 19

@laniakea64
Copy link
Collaborator

Are you using nvim-treesitter with its just syntax enabled? I was able to reproduce the exact behavior you're seeing with this init.lua -

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  {
    "NoahTheDuke/vim-just",
    ft = "just",
  },
  {"nvim-treesitter/nvim-treesitter", build = ":TSUpdate",
    config = function () 
      local configs = require("nvim-treesitter.configs")

      configs.setup({
          ensure_installed = { "just" },
          highlight = { enable = true },
        })
    end
  },
})

@miguno
Copy link
Author

miguno commented Jun 16, 2024

As I said above, manually calling :set syntax=just fixes the problem. I therefore tried to explicitly add an autocmd to forcefully set the syntax to just, but this fails.

vim.api.nvim_create_autocmd("FileType", {
  pattern = "just",
  callback = function(_)
    vim.bo.syntax = "just"
    vim.notify(
      "Syntax was set to 'just' | Effective syntax is now: '" .. vim.cmd("set syn?") .. "'",
      vim.log.levels.INFO,
      { title = "Neovim" }
    )
  end,
})

This prints:

Syntax was set to 'just' | Effective syntax is now: ''

@miguno
Copy link
Author

miguno commented Jun 16, 2024

I do use nvim-treesitter, but my config doesn't enable its "just" syntax as far as I can tell. ensure_installed = { ...} for treesitter doesn't include "just".

However, I did find a just.so file in the parser/ directory of lazy.nvim's nvim-treesitter installation directory:

$ ls -l ~/.local/share/nvim/lazy/nvim-treesitter/parser/just.so
.rwxr-xr-x@ 68k  20 May 16:49 ~/.local/share/nvim/lazy/nvim-treesitter/parser/just.so

Perhaps this is a relic from having enabled "just" in treesitter in the past (see timestamp of May 20th). I'll try deleting the just.so file and will report back.

@miguno
Copy link
Author

miguno commented Jun 16, 2024

Success!

First, I need to explicitly disable "just" support in nvim-treesitter. Otherwise, at least in my setup, nvim-treesitter will keep re-install its own just parser (which generates the aforementioned just.so) — even though "just" isn't included in ensure_installed = { ... }.

Below is my config file for nvim-treesitter, using lazy.nvim:

-- ~/.config/nvim/lua/plugins/nvim-treesitter.lua
return {
  {
    "nvim-treesitter/nvim-treesitter",
    -- ...
    config = function()
      require("nvim-treesitter.configs").setup({
        ensure_installed = {
          "asm",
          "astro",
          "bash",
          "c",
          -- That is, a bunch of explicitly enabled parsers, not an "install all" setup.
          -- I have no idea why nvim-treesitter would still keep re-installing its own
          -- just parser, even though "just" is not included here.
          -- To stop nvim-treesitter (at least in my setup) to keep auto-installing
          -- "just", I had to explicitly add it to `ignore_install`, see below.
        },
        ignore_install = {
          "just", -- <====== ADD THIS TO FIX THE ISSUE REPORTED HERE
        },
        -- ...
      })
    end,
  },
}

Second, I need to delete any leftover just.so file from nvim-treesitter's install directory.

$ rm ~/.local/share/nvim/lazy/nvim-treesitter/parser/just.so

Then syntax highlighting in the original example justfile works and looks like so:
Screenshot 2024-06-16 at 15 59 32

For reference, this is my Lua code that loads vim-just:

-- ~/.config/nvim/lua/plugins/vim-just.lua
return {
  {
    "NoahTheDuke/vim-just",
    ft = "just",
  },
}

Again, thanks a lot for your help!

If you don't mind the question: What led you to believe that nvim-treesitter might be the cause? Simply a general guess because it's a popular plugin with parser functionality? Or something more specific?

@laniakea64 laniakea64 added documentation Improvements or additions to documentation and removed needinfo More information is needed from someone labels Jun 16, 2024
@laniakea64
Copy link
Collaborator

Cool, you're welcome!

I think we should add to our README instructions about disabling nvim-treesitter highlighting of justfiles. This is not the first issue like this we've had.

If you don't mind the question: What led you to believe that nvim-treesitter might be the cause?

  1. The highlighting in your working screenshots included highlighting vim-just doesn't do, so it seemed likely something else was either overriding vim-just or active in addition.
  2. The vertical lines in your screenshot in this comment look sort of like screenshots I've seen of Neovim treesitter plugins.
  3. As far as I know, vim-just and nvim-treesitter/tree-sitter-just are the only Vim/Neovim plugins for justfile syntax highlighting. https://just.systems/man/en/chapter_11.html doesn't mention any others, and the only other justfile-related Neovim plugin I'm aware of isn't a syntax highlighter.

@laniakea64
Copy link
Collaborator

If tree-sitter brings other benefits other than syntax highlighting, and you want to keep those while using vim-just for syntax highlighting, setting { disable = "just" } also seems to work -

  {
    "nvim-treesitter/nvim-treesitter",
    build = ":TSUpdate",
    config = function () 
      local configs = require("nvim-treesitter.configs")

      configs.setup({
          ensure_installed = { "just" },
          highlight = {
            enable = true,
            disable = { "just" },
          },
        })
    end
  },

@miguno
Copy link
Author

miguno commented Jun 16, 2024

Thanks for the tip in your last comment. I am going with such a setup for the time being.

Here's my nvim-treesitter setup, in case it helps others reading this.

        highlight = {
          enable = true,
          disable = function(language, bufnr)
            if language == "just" then
              return true
            end
            -- Other logic to conditionally disable treesitter
            -- (e.g., for large buffers) follows, which is the
            -- reason why I must use a function for `disable`.
          end,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation external The cause of the issue is external to this project support This issue is a support question
Projects
None yet
Development

No branches or pull requests

2 participants