Home

Awesome

Test

Agrolens

What is Agrolens

Its an extention to telescope that runs pre-defined (or custom) tree-sitter queries on a buffer (or all buffers) and gives a quick view via telescope.

Agrolens.nvim demo

Requirements

Neovim 0.9+

Telescope

Plenary

Nvim tree-sitter

And the language you with to use is also required to be installed via Nvim tree-sitter

Installation

Install

Use your favorite plugin manager

"desdic/agrolens.nvim"

Enable the extension in telescope

require "telescope".load_extension("agrolens")

Default configuration

require("telescope").extensions = {
    agrolens = {
       debug = false,
       same_type = true,
       include_hidden_buffers = false,
       disable_indentation = false,
       aliases = {}
    }
}

Usage

:Telescope agrolens <parameters>

Parameters

ParameterValue(s)Description
aliasesemptyCreate aliases for longer lists of queries.
queryfunctions,callings,comments,labelsA comma seperated list with queries you want to run.
buffersallRun queries on all buffers.
disable_indentationtrue/false(default)Strips spaces from line when showing in telescope.
include_hidden_bufferstrue/false(default)when all buffers are selected only the visible are shown unless includehiddenbuffers is true.
matchname and stringMatches a variable (minus the agrolens namespace) from the query with a string. If no string is provided its the word where the cursor is.
same_typetrue(default)/falsedefault we only match on same filetype across buffers but you can run queries on all if you like.
jumpnext/prevJump to the next or previous match of agrolens.scope based in query input. Only works on current buffer.

Examples

Use queries from agrolens.functions and agrolens.labels

:Telescope agrolens query=functions,labels

Use query functions but run it on all buffers regards filetype

:Telescope agrolens query=functions buffers=all

Use query functions but run it on all buffers regards filetype and include hidden buffers. Some files are pre-loaded due to to provide LSP/tree-sitter and you can search in those too

:Telescope agrolens query=functions buffers=all include_hidden_buffers=true

Use query functions on all buffers but only if the agrolens.name matches the word on the cursor

:Telescope agrolens query=functions buffers=all match=name

Or callings (functions/methods called) to find a function being called named myfunctions or a method of object M

:Telescope agrolens query=callings buffers=all match=name=myfunction,object=M

Same query as above but agrolens.name must by either main or myfunc

:Telescope agrolens query=functions buffers=all match=name=main,name=myfunc

Jump to next match in query work

:Telescope agrolens query=work jump=next

Aliases

Using aliases its possible to create a new query name where its a list of other queries like

agrolens = {
...
    aliases = {
        yamllist = "docker-compose,github-workflow-steps",
        work = "cheflxchost,github-workflow-steps,pytest",
    },
},

Using the query yamllist makes a combination of docker-compose, github-workflow-steps queries.

Json/Yaml/etc

Some file formats just doesn't fit into the category labels so custom ones have been made for different formats for json/yaml. See SUPPORTED

Custom queries

You can place your custom queries in ~/.config/nvim/queries you can load them just as with the build-in queries. So adding myspecial as ~/.config/nvim/queries/c/agrolens.myspecial.scm enables you to run

:Telescope agrolens query=myspecial

Generating queries

Agrolens can generate queries (or tries as good as it can) by invoking the generate function on the cursor position with

require("agrolens").generate({}))

Default options are:

OptionsTypeDescription
registercharRegister to copy to. Default ""
in_bufferbooleanCreate a buffer with query, default true
in_registerbooleanCopy query to register (clipboard), default true
full_documentbooleanCreate query for full document/tree
all_capturesbooleanCreate a capture group for every possible combination, default false
include_root_nodebooleaninclude root node, default false

Similar plugins

ziontee113/neo-minimap

Help wanted

I don't use all supported languages and files supported by tree-sitter but if you do and want to contribute please make a MR

See the CONTRIBUTING for details.