Skip to content

cached treesitter navigation on a big projects, an attempt to make navigation in large c# projects better

License

Notifications You must be signed in to change notification settings

leblocks/hopcsharp.nvim

Repository files navigation

hopcsharp.nvim

Cached treesitter navigation on a big projects, an attempt to make navigation in large c# projects better

Description

hopcsharp is a lightweight code navigation tool inspired by ctags, built for large C# projects. It uses tree-sitter to quickly parse code and store marks in a SQLite database for fast access, after that you can navigate freely in code base using built in methods or writing queries on your own against sqlite database. Important to understand that this is not an LSP server this tool is intended for code navigation and read. It won't be as precise as full blown LSP server but it won't require you to compile code as well :) so basically any c# codebase can be opened and parsed with this plugin.

I hope that there will be people's interest and contributions as well. I'll try to improve it little by little.

bvT1Q.gif

How does it work?

hopcsharp parses code base with help of tree-sitter and stores data on type locations \ definitions in local sqlite database. This database provides data for navigation in code. It won't be as precise as LSP but it provides a fast way with pretty good precision for navigation in a codebase.

Requirements

  • sqlite.lua

    • windows may require you to download sqlite dll and additional configuration, take a look at installation instructions.
  • fd to be on PATH

  • c_sharp tree-sitter grammer installed

Installation

Using packer.nvim:

use({ 'leblocks/hopcsharp.nvim', requires = { { 'kkharji/sqlite.lua' } } })

Quick Start

Example keybinding configuration:

local hopcsharp = require('hopcsharp')

-- database
vim.keymap.set('n', '<leader>hD', hopcsharp.init_database, { desc = 'hopcsharp: init database' })

-- navigation
vim.keymap.set('n', '<leader>hd', hopcsharp.hop_to_definition, { desc = 'hopcsharp: go to definition' })
vim.keymap.set('n', '<leader>hi', hopcsharp.hop_to_implementation, { desc = 'hopcsharp: go to implementation' })
vim.keymap.set('n', '<leader>hr', hopcsharp.hop_to_reference, { desc = 'hopcsharp: go to reference' })
vim.keymap.set('n', '<leader>ht', hopcsharp.get_type_hierarchy, { desc = 'hopcsharp: type hierarchy' })

-- fzf pickers (requires fzf-lua)
local pickers = require('hopcsharp.pickers.fzf')
vim.keymap.set('n', '<leader>hf', pickers.source_files, { desc = 'hopcsharp: find source files' })
vim.keymap.set('n', '<leader>ha', pickers.all_definitions, { desc = 'hopcsharp: all definitions' })
vim.keymap.set('n', '<leader>hc', pickers.class_definitions, { desc = 'hopcsharp: class definitions' })
vim.keymap.set('n', '<leader>hn', pickers.interface_definitions, { desc = 'hopcsharp: interface definitions' })
vim.keymap.set('n', '<leader>he', pickers.enum_definitions, { desc = 'hopcsharp: enum definitions' })

API

This plugin exposes only a small set of functions, allowing you to build various interfaces and workflows on top of them.

init_database

require('hopcsharp').init_database()

This function launches the database initialization process in a separate headless Neovim instance to avoid blocking the current session.

hop_to_definition

require('hopcsharp').hop_to_definition(config)

Opens new buffer or switches to existing one on a line and column where definition is defined. If it finds more than one definition it will add those to quickfix list and will open it. See :h hopcsharp.hop_to_definition for more details.

hop_to_implementation

require('hopcsharp').hop_to_implementation(config)

Opens new buffer or switches to existing one on a line and column where implementation is defined. If it finds more than one implementation it will add those to quickfix list and will open it. See :h hopcsharp.hop_to_definition for more details.

hop_to_reference

require('hopcsharp').hop_to_reference(config)

Opens new buffer or switches to existing one on a line and column where reference is defined. If it finds more than one reference it will add those to quickfix list and will open it. See :h hopcsharp.hop_to_reference for more details.

get_type_hierarchy

require('hopcsharp').get_type_hierarchy()

Opens read-only buffer with type hierarchy.

get_db

require('hopcsharp').get_db()

Returns opened sqlite_db object, you can create custom flows querying it with SQL queries from lua. See :h hopcsharp.get_db for more details.

FZF Pickers

hopcsharp ships with built-in fzf-lua pickers for browsing definitions and source files. Requires the fzf-lua plugin to be installed.

All pickers are available via require('hopcsharp.pickers.fzf'):

Picker Description
source_files Browse all .cs source files in the database
all_definitions Browse all definitions
class_definitions Browse class definitions
interface_definitions Browse interface definitions
method_definitions Browse method definitions
struct_definitions Browse struct definitions
enum_definitions Browse enum definitions
record_definitions Browse record definitions
attribute_definitions Browse attribute definitions

See :h hopcsharp-fzf-pickers for more details.

About

cached treesitter navigation on a big projects, an attempt to make navigation in large c# projects better

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published