• Stars
    star
    523
  • Rank 84,684 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 5 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 extension using gopls for coc.nvim.

coc-go

Go language server extension using gopls for coc.nvim.

Install

In your vim/neovim, run this command:

:CocInstall coc-go

Features

See gopls

Commands

Additional to commands provided by gopls, this extensions provides these commands:

Key Description
go.gopls.tidy Run gopls.tidy LSP command
go.impl.cursor Generate interface stubs
go.install.gomodifytags Install / update gomodifytags
go.install.goplay Install / update goplay
go.install.gopls Install / update gopls
go.install.gotests Install / update gotests
go.install.impl Install / update impl
go.install.tools Install / update all tools
go.playground Run on go playground
go.tags.add Add tags to struct fields
go.tags.add.line Add tags to struct field in current line
go.tags.add.prompt Add tags to struct fields (prompt)
go.tags.clear Remove all tags from struct fields
go.tags.clear.line Remove all tags from struct fields in current line
go.tags.remove Remove tags from struct fields
go.tags.remove.line Remove tags from struct field in current line
go.tags.remove.prompt Remove tags from struct fields (prompt)
go.test.generate.exported Generate unit tests for exported functions in file
go.test.generate.file Generate unit tests for file
go.test.generate.function Generate unit tests for current function
go.test.toggle Toggle test file
go.version Print extension version

Examples

  • Add or Remove specific tags

    CocCommand go.tags.add yaml
    CocCommand go.tags.add yaml json xml
    CocCommand go.tags.remove xml
    
  • Add missing imports on save

    autocmd BufWritePre *.go :silent call CocAction('runCommand', 'editor.action.organizeImport')
  • Map Keys to command

    autocmd FileType go nmap gtj :CocCommand go.tags.add json<cr>
    autocmd FileType go nmap gty :CocCommand go.tags.add yaml<cr>
    autocmd FileType go nmap gtx :CocCommand go.tags.clear<cr>

Snippets

Snippets are imported from golang/vscode-go and require coc-snippets to be installed.

Configuration options

