Logo

dev-resources.site

for different kinds of informations.

Enhancing Elixir Development in LazyVim: Quick Documentation Access by Telescope

Published at
12/16/2024
Categories
elixir
lazyvim
neovim
Author
João Paulo Abreu
Categories
3 categories in total
elixir
open
lazyvim
open
neovim
open
Enhancing Elixir Development in LazyVim: Quick Documentation Access by Telescope

When working with Elixir in LazyVim, having quick access to documentation is essential for maintaining a smooth development workflow. This article explores how to set up and use the elixir-extras.nvim plugin to access Elixir documentation directly within your Neovim environment.

Setting Up elixir-extras.nvim

First, you'll need to add the plugin configuration to your LazyVim setup. Create or modify your plugins configuration file with the following code:

return {
  {
    "emmanueltouzery/elixir-extras.nvim",
    lazy = true,
    ft = "elixir",
    dependencies = {
      "nvim-telescope/telescope.nvim",
    },
    keys = {
      { "<leader>ed", function() require("elixir-extras").elixir_view_docs({}) end, desc = "Elixir View Docs" },
      { "<leader>em", function() require("elixir-extras").elixir_view_docs({ include_mix_libs = true }) end, desc = "Elixir View Docs (mix libs)" },
      { "<leader>ec", function() require("elixir-extras").module_complete() end, desc = "Elixir Module Complete" },
    },
    config = function()
      require("elixir-extras").setup_multiple_clause_gutter()
    end,
  },
}

Understanding the Configuration

Let's break down the key components:

  • lazy = true: Enables lazy loading for better startup performance
  • ft = "elixir": Activates the plugin only for Elixir files
  • dependencies: Requires Telescope for the documentation viewer
  • keys: Maps specific key combinations for different documentation features

Key Bindings

The configuration sets up three main key bindings:

  1. <leader>ed: View Elixir core documentation
  2. <leader>em: View documentation including mix dependencies
  3. <leader>ec: Access module completion

Documentation Examples

Here's how the documentation viewer looks in Neovim:

Core Elixir Documentation (<leader>ed)

Core Elixir Documentation showing Enum module

Mix Dependencies Documentation (<leader>em)

Mix Documentation showing ExDoc.Markdown module

Accessing Third-Party Documentation

To ensure documentation for third-party libraries is available, you need to:

  1. Add ex_doc to your project dependencies:
defp deps do
  [
    {:ex_doc, "~> 0.35", only: :dev, runtime: false}
  ]
end
  1. Generate the documentation:
mix deps.get
mix docs

Benefits

This configuration provides several advantages:

  • Instant documentation access without leaving Neovim
  • Seamless integration with LazyVim's existing features
  • Quick access to both core Elixir and third-party documentation
  • Improved development workflow efficiency

Conclusion

By integrating elixir-extras.nvim with LazyVim, you can significantly enhance your Elixir development experience. The quick access to documentation helps maintain flow while coding and reduces context switching between your editor and external documentation sources.

Remember to keep your documentation up to date by running mix docs when adding new dependencies to ensure comprehensive documentation coverage in your development environment.

Featured ones: