Giter VIP home page Giter VIP logo

m-demare / hlargs.nvim Goto Github PK

View Code? Open in Web Editor NEW
446.0 4.0 10.0 123 KB

Highlight arguments' definitions and usages, using Treesitter

License: GNU General Public License v3.0

Lua 52.33% Scheme 25.44% JavaScript 1.16% Python 2.12% C++ 1.30% Java 1.42% TypeScript 1.27% PHP 0.60% Zig 1.38% C 0.48% Go 0.61% Rust 1.71% Ruby 1.32% R 1.15% Vim Script 0.34% Julia 1.85% C# 1.29% Nix 1.27% Kotlin 0.94% Cuda 2.00%
lua neovim tree-sitter neovim-plugin

hlargs.nvim's People

Contributors

electrostasy avatar goakly avatar hd avatar jmarkin avatar kevinhwang91 avatar lostl1ght avatar m-demare avatar m4ttm avatar minebill avatar registergen avatar tmke8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hlargs.nvim's Issues

[Feature Request]: Add included_filetypes

I'm using semantic highlighting, Unfortunately, some language servers like gopls can't highlight parameters in the function. The semantic token in some language servers like pyright can't be supported.

I hope to add an included_filetypes option to enable this plugin only in some filetypes to compensate semantic.
excluded_filetypes must make me change the config if a query is added.

bug: error on bufdelete? `util.lua:106: attempt to index a nil value

Describe the bug

When I :bd a buffer, the following error occurs when loading the next buffer.

I'm not exactly sure whether it is caused by BufLeave or BufEnter but it does not happen on :bn / :bp.

   Error  Error executing vim.schedule lua callback: ...o/.local/share/nvim/lazy/hlargs.nvim/lua/hlargs/util.lua:106: attempt to index a nil value
stack traceback:
	...o/.local/share/nvim/lazy/hlargs.nvim/lua/hlargs/util.lua:106: in function 'get_marks_limits'
	...local/share/nvim/lazy/hlargs.nvim/lua/hlargs/bufdata.lua:108: in function 'stop_older_contained'
	....local/share/nvim/lazy/hlargs.nvim/lua/hlargs/events.lua:47: in function ''
	vim/_editor.lua: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

Expected behavior

No error.

Screenshots or sample file

It happens on lua file or python file but not when closing bash scripts.
I do not enable treesitter on bash files but are enabled on other files so I think that is somewhat related.

System information

  • OS: Linux / Manjaro
  • Neovim version: nightly build of neovim
NVIM v0.10.0-dev-235+ga803bff89
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /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 -fno-common -Wno-unused-result -Wimplicit-fallthrough -fdiagnostics-color=always -fstack-protector-strong -DUNIT_TESTING -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/home/user/.local/share/nvim-git/.deps/usr/include/luajit-2.1 -I/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include -I/home/user/.local/share/nvim-git/build/src/nvim/auto -I/home/user/.local/share/nvim-git/build/include -I/home/user/.local/share/nvim-git/build/cmake.config -I/home/user/.local/share/nvim-git/src -I/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include -I/home/user/.local/share/nvim-git/.deps/usr/include

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

Run :checkhealth for more info

[Python] No highlight in function usage

Describe the bug
Highlighting works perfectly fine in argument declaration, but doesn't work when using a function

Expected behavior
Arguments is being highlighted in function usage

Screenshots or sample file
image

System information

  • OS: MacOS Monterey 12.5
  • Neovim version: 0.8.1 (AstoNvim config)

Ruby support

As discussed in the other issue, it would be great to have Ruby support.

Context

  • Does your language have a Treesitter implementation?
  • Have you supplied an example test file?

Test file

# test.rb

# Function
def fn(arg0)
    puts arg0
end
fn "Function: hlargs is great"

# Method
class Example
    def initialize(arg0, arg1)
        @arg0 = arg0
        @arg1 = arg1
    end

    def output
        puts "Method: " + @arg0 + @arg1
end
Example.new("hlargs", " is great").output

# Lambda
lambda = ->(arg0, arg1) { puts "Lambda: #{arg0} #{arg1}" }
lambda.call("hlargs", "is great")
end

# Blocks
print "Blocks: "
["hlargs", "is", "great"].each do |arg0|
    print arg0 + " "
end

You can run this via ruby test.rb to see the output

[sumneko_lua] Some args usage not highlighted

Describe the bug
As title.

Expected behavior
All args get highlighted.

Screenshots or sample file

System information

  • OS: macOS 12.3.1
  • Neovim version: (result of :version)
NVIM v0.8.0-dev+9-g1facad234
Build type: Release
LuaJIT 2.1.0-beta3

Additional context

Support for julia

Language support request

Test file:

function standard(x)
  print(x)
end

function default(a,b="test")
  print(b)
end

function keyword(a,b="test";c)
  print(c)
end

function default_kw(a,b="test";c="keyword")
  print(c)
end

function nested1(x)
  function nested2(x)
    print(x)
  end
  return nested2(x)
end

function dispatch(x::Int,y::Any)
  println(typeof(x))
  println(typeof(y))
  return x
end

function typed_output(x::Int,y::Float64)::Int
  println(typeof(x))
  println(typeof(y))
  return x
end

function parametric(x::T) where {T<:Real}
  print(x)
end

inline(x) = print(x)

struct StructConstructor
   x::Real
   y::Real
   StructConstructor(x,y) = x > y ? error("out of order") : new(x,y)
end

# Overload operator
import Base.+
(+)(x::Int,y::Float64) = x*y
Base.:+(x::Int,y::Float64) = x*y

# Anonymous functions
x -> 3*x
(x) -> 3*x
z = (x,y) -> 3*x*y
# Can be defined anywhere
map(x->x*2 + 1, [1,2,3])
# Equivalent to do-block
map([1,2,3]) do x
  x*2 + 1
end

slurp(x...) = print(x)

Better defaults?

Imo it would be cool if by default hlargs would link Hlargs highlight to TSParameter like so:

vim.cmd [[autocmd ColorScheme * highlight! link Hlargs TSParameter]]
Maybe this could be added to addon itself, or only to docs. The advantage if above setup is that it will change Hlargs color with theme change.

Support for shell scripts (bash)

Language support request

Test file:

greeting() { echo "Hello $1" }

function farewell {
    echo "$2 says goodbye, $1"
    return 1
}

function many_arguments () {
    cat << EOF
$1 $2, buckle my shoe!"
${3:-red} ${4:+and $4}, knock at the door!
${5} $6, picking up sticks!
$7 ${8}, don't be late!
${9:+nine} ten, let's say it again!
EOF
}

function special_arguments () {
    echo "you have called the function called '$0'"
    echo "and you have passed $# arguments to it."
    echo "the first argument followed by a zero is $10"
}

greeting "James Bond"
farewell "Mr Bond" "Goldfinger"
many_arguments "a" "bee" "three" "4" "e" "eff" "7" "ate" "nueve"

special_arguments martini shaken not stirred

Where there are a few oddities in bash:

  • There are no named arguments. There are only positional parameters.
  • You can only refer to a specific positional parameter between 1 and 9, there is no such thing as $10 - that's just $1 followed by a zero
  • $0 always refers to the function's name (or script name outside of a function context)
  • and $# is the number of arguments passed in to the function

All of these rules apply at the top level as well, but for arguments passed to the entire script. I think it'd still be useful to highlight the two differently, so the queries for hlargs.nvim would only apply within a function body.

Conflict with CODI plugin (interactive repl for nvim)

Describe the bug
After enabling codi for current buffer and going into insert mode I get this error:
image
On every typed in key.

Expected behavior
Hope it Hlargs would work ok with CODI

Steps

  1. Enable codi :Codi - for current buffer
  2. Go into insert mode - HLargs will throw error on each key press.

System information

  • OS: linux Manjaro
  • Neovim version:
  • NVIM v0.8.0-dev
    Build type: Debug
    LuaJIT 2.1.0-beta3

packer.nvim: Error running config for hlargs.nvim: ...vim/site/pack/packer/opt/hlargs.nvim/lua/hlargs/util.lua:3: module 'nvim-treesitter.parsers' not found:

Describe the bug
What the bug is. If the issue is file/filetype specific, provide a file to reproduce it

Somehow nvim-treesitter.parsers isn't found?

Expected behavior
What you expected to happen.

nvim-treesitter.parsers to be found

Screenshots or sample file
If applicable, add screenshots to help explain your problem.

image

System information

  • OS: Arch Linux Rolling
  • Neovim version: v0.9.0-dev-38-g2c08ab5369

Additional context
Add any other context about the problem here.

I'm pretty confident treesitter is loaded so I have no idea why this happens

util.lua:65: attempt to index a nil value

I just installed this and am not passing any custom config to setup(). The module is not available when I try to run:

:require('hlargs').enable()

When I exit nvim, I see this error:

Error executing vim.schedule lua callback: ...m/site/pack/packer/start/hlargs.nvim/lua/hlargs/util.lua:65: attempt to index a nil value
stack traceback:
        ...m/site/pack/packer/start/hlargs.nvim/lua/hlargs/util.lua:65: in function 'get_marks_limits'
        ...ite/pack/packer/start/hlargs.nvim/lua/hlargs/bufdata.lua:106: in function 'stop_older_contained'
        ...site/pack/packer/start/hlargs.nvim/lua/hlargs/events.lua:31: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>%

PHP support

I am not sure what the example should contain so I converted some from this repo in PHP:

function fn(arg0) {
    print_r(arg0, arg1);
    function fn2(arg1) {
        $var = arg0 . arg1->arg0;
    }
}

class C{
    memberFn(arg0){
        arg0->run();
    }
}

Error: Expected lua number

Describe the bug
When copy pasting some vim code into my ~/.config/nvim/init.vim file I see the following error:

Error executing vim.schedule lua callback: ...local/share/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:72: Expected lua number
stack traceback:
        [C]: in function 'nvim_buf_get_extmark_by_id'
        ...local/share/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:72: in function 'get_marks_limits'
        ...local/share/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:83: in function <...local/share/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:82>
        [C]: in function 'sort'
        ...local/share/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:82: in function 'merge_ranges'
        ...cal/share/nvim/plugged/hlargs.nvim/lua/hlargs/events.lua:85: in function 'schedule_partial_repaints'
        ...cal/share/nvim/plugged/hlargs.nvim/lua/hlargs/events.lua:129: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Expected behavior
No error.

System information

  • OS: macOS 12.4
  • Neovim version: (result of :version)
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by [email protected]

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.7.2/share/nvim"

Run :checkhealth for more info

Additional context
My config can be seen here:
https://github.com/Integralist/dotfiles/blob/main/.config/nvim/init.vim

Incremental parsing not working on Windows

Describe the bug
Weirdly enough, it doesn't seem to work, parsing is stuipid slow

Expected behavior
Way faster highlighting

System information

  • OS: Windows 10
  • Neovim version:
NVIM v0.6.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilado por runneradmin@fv-az152-703

Features: -acl +iconv +tui
See ":help feature-compile"

    archivo "vimrc" del sistema: "$VIM\sysinit.vim"
           predefinido para $VIM: "C:/Program Files/nvim/share/nvim"

args from other functions are highlighted

Describe the bug
When opening a file that includes many functions, I notice function arguments are highlighted without regard for their scope. For example.

function A(foo, bar) {
  return foo + bar;
}

function B(baz) {
  const foo = 'hello';   // incorrectly highlighted as an argument
  const bar = 'world';   // same 
  console.log(`${foo} ${bar}`);
}

Expected behavior
It would be nice if arg highlights were contained within function scope.

System information

  • OS: MacOS
  • Neovim version: NVIM v0.8.0-dev-1093-g982fef601-dirty

Additional context
This is not all that common, as I've been using the plugin a week or so and I've just now noticed it. I'm curious if it's possible to achieve this?

New feature - style

Would it be possible to define a style (bold, underline, italic) in addition to (or instead of) color override?

Lua - Argument is not highlighted if used as index

image

Should be reproductible with this:

function Hello(mode)
   mode = hello
   local table = {}
   table[mode] = "world"
end

The argument mode is properly highlighted in the two first lines but not when used with table[mode].

duplicate help tag

Describe the bug

There are 2 tags for hlargs-config-paint_catch_blocks.
I think that second one should be hlargs-config-extra.

Screenshots or sample file

hlargs.nvim/doc/hlargs.txt

Lines 158 to 168 in a866720

paint_catch_blocks *hlargs-config-paint_catch_blocks*
Description: Whether catch block arguments (exceptions) should be
colored or not.
Type: `table`
Default:
>
{
declarations = false,
usages = false
}
<

hlargs.nvim/doc/hlargs.txt

Lines 170 to 178 in a866720

paint_catch_blocks *hlargs-config-paint_catch_blocks*
Description: Extra syntactic highlighting (handled by |treesitter-highlight|)
Type: `table`
Default:
>
{
named_parameters = false,
}
<

Support for Languages that have equivalent Syntax

CUDA (.cu files) is a language that is syntactically identical to C++ apart from minor changes that should not affect parsing. As such, it should be possible to reuse C++ parsing for CUDA, saving the need for a new parser.

Is it possible to map file types to already existing parsers?

Feature request: excluding `self` arguments (or a general mechanism for excluding arguments)

Hi, thanks for this great plugin.

In Python, methods on classes always have self as the first argument. This self variable is usually highlighted differently, because it's special and we want to reduce visual noise a bit. For example it could look like this:

image

In addition, there is also the cls argument for classmethods, which usually gets the same highlighting as self.

class A:
    @classmethod
    def m(cls): ...

Now, my problem is that hlargs.nvim is overriding the special highlighting of self and cls. What would you think about adding a way to exclude certain arguments from hlargs.nvim's special highlighting?

error with augmented type in C

Describe the bug

In below example where IN is defined as 'empty' expression, there's issues on rendering.

#define IN

void test_arg(IN int *a) // 'int' is rendered as argument (not expected). 'a' is rendered as argument (expected).
{
}

void test_arg2(IN int a) // 'int' is rendered as argument (not expected). 'a' is not rendered as argument (not expected).
{
}

System information
NVIM v0.6.1
Build type: Release
LuaJIT 2.1.0-beta3

Additional context
hlarg version information

832920d

feat: use without `nvim-treesitter` loaded

Problem

nvim-treesitter is somewhat of a heavy plugin to load
And it is very easy for neovim users to use vim.treesitter.start for highlighting and only load nvim-treesitter when updating parsers/queries
Additionally this plugin seems to only make use of nvim-treesitter for the ft_to_lang function

Solution

Use vim.treesitter.language.get_lang (which ft_to_lang uses internally) when nvim-treesitter is not loaded

Support for c#

Language support request

Test file:

class Program {
  public static void Main(string[] args) {
    Console.WriteLine("Hello");
    string str = "World";
    Console.Write(str);

    List<int> list = new();
    mystr a = new();
    a.argc = 0;
    a.SampleEvent += () => {
      Console.WriteLine("Event");
      list.Add(5);
    };

    GenericList<string> genList = new();
    genList.Add("Hello, world");
  }
}

class MyClass {
  public MyClass(int arg0, float arg1) {
    this.arg0_ = arg0;
    this.arg1 = arg1;
  }
  int arg0_;
  private float arg1;

  int fn(char arg2, int arg3 = 0) {
    return arg3 + arg2;
  }
};

public struct mystr {
  public int argc;
  public delegate void Del();
  public event Del SampleEvent;
};

public class GenericList<T> {
  public void Add(T input) { }
}

Highlighting conflicts with neodim

Describe the bug
When I use hlargs with zbirenbaum/neodim I get dimmed unused arguments overridden by hlargs.

Steps to reproduce
use hlargs config:

    use {
      'm-demare/hlargs.nvim',
      requires = { 'nvim-treesitter/nvim-treesitter' },
      after = 'nvim-treesitter',
      config = function() require('me.plugins.hlargs') end
    }

require('hlargs').setup({
  color = '#C6B7AB',
  excluded_filetypes = {},
  extras = {
    named_parameters = false,
  },
   excluded_argnames = {
    declarations = {
      python = { 'self', 'cls' },
      lua = { 'self' },
      },
    usages = {
      python = { 'self', 'cls' },
      lua = { 'self' },
    }
  },
})

Use neodim config:

    use {
      'zbirenbaum/neodim',
      event = "LspAttach",
      config = function() require('me.plugins.neodim') end
    }

require("neodim").setup({
  blend_color = "#606060",
  alpha = 0,
  hide = {
    virtual_text = false,
    signs = false,
    underline = false,
  },
})

Expected behavior
Get arguments highlighted by hlargs and get unused arguments dimmed by neodim without conflicts.

Screenshots or sample file
Screenshot_2022-11-30_16-04-47

System information

  • OS: Linux Mint 20.3
  • Neovim version:
    NVIM v0.8.1
    Build type: Release
    LuaJIT 2.1.0-beta3
    Compiled by runner@fv-az178-366

Support for R

Great plugin, would love to see R support. Test file below, please let me know if there are any questions!

Language support request

Test file:

# Normal functions
fn1 <- function(arg1) return(arg1)

fn2 = function(arg1) return(arg1)  # can use `=` of `<-` as assignment operator

fn3 <- function(arg1) {
  arg1
}

fn4 = function(df, col) {
  print(df$col)
}

fn5 <- function (arg1) return    (arg1)  # arbitrary spaces between func def and parens

fn6 <- function(arg1, arg2 = 5) {
  return(abs(arg1) + abs(arg2))
}

fn7 <- function(arg1, arg2 = 5) {
  subfn <- function(subarg1) {
    arg1 + subarg1
  }
  out <- abs(subfn(8)) + abs(arg2)
  out
}

fn8 <- function(f) {
  f(26)
}

fn9 <- function(l, i) {
  return(l[[i]])
}

# Lambdas
lam1 <- \(arg1) print(arg1)

lam2 <- \(arg1, arg2) {
  return(arg1 ^ arg2)
}

Improve partial parsing accuracy

Currentl I'm only using nvim_buf_attach to detect changes, and applying some heuristics to attempt to predict what parts of the buffer will be affected by each change
As explained here, LanguageTree:register_cbs by itself doesn't do what I need, but combining it with the results from nvim_buf_attach might give better results

Too slow on large file

As title. Is it possible to disable when lines of code exceed a certain predefined limit?

Incremental parsing to improve performance

Reading the docs, LanguageTree:register_cbs() callbacks aren't called unless there are syntactical changes to the tree, which is not good enough for this use case (changes to the name of a variable aren't considered syntactical changes, since a node isn't being added/removed)
nvim_buf_attach()'s on_lines callback is called on every change, so that may be useful, though it gives no information about syntax, only about which lines were changed
I'll be playing with this for a bit to see if I can get better performance

Un-highlight arg when using marco without declaring in C

Describe the bug
When the macros aren't declared, the arguments are still highlighted.

Expected behavior
Could you please support me with a config to fix it?

Screenshots or sample file
image

System information

  • OS: Win 10
  • Neovim version: v0.9.0 - nightly

Toggle function doesn't enable by default

Describe the bug
After triggering hlargs.enable() it looks like the arguments doesn't get highlighted. (till I press the second time)

Screenshots or sample file

demo-2023-08-29_04.38.32.mp4

To Reproduce

  • Open up a function
  • trigger toggle function

System information

  • OS: Arch/Linux
  • Neovim version: Nightly
  • Package Manager: Lazy.nvim
  • Config:
      { -- Highlight Args in functions etc. -- TODO: Add highlight-mode for this
        -- I think this is a bloat for now
        "m-demare/hlargs.nvim",
        opts = {},
        -- init = function(_) end, --  .enable function locates here by default
        config = function(_, opts)
          require("hlargs").setup(opts)
        end,
    
        keys = {
          {
            "<leader>zt",
            function()
              require("hlargs").toggle()
            end,
            mode = "n",
            desc = "Toggle Highlight Args",
          },
          {
            "<leader>zd",
            function()
              require("hlargs").enable()
            end,
            mode = "n",
            desc = "Enable Highlight Args",
          },
          {
            "<leader>zl",
            function()
              require("hlargs").enable()
            end,
            mode = "n",
            desc = "Enable Highlight Args",
          },
        },
      },
    

Colouring via a Highlight Group

Firstly, I really love the concept of this plugin.

As the author of a colorscheme (onedarkpro.nvim), I wondered if you'd consider implementing an enhancement to color via a highlight group as well as a hex?

I ask for two reasons:

  1. It would allow us theme users to set a highlight group (HlArgsColor for example) in our theme and would effectively support your plugin out of the box.
  2. I implemented custom highlighting by filetype in my colorscheme recently. I love the idea of being able to set different HlArgsColor for php or lua files.

Doesn't play nice with nvim-treesitter/nvim-treesitter-context

Describe the bug
Hi, the issue is that the context is improperly highlighted with whatever the default nvim-treesitter-context color was.

Expected behavior
Context args color should be the same as the one that is used everywhere else

Screenshots or sample file
obraz

System information

  • OS: MacOS
  • Neovim version: 0.8.0

Extending Ruby support

Describe the bug
Thanks for the excellent plugin. I've just installed it today, but noticed a few issues with ruby.
Arguments are not highlighted with block parameter or destructured parameter passed to a block.

Expected behavior
The arguments to be highlighted

Screenshots or sample file
Example of passing a block_parameter. Note that array is highlighted correctly by hlargs.nvim, but the reference to blk is not.

def each(array, &blk)
  i = 0
  while i < array.count
    el = array[i]
    val = blk.call(el)
    i += 1
  end
end

Example of destructuring. Neither student or grade is highlighted

students = [
  ['Jamie', 99],
  ['Natalie', 77],
]
students.each do |(student, grade)|
  p student
  p grade
end

System information

  • OS: MacOs
  • Neovim version: v0.8.0-dev-725-gfe254fb7e

Additional context
n/a

Thanks! If there's any tests I can run, etc. please let me know.

Multithreaded parsing

Neovim 0.7 added multithreading support (neovim/neovim@b87867e). Since backwards compatibility with 0.6 is already broken, I'd like to see if I can offload some of the work to other threads

Python typed/packed parameters support

Typed parameters, *args, **kwargs packed parameters (and their typed counterparts, though I'm not sure if annotating them is practiced) don't seem to be highlighted by the current Python queries.

Is there any possibility of adding support for typed parameters?

I managed to get it working in my fork, however keyword arguments whose name and value match are also highlighted (line 22) and I have no idea how to fix that short of defining queries for all possible scopes, but the rest seems to work (lambda syntax doesn't support typed parameters):

testfiles/test.py (Original highlighting) testfiles/test.py (My fork)
image image

I'd be willing to open up a PR if my implementation is satisfactory, though I just hacked it together after a brief read of the treesitter docs.

¢£

Describe the bug
What the bug is. If the issue is file/filetype specific, provide a file to reproduce it

Expected behavior
What you expected to happen.

Screenshots or sample file
If applicable, add screenshots to help explain your problem.

System information

  • OS:
  • Neovim version: (result of :version)

Additional context
Add any other context about the problem here.

Compatibility with twilight.nvim

Describe the bug
What the bug is. If the issue is file/filetype specific, provide a file to reproduce it
Args highlighted with this plugin seem to override the highlighting the twilight manages when enabled.

Expected behavior
What you expected to happen.
Args highlighted with this plugin should behave like the other dimmed syntax highlighted outside of the current twilight focus. Recreate it by having Twilight's focused region be near but outside or args that would normally be highlighted with Hlargs. It seems that they don't get dimmed despite all the other syntax highlighting being overridden with twilight.

Screenshots or sample file
If applicable, add screenshots to help explain your problem.
Screen Shot 2022-12-15 at 4 32 28 PM
Screen Shot 2022-12-15 at 4 44 14 PM

System information

  • OS: macOS

  • Neovim version: NVIM v0.9.0-dev-1654+g89374da79-dirty
    Build type: Release
    LuaJIT 2.1.0-beta3

Additional context
Add any other context about the problem here.
(this is my first opened issue ever, I apologize if I missed some more context)

Error from util.lua:98 attempt to index a nil value on nightly

Describe the bug
I've just updated to neovim nightly and updated all of my plugins as well. I can't be sure this is an hlargs issue, so please advise.

I'm using fzf-lua, which is a very similar plugin to Telescope. When viewing "Buffers" hlargs throws the following error. (fzf-lua uses treesitter for previews in the same manner as telescope)

Error executing vim.schedule lua callback: ...il2/.config/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:98: attempt to index a nil value
stack traceback:
        ...il2/.config/nvim/plugged/hlargs.nvim/lua/hlargs/util.lua:98: in function 'get_marks_limits'
        .../.config/nvim/plugged/hlargs.nvim/lua/hlargs/bufdata.lua:107: in function 'stop_older_contained'
        ...2/.config/nvim/plugged/hlargs.nvim/lua/hlargs/events.lua:44: in function ''
        vim/_editor.lua: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Expected behavior
I expect to not see this error. As of now, it doesn't seem to cause any problems, as I can hit ENTER key and continue selecting buffers and using the tool as normal.

System information

  • OS: MacOS 13.2
  • Neovim version: NVIM v0.9.0-dev-1059+g2c9fbe34b

The customized color will be overwritten on colorscheme change.

As title. Could you instead provide a unique highlight name, e.g. HLArgs, so that we can reset the color ourselves on colorscheme change?

update: OK, from the source code I see Hlargs exist. I think you can simply update the README.md so people can dynamically change it themselves.

Allow disabling on specific buffers

Well, this is not a bug, but more of a feature request.
I'd like to setup neovim to use lsp semantic tokens by default, fallback to hlargs when unavailable.
Using the disable option is not a complete solution, because if the lsp client is not yet attached to the buffer being disabled, we cannot check the buffer's capabilities for semanticTokenProvider when first opening that buffer up until the point when the language server finishes initializing.

hlargs.setup {
  disable = function(_, bufnr)
    -- when opening a buffer that hasn't attached an lsp client to it, this check will fail
    local clients = vim.lsp.get_active_clients { bufnr = bufnr }
    for _, c in pairs(clients) do
      local caps = c.server_capabilities
      if caps.semanticTokensProvider and caps.semanticTokensProvider.full then
        return true
      end
    end
  end
}

A more reliable solution would be something like:

vim.api.nvim_create_augroup("LspAttach_hlargs", {})
vim.api.nvim_create_autocmd("LspAttach", {
  group = "LspAttach_hlargs",
  callback = function(args)
    if not (args.data and args.data.client_id) then
      return
    end

    local bufnr = args.buf
    local client = vim.lsp.get_client_by_id(args.data.client_id)
    local caps = client.server_capabilities
    if caps.semanticTokensProvider and caps.semanticTokensProvider.full then
      -- TODO: disable only on the buffer that was attached
      require("hlargs").disable()
    end
  end,
})

However, without the ability to specify which buffer to disable, require("hlargs").disable() will disable hlargs across the board.
Would it be possible to add an option to the disable function so it can be called as require("hlargs").disable { bufnr = bufnr }?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.