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

Makefile highlighting some values and arguments as text #6639

Open
AlejandroSuero opened this issue May 16, 2024 · 8 comments
Open

Makefile highlighting some values and arguments as text #6639

AlejandroSuero opened this issue May 16, 2024 · 8 comments
Labels
highlights Issues or PRs about highlighting queries

Comments

@AlejandroSuero
Copy link

AlejandroSuero commented May 16, 2024

Describe the highlighting problem

  • When inside of a Makefile and using a define <name>\n...\n endef the inside values will be highlighted as a whole and with raw_text.
  • When inside a target calling the define with $(call <defined>,"...") it highlights the arguments as text, including the strings.

Example snippet that causes the problem

define style_calls
	$(eval $@_msg = $(1))
	echo ${GREEN}${$@_msg}
	echo ${RESTORE}
endef

.PHONY: lint format

lint:
	@$(call style_calls,"Linting lua files")
	@selene --display-style quiet --config ./selene.toml lua/supermaven-nvim
	@$(call style_calls,"Running stylua check")
	@stylua --color always -f ./stylua.toml --check .

Tree-sitter parsing result

(variable_assignment) ; [1:1 - 2:0]
 name: (word) ; [1:1 - 5]
 value: (text) ; [1:7 - 19]
(variable_assignment) ; [2:1 - 4:0]
 name: (word) ; [2:1 - 7]
 value: (text) ; [2:9 - 17]
(comment) ; [4:1 - 46]
(define_directive) ; [5:1 - 11:0]
 name: (word) ; [5:8 - 18]
 value: (raw_text) ; [6:1 - 9:0]
(rule) ; [11:1 - 13:0]
 (targets) ; [11:1 - 6]
  (word) ; [11:1 - 6]
 normal: (prerequisites) ; [11:9 - 19]
  (word) ; [11:9 - 12]
  (word) ; [11:14 - 19]
(rule) ; [13:1 - 19:0]
 (targets) ; [13:1 - 4]
  (word) ; [13:1 - 4]
 (recipe) ; [13:6 - 19:0]
  (recipe_line) ; [14:2 - 41]
   (shell_text) ; [14:3 - 41]
    (function_call) ; [14:3 - 41]
     (arguments) ; [14:10 - 40]
      argument: (text) ; [14:10 - 40]
  (recipe_line) ; [15:2 - 73]
   (shell_text) ; [15:3 - 73]
    (command) ; [15:3 - 73]
     name: (command_name) ; [15:3 - 8]
      (word) ; [15:3 - 8]
     argument: (word) ; [15:10 - 24]
     argument: (word) ; [15:26 - 30]
     argument: (word) ; [15:32 - 39]
     argument: (word) ; [15:41 - 53]
     argument: (word) ; [15:55 - 73]
  (recipe_line) ; [16:2 - 44]
   (shell_text) ; [16:3 - 44]
    (function_call) ; [16:3 - 44]
     (arguments) ; [16:10 - 43]
      argument: (text) ; [16:10 - 43]
  (recipe_line) ; [17:2 - 50]
   (shell_text) ; [17:3 - 50]
    (command) ; [17:3 - 50]
     name: (command_name) ; [17:3 - 8]
      (word) ; [17:3 - 8]
     argument: (word) ; [17:10 - 16]
     argument: (word) ; [17:18 - 23]
     argument: (word) ; [17:25 - 26]
     argument: (word) ; [17:28 - 40]
     argument: (word) ; [17:42 - 48]
     argument: (word) ; [17:50 - 50]
(rule) ; [19:1 - 23:0]
 (targets) ; [19:1 - 6]
  (word) ; [19:1 - 6]
 (recipe) ; [19:8 - 23:0]
  (recipe_line) ; [20:2 - 45]
   (shell_text) ; [20:3 - 45]
    (function_call) ; [20:3 - 45]
     (arguments) ; [20:10 - 44]
      argument: (text) ; [20:10 - 44]
  (recipe_line) ; [21:2 - 42]
   (shell_text) ; [21:3 - 42]
    (command) ; [21:3 - 42]
     name: (command_name) ; [21:3 - 8]
      (word) ; [21:3 - 8]
     argument: (word) ; [21:10 - 16]
     argument: (word) ; [21:18 - 23]
     argument: (word) ; [21:25 - 26]
     argument: (word) ; [21:28 - 40]
     argument: (word) ; [21:42 - 42]