Key Description Default
go.checkForUpdates Check for gopls updates on start. install
go.disable Disable gopls features {}
‣ completion Disable completion feature (Change requires :CocRestart) false
‣ diagnostics Disable handle diagnostics (Change requires :CocRestart) false
‣ features Disabled features (Change requires :CocRestart) []
‣ snippetCompletion Disable snippet completion (Change requires :CocRestart) false
‣ workspaceFolders Disable workspaceFolders feature (Change requires :CocRestart) false
go.enable Enable Go extension true
go.goplsArgs Arguments passed to gopls (Change requires :CocRestart)
go.goplsEnv ENV passed to gopls (Change requires :CocRestart)
go.goplsOptions See gopls documentation
‣ allowImplicitNetworkAccess This setting is experimental and may be deleted. allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module downloads rather than requiring user action. false
‣ allowModfileModifications This setting is experimental and may be deleted. allowModfileModifications disables -mod=readonly, allowing imports from out-of-scope modules. false
‣ analyses analyses specify analyses that the user would like to enable or disable.
‣ analysisProgressReporting analysisProgressReporting controls whether gopls sends progress notifications when construction of its index of analysis facts is taking a long time. true
‣ annotations This setting is experimental and may be deleted. annotations specifies the various kinds of optimization diagnostics that should be reported by the gc_details command.
‣ buildFlags buildFlags is the set of flags passed on to the build system when invoked.
‣ codelenses codelenses overrides the enabled/disabled state of code lenses.
‣ completeFunctionCalls completeFunctionCalls enables function call completion. true
‣ completionBudget This setting is for debugging purposes only. completionBudget is the soft latency goal for completion requests. 100ms
‣ diagnosticsDelay This is an advanced setting and should not be configured by most gopls users. diagnosticsDelay controls the amount of time that gopls waits after the most recent file modification before computing deep diagnostics. 1s
‣ diagnosticsTrigger This setting is experimental and may be deleted. diagnosticsTrigger controls when to run diagnostics. Edit
‣ directoryFilters directoryFilters can be used to exclude unwanted directories from the workspace.
‣ env env adds environment variables to external commands run by gopls, most notably go list.
‣ expandWorkspaceToModule This setting is experimental and may be deleted. expandWorkspaceToModule determines which packages are considered "workspace packages" when the workspace is using modules. true
‣ experimentalPostfixCompletions This setting is experimental and may be deleted. experimentalPostfixCompletions enables artificial method snippets such as "someSlice.sort!". true
‣ gofumpt gofumpt indicates if we should run gofumpt formatting. false
‣ hints This setting is experimental and may be deleted. hints specify inlay hints that users want to see.
‣ hoverKind hoverKind controls the information that appears in the hover text. FullDocumentation
‣ importShortcut importShortcut specifies whether import statements should link to documentation or go to definitions. Both
‣ linkTarget linkTarget controls where documentation links go. pkg.go.dev
‣ linksInHover linksInHover toggles the presence of links to documentation in hover. true
‣ local local is the equivalent of the goimports -local flag, which puts imports beginning with this string after third-party packages.
‣ matcher This is an advanced setting and should not be configured by most gopls users. matcher sets the algorithm that is used when calculating completion candidates. Fuzzy
‣ memoryMode This setting is experimental and may be deleted. obsolete, no effect
‣ noSemanticNumber This setting is experimental and may be deleted. noSemanticNumber turns off the sending of the semantic token 'number' false
‣ noSemanticString This setting is experimental and may be deleted. noSemanticString turns off the sending of the semantic token 'string' false
‣ semanticTokens This setting is experimental and may be deleted. semanticTokens controls whether the LSP server will send semantic tokens to the client. false
‣ standaloneTags standaloneTags specifies a set of build constraints that identify individual Go source files that make up the entire main package of an executable.
‣ staticcheck This setting is experimental and may be deleted. staticcheck enables additional analyses from staticcheck.io. false
‣ symbolMatcher This is an advanced setting and should not be configured by most gopls users. symbolMatcher sets the algorithm that is used when finding workspace symbols. FastFuzzy
‣ symbolScope symbolScope controls which packages are searched for workspace/symbol requests. all
‣ symbolStyle This is an advanced setting and should not be configured by most gopls users. symbolStyle controls how symbols are qualified in symbol responses. Dynamic
‣ templateExtensions templateExtensions gives the extensions of file names that are treateed as template files.
‣ usePlaceholders placeholders enables placeholders for function parameters or struct fields in completion responses. false
‣ verboseOutput This setting is for debugging purposes only. verboseOutput enables additional debug logging. false
‣ vulncheck This setting is experimental and may be deleted. vulncheck enables vulnerability scanning. Off
go.goplsPath Path to gopls bin (Change requires :CocRestart)
go.goplsUseDaemon Run gopls as daemon true
go.tags
‣ options Comma separated tag=options pairs to be used by go.tags.add command json=omitempty
‣ skipUnexported If true, skip unexported fields false
‣ tags Comma separated tags to be used by go.tags.add command json
‣ transform Transformation rule used by go.tags.add command to add tags snakecase
go.tests
‣ generateFlags Additional command line flags to pass to gotests for generating tests. []
go.trace.server Trace level of gopls off

Trigger completion in coc-settings.json to get complete list.

Example Configuration

{
  "go.goplsOptions": {
    "completeUnimported": true
  }
}

Development

  1. Run npm run build or npm run build:watch
  2. Link extension: npm run link / npm run unlink

Tools

FAQ

How does coc-go compare to vim-go?

With coc-go I do not aim to recreate the features of vim-go. For now, the main goal is to provide a convenient way to install gopls and use it with coc.nvim.

If you need more than the features provided by gopls, you are probably better of with vim-go or govim.

How to use coc-go with wasm?

