• This repository has been archived on 12/Oct/2022
  • Stars
    star
    1,163
  • Rank 40,128 (Top 0.8 %)
  • Language
    Go
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go language server to add Go support to editors and other tools that use the Language Server Protocol (LSP)

Go Language Server Build Status

Note: We have deprioritized work on this language server for use in editors in favor of Google's Go language server, gopls. It is in the best interests of the community to only have a single language server.

go-langserver is a Go language server that speaks Language Server Protocol. It supports editor features such as go-to-definition, hover, and find-references for Go projects.

Open in Sourcegraph

To build and install the standalone go-langserver run

go get -u github.com/sourcegraph/go-langserver

Support

Hover Jump to def Find references Workspace symbols VFS extension Isolated Parallel
Go

InitializationOptions

If you are a client wanting to integrate go-langserver, you can use the following as initializationOptions in your initialize request to adjust the behaviour:

interface GoInitializationOptions {
  /**
   * funcSnippetEnabled enables the returning of argument snippets
   * on `func` completions, eg. func(foo string, arg2 bar).
   * Requires code completion to be enabled.
   *
   * Defaults to true if not specified.
   */
  funcSnippetEnabled?: boolean;

  /**
   * gocodeCompletionEnabled enables code completion feature (using gocode).
   *
   * Defaults to false if not specified.
   */
  gocodeCompletionEnabled?: boolean;

  /**
   * formatTool decides which tool is used to format documents. Supported: goimports and gofmt.
   *
   * Defaults to goimports if not specified.
   */
  formatTool?: "goimports" | "gofmt";


  /**
   * lintTool decides which tool is used for linting documents. Supported: none and golint
   *
   * Diagnostics must be enabled for linting to work.
   *
   * Defaults to none if not specified.
   */
  lintTool?: "none" | "golint";

  /**
   * goimportsLocalPrefix sets the local prefix (comma-separated string) that goimports will use.
   *
   * Defaults to empty string if not specified.
   */
  goimportsLocalPrefix?: string;

  /**
   * MaxParallelism controls the maximum number of goroutines that should be used
   * to fulfill requests. This is useful in editor environments where users do
   * not want results ASAP, but rather just semi quickly without eating all of
   * their CPU.
   *
   * Defaults to half of your CPU cores if not specified.
   */
  maxParallelism?: number;

  /**
   * useBinaryPkgCache controls whether or not $GOPATH/pkg binary .a files should
   * be used.
   *
   * Defaults to true if not specified.
   */
  useBinaryPkgCache?: boolean;

  /**
   * DiagnosticsEnabled enables handling of diagnostics.
   *
   * Defaults to false if not specified.
   */
  diagnosticsEnabled?: boolean;
}

Debugging Go code intelligence

Additional configuration for Go code intelligence may be required in some cases:

Custom GOPATHs / Go monorepos

By default, Sourcegraph assumes that Go code in a repository represents Go packages that would be placed under $GOPATH/src/.... That is, a Go repository is assumed to only contain Go packages.

For some repositories, such as Go monorepos, this may not be the case. These repositories typically have an entire (or multiple) $GOPA TH directories comitted to them, and the Go language server may not be able to provide code intelligence without being informed of thi s.

To inform Sourcegraph's Go language server that your repository contains an entire $GOPATH directory, you can use one of three option s:

  1. Auto-detection via .vscode/settings.json

    Sourcegraph will automatically detect a Visual Studio Code settings.json file with a GOPATH configuration. You may already have o ne of these files if you are using Visual Studio Code with the Go extension. The file .vscode/settings.json would look like:

    {
      "go.gopath": "${workspaceRoot}/YOUR_GOPATH"
    }

    In this case, Sourcegraph would look for a folder named YOUR_GOPATH in the root of the repository.

  2. Auto-detection via .envrc

    Sourcegraph will also automatically detect a GOPATH from an .envrc file in the root of the repository. You may already have one of these if you are using direnv. For example a file such as:

    export GOPATH=${PWD}/third_party
    GOPATH_add code:code2
    GOPATH_add /absolute

    Would lead to Sourcegraph using a final GOPATH of third_party:code:code2. Note that we will ignore any /absolute path, and that we do not execute .envrc files but rather scan them for simple syntax such as the above. If you use a more complex .envrc file to build your GOPATH, this auto-detection may not work for you.

  3. Manual configuration via .sourcegraph/config.json

    If you add a .sourcegraph/config.json file in the root directory of your repository, Sourcegraph will use this configuration to determine the GOPATH instead of the auto-detection methods described above. An example configuration is:

    {
      "go": {
        "GOPATH": ["/third_party", "code"]
      }
    }

    Sourcegraph will use a final GOPATH of third_party:code. That is, it will assume the third_party and code directories in the root of the repository are to be used as $GOPATH directories.

