Code Monkey home page Code Monkey logo

neogen's Introduction


Neogen - Your Annotation Toolkit

Neovim Lua

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

Installation

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

use {
    "danymat/neogen",
    config = function()
        require('neogen').setup {
            enabled = true
        }
    end,
    requires = "nvim-treesitter/nvim-treesitter"
}

Usage

  • If you want to keep it simple, you can use the :Neogen command:
" will generate annotation for the function you're inside
:Neogen
" or you can force a certain type of annotation.
" It'll find the next upper node that matches the 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.
:Neogen func|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:

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

Calling the generate 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:

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

Cycle between annotations

I added support passing cursor positionings in templates. That means you can now cycle your cursor between different parts of the annotation.

To configure it to the keybind of your choice, you can do something like this:

local opts = { noremap = true, silent = true }
vim.api.nvim_set_keymap("n", "<C-n>", ":lua require('neogen').jump_next()<CR>", opts)
vim.api.nvim_set_keymap("n", "<C-p>", ":lua require('neogen').jump_prev()<CR>", opts)

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

nvim-cmp
local cmp = require('cmp')
local neogen = require('neogen')

local t = function(str)
    return vim.api.nvim_replace_termcodes(str, true, true, true)
end

local check_back_space = function()
    local col = vim.fn.col '.' - 1
    return col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' ~= nil
end

cmp.setup {
    ...

    -- You must set mapping if you want.
    mapping = {
		["<tab>"] = cmp.mapping(function(fallback)
			if neogen.jumpable() then
				vim.fn.feedkeys(t("<cmd>lua require('neogen').jump_next()<CR>"), "")
			else
				fallback()
			end
		end, {
			"i",
			"s",
		}),
		["<S-tab>"] = cmp.mapping(function(fallback)
			if neogen.jumpable(-1) then
				vim.fn.feedkeys(t("<cmd>lua require('neogen').jump_prev()<CR>"), "")
			else
				fallback()
			end
		end, {
			"i",
			"s",
		}),
    },
    ...
}

Configuration

require('neogen').setup {
        enabled = true,             --if you want to disable Neogen
        input_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
		}
	    },
	    ...
    }
}

Supported Languages

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

Languages Annotation Conventions Supported annotation types
c Doxygen ("doxygen") func, file
csharp Xmldoc ("xmldoc")
Doxygen ("doxygen")
func, file, class
cpp Doxygen ("doxygen") func, file, class
go GoDoc ("godoc") func, type
java Javadoc ("javadoc) func, class
javascript JSDoc ("jsdoc") func, class, type, file
jsx JSDoc ("jsdoc") func, class, type, file
lua Emmylua ("emmylua")
Ldoc ("ldoc")
func, class, type, file
php Php-doc ("phpdoc") func, type, class
python Google docstrings ("google_docstrings")
Numpydoc ("numpydoc")
reST ("reST")
func, class, type, file
rust RustDoc ("rustdoc")
Alternative ("alternative")
func, file, class
typescript JSDoc ("jsdoc") func, class, type, file
tsx JSDoc ("jsdoc") func, class, type, file
vue JSDoc ("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

GIFS

screen1

screen3

screen4

Credits

  • Binx, for making that gorgeous logo for free!

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 ๐Ÿ’

neogen's People

Contributors

bryant-the-coder avatar cryptomilk avatar danymat avatar davidgranstrom avatar meijieru avatar ntbbloodbath avatar p00f avatar shatur avatar thomasfeher avatar vhyrro avatar

Watchers

 avatar

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.