(rule) ; [23:1 - 24:0]
 (targets) ; [23:1 - 3]
  (word) ; [23:1 - 3]
 normal: (prerequisites) ; [23:6 - 16]
  (word) ; [23:6 - 9]
  (word) ; [23:11 - 16]

Example screenshot

  • define call:
define call values as raw_text
  • target calling the defined one:
arguments of call in target as text
  • :Inspect of both:
:Inspect define :Inspect call
  • Colorscheme rose-pine-moon more on how to configure here:
-- with lazy
return {
  "rose-pine/neovim",
  name = "rose-pine",
  priority = 1000,
  lazy = false,
  config = function()
    require("rose-pine").setup({
      variant = "moon", -- auto, main, moon, or dawn
      dark_variant = "main", -- main, moon, or dawn
      dim_inactive_windows = true,

      enable = {
        terminal = true,
        legacy_highlights = true, -- Enabling or disabling this takes no effect on `Makefile`
        migrations = true, -- Handle deprecated options automatically
      },

      styles = {
        bold = true,
        italic = false,
        transparency = vim.g.transparency,
      },
    })
  end,
}

Expected behavior

To have highlights other than raw_text or text, at least the strings.

Output of :checkhealth nvim-treesitter

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.22.6 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v20.13.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: Apple clang version 15.0.0 (clang-1500.3.9.4)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "arm64",
  release = "23.4.0",
  sysname = "Darwin",
  version = "Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103"
} ~

Parser/Features         H L F I J
  - astro               ✓ ✓ ✓ ✓ ✓
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - csv                 ✓ . . . .
  - dockerfile          ✓ . . . ✓
  - git_config          ✓ . ✓ . ✓
  - git_rebase          ✓ . . . ✓
  - gitattributes       ✓ ✓ . . ✓
  - gitcommit           ✓ . . . ✓
  - gitignore           ✓ . . . .
  - go                  ✓ ✓ ✓ ✓ ✓
  - graphql             ✓ . . ✓ ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - http                ✓ . . . ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - jsdoc               ✓ . . . .
  - json                ✓ ✓ ✓ ✓ .
  - jsonc               ✓ ✓ ✓ ✓ ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - make                ✓ . ✓ . ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - php                 ✓ ✓ ✓ ✓ ✓
  - prisma              ✓ . ✓ . .
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - svelte              ✓ ✓ ✓ ✓ ✓
  - templ               ✓ . . . ✓
  - tmux                ✓ . . . ✓
  - toml                ✓ ✓ ✓ ✓ ✓
  - tsx                 ✓ ✓ ✓ ✓ ✓
  - typescript          ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - xml                 ✓ ✓ ✓ ✓ ✓
  - yaml                ✓ ✓ ✓ ✓ ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

Output of nvim --version

NVIM v0.9.5
Build type: RelWithDebInfo
LuaJIT 2.1.1692716794
Compilation: /Library/Developer/CommandLineTools/usr/bin/cc -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wvla -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -I/Users/aome/neovim/.deps/usr/include/luajit-2.1 -I/opt/homebrew/opt/gettext/include -I/Users/aome/neovim/.deps/usr/include -I/Users/aome/neovim/build/src/nvim/auto -I/Users/aome/neovim/build/include -I/Users/aome/neovim/build/cmake.config -I/Users/aome/neovim/src -I/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/include -I/Users/aome/neovim/.deps/usr/include -I/Users/aome/neovim/.deps/usr/include -I/Users/aome/neovim/.deps/usr/include -I/Users/aome/neovim/.deps/usr/include -I/Users/aome/neovim/.deps/usr/include -I/Users/aome/neovim/.deps/usr/include

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Additional context

No response

@AlejandroSuero AlejandroSuero added the highlights Issues or PRs about highlighting queries label May 16, 2024
@clason
Copy link
Contributor

clason commented May 16, 2024

How would you expect them to be highlighted?

@AlejandroSuero
Copy link
Author

@clason I am not sure, inside the define call it could treat them as bash|zsh|sh|... commands when in an .{bash|zsh|sh|...} files. For example:

  • define style_calls inside a .sh file:
define call inside sh
  (command) ; [31:3 - 20]
   name: (command_name) ; [31:3 - 8]
    (word) ; [31:3 - 8]
   argument: (word) ; [31:10 - 20]
  (command) ; [32:4 - 24]
   name: (command_name) ; [32:4 - 24]
    (command_substitution) ; [32:4 - 24]
     (command) ; [32:6 - 23]
      name: (command_name) ; [32:6 - 9]
       (word) ; [32:6 - 9]
      argument: (concatenation) ; [32:11 - 16]
       (simple_expansion) ; [32:11 - 12]
        (special_variable_name) ; [32:12 - 12]
       (word) ; [32:13 - 16]
      argument: (word) ; [32:18 - 18]
      argument: (command_substitution) ; [32:20 - 23]
       (command) ; [32:22 - 22]
        name: (command_name) ; [32:22 - 22]
         (number) ; [32:22 - 22]
  (command) ; [33:4 - 25]
   name: (command_name) ; [33:4 - 7]
    (word) ; [33:4 - 7]
   argument: (concatenation) ; [33:9 - 25]
    (expansion) ; [33:9 - 16]
     (variable_name) ; [33:11 - 15]
    (ERROR) ; [33:17 - 20]
    (word) ; [33:21 - 24]
    (word) ; [33:25 - 25]
  (command) ; [34:4 - 18]
   name: (command_name) ; [34:4 - 7]
    (word) ; [34:4 - 7]
   argument: (expansion) ; [34:9 - 18]
    (variable_name) ; [34:11 - 17]
  (command) ; [35:3 - 7]
   name: (command_name) ; [35:3 - 7]
    (word) ; [35:3 - 7]

:Inspect: style_calls as @variable.parameter and numbers and Uppercase variables as @string.

  • target call inside sh:
target call install sh
  (command) ; [31:3 - 7]
   name: (command_name) ; [31:3 - 7]
    (word) ; [31:3 - 7]
  (command) ; [32:4 - 43]
   name: (command_name) ; [32:4 - 43]
    (concatenation) ; [32:4 - 43]
     (word) ; [32:4 - 4]
     (command_substitution) ; [32:5 - 43]
      (command) ; [32:7 - 42]
       name: (command_name) ; [32:7 - 10]
        (word) ; [32:7 - 10]
       argument: (concatenation) ; [32:12 - 42]
        (word) ; [32:12 - 23]
        (string) ; [32:24 - 42]
         (string_content) ; [32:25 - 41]

:Inspect: style_calls as @variable.parameter and "..." as @string

@clason
Copy link
Contributor

clason commented May 16, 2024

That's not possible, though. The make query can't know what file it is in. Feel free to make a PR adding a bash injection; maybe that is good enough. But if it isn't, then the current state is the best we can do.

@AlejandroSuero
Copy link
Author

@clason it will be my first time touching this code base, do you know where should I do it?

@clason
Copy link
Contributor

clason commented May 16, 2024

The relevant query is make/injections.scm.

@AlejandroSuero
Copy link
Author

@clason one question I have, what should I do to put the injection?

  • This is what make/injections.scm contains.
((comment) @injection.content
  (#set! injection.language "comment"))

((shell_text) @injection.content
  (#set! injection.language "bash"))

((shell_command) @injection.content
  (#set! injection.language "bash"))
  • This is what make/highlights.scm contains:
(define_directive
  "define" @keyword
  name: (word) @string.special.symbol
  [
    "="
    ":="
    "::="
    ; ":::="
    "?="
    "!="
  ]? @operator
  "endef" @keyword)

My question is, wouldn't be better to assign to highlights.scm value: (...) and try to match it there? Seems that the problem that I have is that value: is not set and therefore it takes it as raw_text as default.

@clason
Copy link
Contributor

clason commented May 16, 2024

No, since we can only assign single captures to single nodes exposed by the parser.

If you are not (yet) sufficiently familiar with treesitter queries, no worries; but then you'll have to wait for some else to do this. (Queries are community contributed.)

@AlejandroSuero
Copy link
Author

@clason I haven't written a single one yet 😥 but I will give it a try, in the meantime if anyone does it will be nice too ✌️.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
highlights Issues or PRs about highlighting queries
Projects
None yet
Development

No branches or pull requests

2 participants