Skip to content

ildarisaev/srclib-go

 
 

Repository files navigation

srclib-go Build Status

srclib-go is a srclib toolchain that performs Go code analysis: type checking, documentation generation, jump-to-definition, dependency resolution, etc.

It enables this functionality in any client application whose code analysis is powered by srclib, including:

Screenshots are below.

Installation

This toolchain is not a standalone program; it provides additional functionality to editor plugins and other applications that use srclib.

First, install the src program (see srclib installation instructions).

Then run:

# download and fetch dependencies
go get -v sourcegraph.com/sourcegraph/srclib-go
cd $GOPATH/src/sourcegraph.com/sourcegraph/srclib-go

# build the srclib-go program in .bin/srclib-go (this is currently required by srclib to discover the program)
make

# link this toolchain in your SRCLIBPATH (default ~/.srclib) to enable it
src toolchain add sourcegraph.com/sourcegraph/srclib-go

To verify that installation succeeded, run:

src toolchain list

You should see this srclib-go toolchain in the list.

Now that this toolchain is installed, any program that relies on srclib (such as editor plugins) will support Go.

(TODO(sqs): add a tutorial link)

Screenshot

Here's what srclib-go's analysis looks like in these applications.

The first screenshot shows the http.NewRequest function on Sourcegraph.com. Here, srclib-go enables clickable links for every identifier (that take you to their definitions), automatic cross-repository usage examples, type inference, and documentation generation.

screenshot

The second screenshot shows the emacs-sourcegraph-mode plugin for Emacs with this toolchain installed. Here, srclib-go enables jump-to-definition, type inference, documentation generation, and automatic cross-repository usage examples from Sourcegraph.com. All code analysis is performed locally by srclib using this toolchain.

screenshot

Usage

srclib-go only works with code that exists in a proper GOPATH. When you run the src tool, it should use this GOPATH environment variable.

If you are using an editor plugin that calls src, it may not inherit the correct GOPATH. To ensure it does use the correct GOPATH, try launching your editor from a shell that has GOPATH set to the desired value, or use the editor's internal mechanism (e.g., setenv in Emacs) for setting environment variables.

Srcfile configuration

Go repositories built with this toolchain may specify the following properties in their Srcfile's Config property:

  • GOROOT: a directory that should be used as the GOROOT when building Go packages in the directory tree. If relative, it is made absolute by prefixing the directory containing the Srcfile.

    Setting GOROOT (to .) is how srclib-go builds the standard library from the repository code.google.com/p/go without having the system Go stdlib packages interfere with analysis.

  • GOPATH: a colon-separated list of directories that are appended to the build GOPATH. If relative, the dirs are made absolute by prefixing the directory containing the Srcfile.

    Set GOPATH when you have vendored dependencies within your repository that you import using import paths relative to the vendored dir (as with godep and third_party.go).

Known issues

srclib-go is alpha-quality software. It powers code analysis on Sourcegraph.com but has not been widely tested or adapted for other use cases.

Tests

TODO: needs updating.

Contributing

Patches are welcomed via GitHub pull request! See CONTRIBUTING.md for more information.

srclib-go's type analysis is based on go/types.

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.6%
  • Makefile 1.4%