Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A better annotation generator. Supports multiple languages and annotation conventions.

License

NotificationsYou must be signed in to change notification settings

danymat/neogen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Neogen - Your Annotation Toolkit

NeovimLua

Table Of Contents

Features

  • Create annotations with one keybind, and jump your cursor in the inserted annotation
  • Defaults for multiple languages and annotation conventions
  • Extremely customizable and extensible
  • Written in lua (and uses Tree-sitter)

screen2

Requirements

Have Tree-sitter parsers installed on your system. For more information, check out the:treesitter-parsers neovim help page.

Installation

Use your favorite package manager to install Neogen, e.g:

Lazy

{"danymat/neogen",config=true,-- Uncomment next line if you want to follow only stable versions-- version = "*"}

Packer

use {"danymat/neogen",config=function()require('neogen').setup {}end,-- Uncomment next line if you want to follow only stable versions-- tag = "*"}

Usage

  • If you want to keep it simple, you can use the:Neogen command:
" will generate annotation for the function, class or other relevant type you're currently in:Neogen" or you can force a certain type of annotation with `:Neogen <TYPE>`" It'll find the next upper node that matches the type `TYPE`" E.g if you're on a method of a class and do `:Neogen class`, it'll find the class declaration and generate the annotation.:Neogenfunc|class|type|...
  • If you like to use the lua API, I exposed a function to generate the annotations.
require('neogen').generate()

You can bind it to your keybind of choice, like so:

localopts= {noremap=true,silent=true }vim.api.nvim_set_keymap("n","<Leader>nf",":lua require('neogen').generate()<CR>",opts)

Calling thegenerate function without any parameters will try to generate annotations for the current function.

You can provide some options for the generate, like so:

require('neogen').generate({type="func"-- the annotation type to generate. Currently supported: func, class, type, file})

For example, I can add an other keybind to generate class annotations:

localopts= {noremap=true,silent=true }vim.api.nvim_set_keymap("n","<Leader>nc",":lua require('neogen').generate({ type = 'class' })<CR>",opts)

Snippet support

We added snippet support, and we provide defaults for some snippet engines.And this is done via thesnippet_engine option in neogen's setup:

  • snippet_engine option will use provided engine to place the annotations:

Currently supported:luasnip,snippy,vsnip,nvim,mini.

require('neogen').setup({snippet_engine="luasnip"})

That's all ! You can now use your favorite snippet engine to control the annotation, like jumping between placeholders.

Or, if you want to return the snippet as a string (to integrate with other snippet engines, for example),you can do it by using thereturn_snippet option in thegenerate function:

  • return_snippet option will return the annotations as lsp snippets.
localsnippet,row,col=require('neogen').generate({snippet_engine="luasnip"})

And then pass the snippet to the plugin's snippet expansion function.

Default cycling support

Note that this part is only useful if you don't use the snippets integration.

If you don't want to use a snippet engine with Neogen, you can leverage Neogen's native jumps between placeholders.To map some keys to the cycling feature, you can do like so:

localopts= {noremap=true,silent=true }vim.api.nvim_set_keymap("i","<C-l>",":lua require('neogen').jump_next<CR>",opts)vim.api.nvim_set_keymap("i","<C-h>",":lua require('neogen').jump_prev<CR>",opts)

Or, if you want to use a key that's already used for completion purposes, take a look at the code snippet here:

nvim-cmp
localcmp=require('cmp')localneogen=require('neogen')cmp.setup {...-- You must set mapping if you want.mapping= {        ["<tab>"]=cmp.mapping(function(fallback)ifneogen.jumpable()thenneogen.jump_next()elsefallback()endend, {"i","s",        }),        ["<S-tab>"]=cmp.mapping(function(fallback)ifneogen.jumpable(true)thenneogen.jump_prev()elsefallback()endend, {"i","s",        }),    },...}

Configuration

require('neogen').setup {enabled=true,--if you want to disable Neogeninput_after_comment=true,-- (default: true) automatic jump (with insert mode) on inserted annotation-- jump_map = "<C-e>"       -- (DROPPED SUPPORT, see [here](#cycle-between-annotations) !) The keymap in order to jump in the annotation fields (in insert mode)}

If you're not satisfied with the default configuration for a language, you can change the defaults like this:

require('neogen').setup {enabled=true,languages= {lua= {template= {annotation_convention="emmylua"-- for a full list of annotation_conventions, see supported-languages below,...-- for more template configurations, see the language's configuration file in configurations/{lang}.lua                }        },...    }}

For example, if you want to quickly add support for new filetypes based around existing ones, you can do like this:

require('neogen').setup({languages= {        ['cpp.doxygen']=require('neogen.configurations.cpp')    }})

Supported Languages

There is a list of supported languages and fields, with their annotation style

LanguagesAnnotation ConventionsSupported annotation types
shGoogle Style Guide ("google_bash")func,file
cDoxygen ("doxygen")func,file,type
csXmldoc ("xmldoc")
Doxygen ("doxygen")
func,file,class
cppDoxygen ("doxygen")func,file,class
goGoDoc ("godoc")func,type
javaJavadoc ("javadoc)func,class,type
javascriptJSDoc ("jsdoc")func,class,type,file
javascriptreactJSDoc ("jsdoc")func,class,type,file
juliaJulia ("julia")func,class
kotlinKDoc ("kdoc")func,class
luaEmmylua ("emmylua")
Ldoc ("ldoc")
func,class,type,file
phpPhp-doc ("phpdoc")func,type,class
pythonGoogle docstrings ("google_docstrings")
Numpydoc ("numpydoc")
reST ("reST")
func,class,type,file
rubyYARD ("yard")
Rdoc ("rdoc")
Tomdoc ("tomdoc")
func,type,class
rustRustDoc ("rustdoc")
Alternative ("rust_alternative")
func,file,class
typescriptJSDoc ("jsdoc")
TSDoc ("tsdoc")
func,class,type,file
typescriptreactJSDoc ("jsdoc")
TSDoc ("tsdoc")
func,class,type,file
vueJSDoc ("jsdoc")func,class,type,file

Adding Languages

  1. Using the defaults to generate a new language support:Adding Languages
  2. (advanced) Only if the defaults aren't enough, please see here:Advanced Integration

Tip: Take a look at this beatiful diagram, showing a representation of the codebase. You can then take a first understanding of what is under the hood. For more details, you can see:h neogen-develop.

Visualization of this repo

Tests

Run tests using this command

maketest

GIFS

screen1

screen3

screen4

Credits

Support

You like my plugin and want to express your gratitude 👼 ? You can suppport me by donating the equivalent of my morning coffee (no minimum required). I would really appreciate your support as it can motivate me to continue this journey 💝

About

A better annotation generator. Supports multiple languages and annotation conventions.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors48

Languages


[8]ページ先頭

©2009-2025 Movatter.jp