Coder Social home page Coder Social logo

sg.nvim's Introduction

sg.nvim

Status: Beta

Table of Contents

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

Setup

To configure logging in:

  • Log in on your Sourcegraph instance.
  • Click your user menu in the top right, then select Settings > Access tokens.
  • Create your access token, and then run :SourcegraphLogin in your neovim editor after installation.
  • Type in the link to your Sourcegraph instance (for example: https://sourcegraph.com)
  • And then paste in your access token.

An alternative to this is to use the environment variables specified for src-cli.

You can check that you're logged in by then running :checkhealth sg

Installation

Requirements

Requires:

  • nvim 0.9 or nvim nightly
  • Node.js >= 18.17.0 (LTS) at runtime for cody-agent.js

(By default, sg.nvim downloads released binaries from Github. If you prefer to build the plugin yourself, you'll need cargo to build)

  • Currently uses plenary.nvim and telescope.nvim for some features.
    • If you would like to use something else for search functionality, please make an issue and I can look into adding support.

Install

lazy.nvim
-- Use your favorite package manager to install, for example in lazy.nvim
--  Optionally, you can also install nvim-telescope/telescope.nvim to use some search functionality.
return {
  {
    "sourcegraph/sg.nvim",
    dependencies = { "nvim-lua/plenary.nvim", --[[ "nvim-telescope/telescope.nvim ]] },

    -- If you have a recent version of lazy.nvim, you don't need to add this!
    build = "nvim -l build/init.lua",
  },
}
packer.nvim
-- Packer.nvim, also make sure to install nvim-lua/plenary.nvim
use { 'sourcegraph/sg.nvim', run = 'nvim -l build/init.lua' }

-- You'll also need plenary.nvim
use { 'nvim-lua/plenary.nvim' }

-- And optionally, you can install telescope for some search functionality
--  "nvim-lua/plenary.nvim", --[[ "nvim-telescope/telescope.nvim ]] 
vim-plug
" Using vim-plug
Plug 'sourcegraph/sg.nvim', { 'do': 'nvim -l build/init.lua' }

" Required for various utilities
Plug 'nvim-lua/plenary.nvim'

" Required if you want to use some of the search functionality
Plug 'nvim-telescope/telescope.nvim'

After installation, run :checkhealth sg.

(Nix instructions at the end of the readme)

Configuration:

-- Sourcegraph configuration. All keys are optional
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
}
" Example mapping for doing searches from within neovim (may change) using telescope.
" (requires telescope.nvim to be installed)
nnoremap <space>ss <cmd>lua require('sg.extensions.telescope').fuzzy_search_results()<CR>

Demos:

Features:

Cody:

  • Chat interface and associated commands
  • Autocompletions, prompted
  • Autocompletions, suggested

Sourcegraph Browsing:

  • 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? Make an issue with something you're missing :)

Nix(OS)

The project is packaged as a Nix Flake. Consume it as you normally would. For reference, see:

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"
      end
    '';
  };
};

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

sg.nvim's People

Contributors

tjdevries avatar pjlast avatar mrnugget avatar willruggiano avatar pegasust avatar willothy avatar camdencheek avatar vividboarder avatar jhchabran avatar keegancsmith avatar fearphage avatar thehamsta avatar lattay avatar renovate[bot] avatar dechnik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.