Giter Site home page Giter Site logo

coc-go's Introduction

coc-go

Go language server extension using gopls for coc.nvim.

Install

In your vim/neovim, run command:

:CocInstall coc-go

Features

See gopls

Commands

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

Key Description
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.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.toggle Toggle test file
go.version Print extension version
go.impl.cursor Generate interface stubs

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 :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 microsoft/vscode-go and require coc-snippets to be installed.

Configuration options

Key Description Default
go.checkForUpdates EXPERIMENTAL Check for gopls updates on start.
go.enable Enable Go extension
go.goplsArgs Arguments passed to gopls (Change requires :CocRestart)
go.goplsOptions See gopls documentation
‣ analyses EXPERIMENTAL Analyses specify analyses that the user would like to enable or disable.
‣ buildFlags This is the set of flags passed on to the build system when invoked. It is applied to queries like go list, which is used when discovering files. The most common use is to set -tags.
‣ codelens EXPERIMENTAL
‣ completeUnimported EXPERIMENTAL If true, the completion engine is allowed to make suggestions for packages that you do not currently import. false
‣ completionDocumentation EXPERIMENTAL If false, indicates that the user does not want documentation with completion results. true
‣ deepCompletion EXPERIMENTAL If true, this turns on the ability to return completions from deep inside relevant entities, rather than just the locally accessible ones. true
‣ env This can be used to add environment variables. These will not affect gopls itself, but will be used for any external commands it invokes.
‣ fuzzyMatching EXPERIMENTAL If true, this enables server side fuzzy matching of completion candidates. true
‣ hoverKind This controls the information that appears in the hover text. SynopsisDocumentation
‣ linkTarget This controls where points documentation for given package in textDocument/documentLink. pkg.go.dev
‣ local This is the equivalent of the goimports -local flag, which puts imports beginning with this string after 3rd-party packages.
‣ matcher EXPERIMENTAL caseInsensitive
‣ staticcheck EXPERIMENTAL If true, it enables the use of the staticcheck.io analyzers.
‣ symbolMatcher EXPERIMENTAL caseInsensitive
‣ usePlaceholders If true, then completion responses may contain placeholders for function parameters or struct fields. false
go.goplsPath Path to gopls bin (Change requires :CocRestart)
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

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

Example Configuration

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

Development

  1. Run yarn build or yarn build:watch
  2. Run yarn run link:add to link extension

TODO

  • Check for tool updates and prompt the the user

  • Add godoctor refactor commands

    {
      "command": "go.godoctor.extract",
      "title": "Extract to function"
    },
    {
      "command": "go.godoctor.variable",
      "title": "Extract to variable"
    }
    
  • Add fillstruct command

    {
      "command": "go.fill.struct",
      "title": "Fill struct"
    }
    

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.

License

MIT © Josa Gesell

coc-go's People

Contributors

adamatom avatar charlesvdv avatar dependabot-support avatar fannheyward avatar gabrieldavid98 avatar jbactad avatar josa42 avatar mathieupost avatar oncomouse avatar thinceller avatar voldikss 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.