Add this to you (local) coc-settings.json (run :CocLocalConfig).

{
  "go.goplsEnv": {
    "GOOS": "js",
    "GOARCH": "wasm",
  }
}

Running gopls as a daemon

coc-go runs gopls as shared daemon by passing -remote=auto to gopls. To disable this behavior set go.goplsUseDaemon to false.

See Running gopls as a daemon for more information.

License

MIT © Josa Gesell.

More Repositories

1

coc-sh

SH language server extension using bash-language-server for coc.nvim.
Shell
170
star
2

coc-lua

Lua language server extension using lua-lsp for coc.nvim.
TypeScript
110
star
3

coc-docker

Docker language server extension using dockerfile-language-server-nodejs for coc.nvim.
Shell
62
star
4

vim-lightline-coc

Vim Script
52
star
5

atom-svg-preview

Live SVG preview for Atom editor
JavaScript
51
star
6

atom-blame

Show git blame as a gutter in Atom editor
JavaScript
22
star
7

atom-pandoc-convert

JavaScript
19
star
8

nvim-lightline-lsp

Vim Script
17
star
9

vim-clippy

Vim Script
14
star
10

atom-linter-less

Linter plug in for Less in the Atom text editor
JavaScript
11
star
11

atom-caniuse

JavaScript
11
star
12

vscode-ember-related-files

TypeScript
11
star
13

vscode-markdown-table-formatter

TypeScript
10
star
14

nvim-lsp-codelenses

Lua
7
star
15

nvim-actions

Lua
7
star
16

atom-ide-ember

JavaScript
7
star
17

atom-linter-handlebars

AtomLinter interface to handlebars
JavaScript
6
star
18

jenkins-theme-clean

jenkins-theme-clean
CSS
6
star
19

coc-lua-binaries

5
star
20

nvim-telescope-minimal-layout

Lua
5
star
21

atom-linter-node-markdownlint

JavaScript
4
star
22

atom-smyck

Smyck color scheme for atom
CSS
4
star
23

atom-ide-docker

JavaScript
4
star
24

ember-find-related-files

JavaScript
3
star
25

nvim-telescope-workspaces

Lua
3
star
26

nvim-file-tree

Lua
2
star
27

atom-linter-json-lint

JavaScript
2
star
28

nvim-gx

Lua
2
star
29

atom-http-status-codes

JavaScript
2
star
30

go-prompt

Go
2
star
31

nvim-telescope-select

Lua
2
star
32

nvim-quickfix

Lua
1
star
33

nvim-neighbors

Lua
1
star
34

nvim-lsp-autoformat

Lua
1
star
35

hastdueier-twitter-bot

JavaScript
1
star
36

git-bus-factor

Go
1
star
37

vscode-xcode-project

TypeScript
1
star
38

jsonschema-bitbucket-pipelines

1
star
39

vim-go-syntax

Vim Script
1
star
40

go-gitutils

Go
1
star
41

nvim-filetree

Go
1
star
42

go-devicons

Go
1
star
43

vim-monkey-c

Vim Script
1
star
44

atom-readme

JavaScript
1
star
45

lua-vim-textobj-user

Lua
1
star
46

homebrew-moneymoney-extensions

Ruby
1
star
47

coc-dev-tools

JavaScript
1
star
48

alfred-slack-status

JavaScript
1
star
49

nodeschool

JavaScript
1
star
50

alfred-google-maps

Go
1
star
51

zsh-upgrade-all

Shell
1
star
52

go-spinner

Go
1
star
53

go-zip

Go
1
star
54

vim-lightline-sensible

Vim Script
1
star
55

alfred-text-transformation

JavaScript
1
star
56

git-repo

Go
1
star
57

ZyFileheader

Help add fileheader when file is created.
Python
1
star
58

atom-linter-package-json-validator

JavaScript
1
star
59

atom-package-settings

JavaScript
1
star
60

atom-ember-module-import-snippets

JavaScript
1
star
61

go-applescript

Go
1
star