Skip to content

sourcegraph/sg.nvim

Repository files navigation

sg.nvim

sg.nvim is a plugin focused on bringing many of the features of sourcegraph.com into Neovim.

Status: Alpha (see #Features for currently supported features)

Bug Reporting

If you encounter a bug, please run :SourcegraphInfo and copy the contents of the information into your bug report. It will greatly help in debugging what is happening (and there will probably be some bugs to start... Sorry!)

Setup

Connection

You can connect to an existing Sourcegraph instance using the same environment variables that are used for src-cli. See this for more information.

If you have these environment variables set when opening Neovim, you'll connect to your instance of Sourcegraph

Features:

  • Read files:
    • Directly from sourcegraph links: :edit <sourcegraph url>
      • sg.nvim will automatically add protocols for handling https://sourcegraph.com/* links.
    • Directly from buffer names: :edit sg://github.com/tjdevries/sam.py/-/src/sam.py
    • Use :SourcegraphLink to get a link for the location under your cursor
  • Reading non-files:
    • Repository roots
    • Folders
      • Expand Folders
      • Unexpand Folders
      • Open file from folder
  • Use builtin LSP client to connect to SG
    • Goto Definition
    • Goto References
      • <20 references
      • kind of broken right now for lots of references
  • Basic Search
    • literal, regexp and structural search support
    • type:symbol support
    • repo support
  • Advanced Search Features
    • Autocompletion
    • Memory of last searches
  • More ??

Installation

-- Use your favorite package manager to install, for example in lazy.nvim
return {
  {
    "sourcegraph/sg.nvim",
    build = "cargo build --workspace",
    dependencies = { "nvim-lua/plenary.nvim" },
  },
}

You also need to have the appropriate environment variables to log in to your sourcegraph instance, as described in https://github.com/sourcegraph/src-cli#log-into-your-sourcegraph-instance

Nix(OS)

The project is packaged as a Nix Flake. Consume it as you normally would. In your Nix configuration, make sure that sg-nvim is included both as a Neovim plugin and as an environment/user package (because sg-lsp needs to be on your PATH).

See Neovim guide on NixOS wiki for more details on configuration See gh:willruggiano/neovim.drv for a practical configuration.

For Nix contributors and maintainers:

  • Feel free to nix flake update every once in a while to make sure flake.lock is up-to-date
  • Minimal sg.nvim-integrated neovim package for testing and example
  • Integrate sg.nvim + Cody onto nixpkgs:vimPlugins

You will also need to add the built .cdylib onto package.cpath. Here is one example using gh:willruggiano/neovim.nix:

sg = let
  system = "x86_64-linux";
  package = inputs.sg-nvim.packages.${system}.default;
in {
  inherit package;
  init = pkgs.writeTextFile {
    name = "sg.lua";
    text = ''
      return function()
        package.cpath = package.cpath .. ";" .. "${package}/lib/?.so;${package}/lib/?.dylib"
      end
    '';
  };
};

Setup:

-- Setup the LSP server to attach when you edit an sg:// buffer
require("sg").setup {
  -- Pass your own custom attach function
  --    If you do not pass your own attach function, then the following maps are provide:
  --        - gd -> goto definition
  --        - gr -> goto references
  on_attach = your_custom_lsp_attach_function
}


```vim
" Example mapping for doing searches from within neovim (may change)
nnoremap <space>ss <cmd>lua require('sg.telescope').fuzzy_search_results()<CR>

Demos:

About

Experimental Sourcegraph + Cody plugin for Neovim

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages