Coder Social home page Coder Social logo

sourcegraph.nvim's Introduction

SourceGraph for NeoVIM

Query SourceGraph from NeoVIM, display search results and open local files directly from search.

ezgif-3-da68b59bd3

Installation

This plugin has a hard dependency on plenary.nvim since standard nvim lua library can't make web requests. So install those two plugins together.

Also for quickstart you can install fzf plugin, for which there are basic commands predefined already.

Minimal setup

Using plug:

Plug 'nvim-lua/plenary.nvim'
Plug 'fspv/sourcegraph.nvim'

Recommended setup

Using plug:

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'nvim-lua/plenary.nvim'
Plug 'fspv/sourcegraph.nvim'
Plug 'nvim-telescope/telescope.nvim'

TODO: add packer instructios

Quickstart

Assumptions before starting using the plugin:

  • You're using a git repo
  • Your repo is indexed by the SourceGraph instance (either public or a private one)
  • Your current nvim cwd is the root of the repo you're trying to search
  • You have used recommended setup from the installation section
  • Sourcegraph knows your repo with the same path that is returned by git remote -v (excluding .git suffix, username and protocol)
  • Git upstream for the current branch is set to the branch, which contains commits, indexed by sourcegraph (otherwise, reset it with git branch --set-upstream-to)

Those assumptions should be the most common case, if you're already using sourcegraph with your repo, so just give it a go.

To search anything in the current repository, just enter:

:SourceGraph query123

If that worked, you've set up everything correctly, enjoy. You can also use sg/ shortcut to search a word under cursor.

In case that doesn't work, try the version, which doesn't add any git-related parameters

:SourceGraphRaw query123

Custom repo

Setting up a custom repo is as easy as calling

lua << EOF
require("sourcegraph").setup(
  {
    api_url = "https://sourcegraph.yourdomain.com/.api",
    api_token = "abcde"
  }
)
EOF

Telescope plugin

Telescope plugin provides you an ability to search as you type. Theoretically it is possible to make it with fzf as well, but it wasn't implemented in plugin yet.

By default the search scope is not limited by a particular repo or revision. You have to define a custom query prefix to search in your current repo. There is a vimscript function already defined (works only with git at the moment, see the assumptions above), to use it, you can do this:

require("telescope").setup {
  extensions = {
    sourcegraph = {
      query_prefix_function = function()
        return vim.fn["sourcegraph#construct_local_repo_query"]()
      end
    },
  },
}

require("telescope").load_extension("sourcegraph")

To search SourceGraph with Telescope, you can run this:

:Telescope sourcegraph

Or using lua

:lua require('telescope').extensions.sourcegraph.sourcegraph()

TODO

  • Add lsp to complete search

sourcegraph.nvim's People

Contributors

fspv avatar

Stargazers

 avatar  avatar

Watchers

 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.