m-demare / hlargs.nvim Goto Github PK
View Code? Open in Web Editor NEWHighlight arguments' definitions and usages, using Treesitter
License: GNU General Public License v3.0
Highlight arguments' definitions and usages, using Treesitter
License: GNU General Public License v3.0
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.
Not sure why it doesn't support C while CPP works.
As title.
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
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
What do you think about multiple colors for arguments?
I tried to implement it in fork. It looks like this
PR: #32
As discussed in the other issue, it would be great to have Ruby support.
# 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
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)
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.
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:
$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)$#
is the number of arguments passed in to the functionAll 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.
Describe the bug
After enabling codi for current buffer and going into insert mode I get this error:
On every typed in key.
Expected behavior
Hope it Hlargs would work ok with CODI
Steps
:Codi
- for current bufferSystem information
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.
System information
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
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>%
i installed hlargs and treesitter but it doesn't work with javascript.
i'm using nvim 0.8, is that a problem ?
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();
}
}
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
: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
Describe the bug
Weirdly enough, it doesn't seem to work, parsing is stuipid slow
Expected behavior
Way faster highlighting
System information
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"
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
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?
Would it be possible to define a style (bold, underline, italic) in addition to (or instead of) color override?
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?
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:
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?
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
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
Use vim.treesitter.language.get_lang
(which ft_to_lang
uses internally) when nvim-treesitter
is not loaded
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) { }
}
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.
System information
Great plugin, would love to see R support. Test file below, please let me know if there are any questions!
# 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)
}
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
As title. Is it possible to disable when lines of code exceed a certain predefined limit?
Basically, implement the same thing this plugin already does for function arguments, but for loop iterators.
given this loop, the i
could be colored
for i = 1, 10, 1 do
print(i)
end
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
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
To Reproduce
System information
{ -- 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",
},
},
},
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:
HlArgsColor
for example) in our theme and would effectively support your plugin out of the box.HlArgsColor
for php
or lua
files.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
System information
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
Additional context
n/a
Thanks! If there's any tests I can run, etc. please let me know.
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
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) |
---|---|
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
:version
)Additional context
Add any other context about the problem here.
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.
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)
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
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.
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 }
?
https://www.reddit.com/r/neovim/comments/xmvmia/is_there_plugin_like_hlargsnvim_desirable/
I might miss some discussion (if there's any), but why can't this be on nvim-treesitter instead ?
I can't get the extmarks using nvim_get_namespaces
and nvim_buf_get_extmarks
.
Describe the bug
At least in golang, argument names in structs etc with the same name as the actual vars from the function args that should be highlighted by hlargs.
Expected behavior
Only actual usage of the function args should be highlighted.
System information
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.