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.
- PHP
- Java
- More languages coming soon! (Contributions welcome)
- Neovim (0.7.0+)
- telescope.nvim
- nvim-treesitter
- plenary.nvim
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:
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
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,
},
},
}
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.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- 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.