Skip to content

michael-a-grammar/mona.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧪 mona.nvim

Lua

A set of elixir extensions and configuration for neovim!

Important

Please note that this is not a replacement for the various LSP implementations available for elixir; it is solely some goodies that I find nice when programming my favourite language in my favourite editor

As mona doesn't use any fancy LSP shenanigans, it is blindingly fast (thanks to ripgrep!) but may prove to be naive in implementation

We rely on regular expressions and conventions in order to work things out - if you consider using mona, please report any inconsistencies!

✨ Features

  • Browse project, application and current buffer directory modules and tests using telescope!

💻 Install

return {
  'michael-a-grammar/mona.nvim',

  dependencies = {
    'nvim-lua/plenary.nvim',
    'nvim-telescope/telescope.nvim',
  },
}

🚀 Usage

Note

You don't strictly have to do the below if you don't mind elixir-specific shortcuts clobbering your keymap!

  • Create a elixir filetype plugin where your neovim configuration resides (typically ~/.config/nvim/) if one doesn't already exist
if [ ! -f ~/.config/nvim/after/ftplugin/elixir.lua ]; then
    mkdir -p ~/.config/nvim/after/ftplugin/
    touch ~/.config/nvim/after/ftplugin/elixir.lua
fi
  • Add the following keymap to the above file to bind searching for elixir modules within your current project

Note

Or, as above, if you're not fussed about the shortcut being set for every filetype, add it to where you usually define keymaps

local mona = require('telescope').extensions.mona
local bufnr = vim.api.nvim_get_current_buf()

vim.keymap.set({ 'n', 'x' }, '<leader>mp', mona.elixir_project_modules, {
  desc = 'Project Modules',
  buffer = bufnr, -- exclude setting this key if not defining the keymap within the `elixir` filetype plugin
  noremap = true,
})
  • You can also call the telescope picker via the following vim command - :Telescope mona elixir_project_modules

Tip

You can load the telescope extension early to get tab completion when typing the above command

local telescope = require('telescope')

telescope.load_extension('mona')

🔭 Telescope Pickers

mona exposes the following telescope pickers as well as the elixir_project_modules picker shown in the example above

They each rely on convention to find relevant results, disclosed below

elixir_project_modules

To discern the root, project directory:

  • From the current working directory, we attempt to find a .git directory by searching upwards through the directory tree

  • We relay an error message if a .git directory cannot be found

  • Within the directory that the .git directory is found, we check for the existence of a mix.exs file

  • From here, a simple ripgrep query is launched to populate a telescope picker with every descendant .ex file that contains one or more module definitions

elixir_application_modules

To discern the application directory:

  • From the current buffer directory, we attempt to find a mix.exs file by searching upwards through the directory tree

  • We relay an error message if a mix.exs file cannot be found or if the found mix.exs file is the project-level one

  • From here, a simple ripgrep query is launched to populate a telescope picker with every descendant .ex file that contains one or more module definitions

elixir_buffer_directory_modules

From the current buffer directory, a simple ripgrep query is launched to populate a telescope picker with every descendant .ex file that contains one or more module definitions

tests

There are also equivalents to each of the above available specifically for tests

These work in much the same way except each ripgrep query is configured to find descendant .exs files that contain one or more module definitions suffixed with test

  • elixir_project_tests
  • elixir_application_tests
  • elixir_buffer_directory_tests

🕰️ Coming Soon

  • Improved module navigation

💕 Attributions

Projects that have either inspired or helped with the development of mona

mona is also a part of my personal neovim setup, vamp 🎷