Vanity import paths

When the Go language server encounters a vanity import path, it must be able to locate the source code for it or else code intelligence will not work for code related to that dependency.

For example, consider a repository github.com/example/server which contains Go code with an import "example.io/pkg/logger" statement.

  1. If the source code for example.io/pkg/logger is located under a vendor directory, Sourcegraph will use that in the same manner that the go tool would.

  2. If the source code for example.io/pkg/logger is inside of the current repository at e.g. github.com/example/pkg/logger, Sourcegraph will look for it by scanning the repository for a canonical import path comment using some heuristics.

    • For example, if Sourcegraph finds a canonical import path comment such as package logger // import "example.io/pkg/logger" in the pkg/logger directory of the repository, Sourcegraph will assume that the code in the pkg/logger directory is what should be used when a import "example.io/pkg/logger" statement is seen.
    • Note that Sourcegraph only needs to find one such comment for the example.io domain in order to resolve all other vanity imports. That is, placing this comment in pkg/logger/logger.go is enough for Sourcegraph to know how to import any package under example.io/....
    • Sometimes the Go language server's heuristics are not able to locate a canonical import path comment in a repository, in which case you can specify the root import path of your repository directly by placing a .sourcegraph/config.json file in the root of your repository, e.g.:
    {
      "go": {
        "RootImportPath": "example.io/pkg"
      }
    }

    Which would tell the Go language server to clone github.com/example/pkg into $GOPATH/src/example.io/pkg.

  3. Otherwise, Sourcegraph will attempt to fetch example.io/pkg/logger via the network using go get example.io/pkg/logger.

Profiling

If you run into performance issues while using the language server, it can be very helpful to attach a CPU or memory profile with the issue report. To capture one, first install Go, start go-langserver with the pprof flag (e.g. $GOPATH/bin/go-langserver -pprof :6060) and then:

Capture a heap (memory) profile:

go tool pprof -svg $GOPATH/bin/go-langserver http://localhost:6060/debug/pprof/heap > heap.svg

Capture a CPU profile:

go tool pprof -svg $GOPATH/bin/go-langserver http://localhost:6060/debug/pprof/profile > cpu.svg

Since these capture the active resource usage, it's best to run these commands while the issue is occurring (i.e. while memory or CPU is high).

More Repositories

1

sourcegraph

Code AI platform with Code Search & Cody
Go
9,777
star
2

conc

Better structured concurrency for go
Go
6,764
star
3

checkup

Distributed, lock-free, self-hosted health checks and status pages
Go
3,392
star
4

cody

Type less, code more: Cody is an AI code assistant that uses advanced search and codebase context to help you write and fix code.
TypeScript
2,348
star
5

thyme

Automatically track which applications you use and for how long.
Go
2,237
star
6

appdash

Application tracing system for Go, based on Google's Dapper.
Go
1,720
star
7

webloop

WebLoop: Scriptable, headless WebKit with a Go API. Like PhantomJS, but for Go.
Go
1,357
star
8

srclib

srclib is a polyglot code analysis library, built for hackability. It consists of language analysis toolchains (currently for Go and Java, with Python, JavaScript, and Ruby in beta) with a common output format, and a CLI tool for running the analysis.
Go
944
star
9

doctree

First-class library documentation for every language (based on tree-sitter), with symbol search & more. Lightweight single binary, run locally or self-host. Surfaces usage examples via Sourcegraph.
Go
848
star
10

javascript-typescript-langserver

JavaScript and TypeScript code intelligence through the Language Server Protocol
TypeScript
792
star
11

sg.nvim

Experimental Sourcegraph + Cody plugin for Neovim
Lua
707
star
12

go-diff

Unified diff parser and printer for Go
Go
407
star
13

thesrc

Example of a 3-layer (frontend, API, datastore) Go web app (based on the code that powers https://sourcegraph.com)
Go
396
star
14

go-selenium

Selenium WebDriver client for Go
Go
364
star
15

go-webkit2

WebKit API bindings (WebKitGTK+ v2) for Go
Go
305
star
16

syntaxhighlight

Go package for syntax highlighting of code
Go
263
star
17

src-cli

Sourcegraph CLI
Go
261
star
18

scip

SCIP Code Intelligence Protocol
Go
257
star
19

zoekt

Fast trigram based code search
Go
229
star
20

prototools

documentation generator & other tools for protobuf/gRPC
Go
162
star
21

jsonrpc2

Package jsonrpc2 provides a client and server implementation of JSON-RPC 2.0 (http://www.jsonrpc.org/specification)
Go
159
star
22

awesome-code-ai

A list of AI coding tools (assistants, completions, refactoring, etc.)
157
star
23

careers

Want to work at Sourcegraph?
132
star
24

openctx

See contextual info about code from your dev tools, in your editor, code review, and anywhere else you read code.
TypeScript
122
star
25

lsif-go

Language Server Indexing Format (LSIF) generator for Go
Go
111
star
26

deploy-sourcegraph

Deploy Sourcegraph to a Kubernetes cluster for large-scale code search and intelligence
Shell
104
star
27

python-langserver

Language server which talks LSP via JSONRPC for Python.
Python
102
star
28

emacs-lsp

LSP support for Emacs
Emacs Lisp
102
star
29

apiproxy

apiproxy proxies HTTP/REST APIs with configurable cache timeouts, etc.
Go
96
star
30

syntect_server

HTTP code syntax highlighting server written in Rust.
Rust
89
star
31

handbook

📘 The Sourcegraph handbook
TypeScript
87
star
32

llmsp

LLM-power language server protocol implementation.
Go
85
star
33

about

Sourcegraph blog, feature announcements, and website (about.sourcegraph.com)
TypeScript
84
star
34

sourcegraph-vscode-DEPRECATED

*️⃣+ 🆚 = ❤️
TypeScript
83
star
35

go-vcs

manipulate and inspect VCS repositories in Go
Go
77
star
36

deploy-sourcegraph-docker

Sourcegraph with Docker Compose deployment reference
Shell
73
star
37

go-lsp

Go types for the messages used in the Language Server Protocol.
Go
71
star
38

scip-java

SCIP Code Intelligence Protocol (LSIF) generator for Java
Java
60
star
39

docsite

The documentation site used by Sourcegraph
Go
57
star
40

codenotify

Go
55
star
41

codeintellify

Adds code intelligence to code views on the web ✨
TypeScript
55
star
42

jetbrains

Kotlin
54
star
43

browser-extensions

Sourcegraph's browser extensions: MOVED. See https://docs.sourcegraph.com/integration/browser_extension.
TypeScript
49
star
44

go-ses

Amazon AWS Simple Email Service (SES) client for Go
Go
49
star
45

emacs-cody

Sourcegraph Cody in Emacs
Emacs Lisp
48
star
46

sourcegraph-extension-api

Sourcegraph extension API: use and build extensions that enhance reading and reviewing code in your existing tools. "The extension API you wish your code host had."
TypeScript
44
star
47

srclib-cpp

43
star
48

go-sourcegraph

Go
43
star
49

scip-typescript

SCIP indexer for TypeScript and JavaScript
TypeScript
43
star
50

go-template-lint

Linter for Go text/template (and html/template) template files
Go
40
star
51

android-sdk-jars

HTML
40
star
52

run

🏃‍♂️ A new way to execute commands and manipulate command output in Go
Go
40
star
53

codesearch.ai

codesearch.ai semantic code search engine
Go
36
star
54

sourcegraph-jetbrains

Sourcegraph for JetBrains IDEs (IntelliJ)
Java
36
star
55

docs

Web app and content for the new Sourcegraph documentation.
TypeScript
35
star
56

lsif-node

Language Server Indexing Format (LSIF) generator for JavaScript and TypeScript
TypeScript
35
star
57

sourcegraph-typescript

Provides code intelligence for TypeScript
TypeScript
34
star
58

lsif-py

Language Server Indexing Format (LSIF) generator for Python
Python
31
star
59

srclib-c

Makefile
30
star
60

srclib-go

Go toolchain for srclib
Go
29
star
61

lsp-adapter

lsp-adapter provides a proxy which adapts Sourcegraph LSP requests to vanilla LSP requests
Go
29
star
62

s3cache

Amazon S3 storage interface for a Go cache
Go
29
star
63

srclib-python

Python
28
star
64

pydep

a simple command line tool / package that prints the dependencies of a python project
Python
28
star
65

app

Issue tracker for the Sourcegraph app - a lightweight single-binary version of Sourcegraph for your local machine
27
star
66

sg

sg releases
27
star
67

helix-docker

Docker images for Perforce Helix
Dockerfile
27
star
68

code-intel-extensions

Provides precise code intelligence via LSIF and Language Servers, and fuzzy code intelligence using ctags and text search
TypeScript
26
star
69

scip-clang

C++
25
star
70

makex

makex is a "make" clone for Go that makes it easier to write build tools in Go. It lets you define tasks and dependencies in the familiar Makefile format, and unlike just shelling out to "make", it gives you programmatic access (in Go) to the progress and console output of your tasks.
Go
24
star
71

scip-python

SCIP indexer for Python
Python
23
star
72

codemod

A collection of codemods powered by TS-Morph and PostCSS
TypeScript
23
star
73

jsonx

Extended JSON parser and writer for Go
Go
21
star
74

srclib-csharp

placeholder for a srclib C# toolchain
C#
20
star
75

learn

Sourcegraph Learn: an educational hub to support all developers
TypeScript
19
star
76

lsif-jsonnet

Language Server Index Format (LSIF) generator for JSonnet
Go
19
star
77

vcsstore

vcsstore stores VCS repositories and makes them accessible via HTTP
Go
19
star
78

sourcegraph-sublime

Sourcegraph for Sublime Text 3
Python
18
star
79

sourcegraph-git-extras

A Sourcegraph extension that adds Git blame and other useful features to code views on Sourcegraph, GitHub, GitLab, etc.
TypeScript
18
star
80

xconf

xconf.io is a config file search engine built on the Sourcegraph (https://sourcegraph.com) API. It currently supports Dockerfiles.
Go
18
star
81

go-jsonschema

EXPERIMENTAL: A Go library for working with JSON Schema (draft-07): parsing schemas, generating Go types from a JSON Schema
Go
17
star
82

themes

Color themes for Sourcegraph and editors
Shell
17
star
83

talks

Talks given about Sourcegraph or by Sourcegraphers
Go
17
star
84

phabricator-extension

Get code intelligence on Phabricator
PHP
16
star
85

httpfstream

httpstream provides HTTP handlers for simultaneous streaming uploads and downloads of objects, as well as persistence and a standalone server.
Go
16
star
86

batch-change-examples

A collection of examples for Batch Changes
Python
16
star
87

sourcegraph-alfred

Sourcegraph workflow for Alfred
Python
15
star
88

gen-mocks

Go
14
star
89

sbt-sourcegraph

sbt plugin to upload LSIF indexes to Sourcegraph for precise code intelligence
Scala
13
star
90

go-vcsurl

Lenient VCS repository URL parsing library for Go
Go
13
star
91

srclib-javascript

JavaScript (node.js) toolchain for srclib
JavaScript
12
star
92

appmon

Appmon tracks API calls in Web applications that use Go.
Go
12
star
93

srclib-php

PHP toolchain for srclib (https://srclib.org) - WORK IN PROGRESS
PHP
12
star
94

yj

Convert YAML to JSON
Go
12
star
95

go-papertrail

Go API client for papertrail (https://papertrailapp.com), a hosted log management service.
Go
12
star
96

log

OpenTelemetry-compatible Zap logger for Sourcegraph
Go
11
star
97

scip-go

SCIP indexer for Golang
Go
11
star
98

annotate

Go package for applying multiple sets of annotations to a region of text
Go
11
star
99

codesearchguide.org

Everything you ever wanted to know about code search. (WIP, will be online soon!)
CSS
11
star
100

multicache

Package multicache provides a "fallback" cache implementation that short-circuits gets and writes/deletes to all underlying caches.
Go
11
star