Skip to content

markelca/clapi.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clapi.nvim

This is a Neovim plugin that analyzes the entire class/module hierarchy, including the document symbols of parent classes, traits, interfaces, and other inherited elements, giving you a complete view of the API surface.

Why this project?
The telescope.nvim pickers to show document symbols don't include the items' visibility modifiers. This is a fundamental feature to reason about the interfaces you're exposing in order to design a well-architected codebase. Without visibility information, it's difficult to:

  • Understand which methods and properties are part of the public API
  • Identify protected members available to subclasses
  • Distinguish between implementation details and interface contracts

clapi.nvim solves this by providing a complete picture of your class interface (or Class API), making proper API design and navigation significantly easier.


demo.gif

Supported Languages

  • PHP
  • Java
  • More languages coming soon! (Contributions welcome)

Requirements

Installation

Using lazy.nvim

{ -- Add the clapi plugin with its dependencies
  'markelca/clapi.nvim',
  dependencies = {
    'nvim-telescope/telescope.nvim',
    'nvim-treesitter/nvim-treesitter',
    'nvim-lua/plenary.nvim',
  },
},
{ -- Add the following to your telescope configuration
  'nvim-telescope/telescope.nvim',
  config = function()
    require('telescope').setup {
      extensions = {
      -- Configurations for the clapi picker
        clapi = {},
      },
    }
    -- Enable the clapi extension
    pcall(require('telescope').load_extension 'clapi')
    -- Optionally you can set up a keymap to run the picker
    vim.keymap.set('n', '<leader>sa', require('telescope').extensions.clapi.clapi, { desc = '[S]earch [A]pi' })
  end,
}

Full example in my nvim config repository:

Usage

After installation, you can use the picker with:

:Telescope clapi

You can also add parameters

:Telescope clapi show_inherited=false visibility=public

Or in Lua:

-- Call the builtin directly
:lua require('clapi').builtin()
:lua require('clapi').builtin({show_inherited = false, visibility = 'public'}) -- You can pass options to filter the results

-- Call the extension instead. This option will use your default configurations from the telescope config
:lua require('telescope').extensions.clapi.clapi()
:lua require('telescope').extensions.clapi.clapi({show_inherited = false, visibility = 'public'}) -- You can also use parameters this way

Configuration Options

The following options can be configured in the telescope setup:

require('telescope').setup {
  extensions = {
    clapi = {
      -- Show inherited members (default: true)
      show_inherited = true,
      -- Default visibility filter (default: nil - show all)
      -- Examples: "public", "protected", "private"
      visibility = nil,
    },
  },
}

Troubleshooting

Q: No symbols are displayed for my file

  • A: clapi needs treesitter in order to work. The language parsers should have been installed automatically, but make sure they are available:
:TSInstall php
:TSInstall java

Q: Some inherited members are missing

  • A: Check that you have an LSP installed and attached to the current buffer. It may take a few seconds since you open the file.
  • A: The plugin requires proper parsing of the inheritance hierarchy. Ensure your project structure allows the LSP to find parent classes and interfaces.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Submit a pull request

For adding support for a new language, check the following folders for examples:

  • lua/clapi/parser/: Specific parser logic for each language.
  • queries/: Treesitter queries for each language.

About

Display and navigate easily the public interface of your modules

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published