gopls is not formatting or importing

See original GitHub issue

Describe the bug I am working on a file in a go path.

To Reproduce

I made a go file:

package main 

import (

)

func main() {
	fmt.Println("hello")
}

I save this file and I get an error from gopls:

compiler error undeclared name:fmt

Expected behavior I thought that my go file would be autoformatted.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Sublime Text version: 3.2.2 Build 3211
  • LSP version: v0.14.2

Additional context My LSP settings:

{
    "lsp_format_on_save": true,
    "lsp_code_actions_on_save": {
        "source.fixAll": true,
        "source.organizeImports": true
    },
    "show_symbol_action_links": true,
    "only_show_lsp_completions": true,
    "clients": {
        "gopls": {
            "enabled": true,
            "settings": {
                "gopls.usePlaceholders": true,
                "gopls.analyses": {
                  "fillreturns": true,
                  "nonewvars": true,
                  "undeclaredname": true,
                  "unusedparams": true
                },
                "gopls.completeUnimported": true,
                "gopls.staticcheck": true
            }
        }
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rchlcommented, Nov 24, 2020

I’ve tried in ST3 and I can see that formatting is triggering when the code has no errors otherwise.

The “organize imports” feature is apparently not part of the formatting functionality which means that in ST3 you have to fix issues manually through code actions.

1reaction
schollzcommented, Nov 24, 2020

@rchl Okay I’ve upgraded to ST4 and no longer have the issue! It works beautifully too.

I have an old computer that I can try your fix on ST3 for future users

Read more comments on GitHub >

github_iconTop Results From Across the Web

Features
This feature is not available if you are using Go modules without gopls , the Go language server. Go to symbol. Search for...
Read more >
gopls not working : r/neovim - Reddit
I'm finding my configuration isn't working as expected. UPDATE: I discovered I had overlapping autocmds and this caused problems because an ...
Read more >
[vscode-go] docs/features.md: discuss default formatting ...
We need to update the diagnostics section to discuss gopls's diagnostics feature. ... Format code and organize imports, either manually or on save....
Read more >
Go | Nova Extensions - Panic Inc.
WARNING: (aye, again) If you click on Format/Organise Imports when saving file to get gopls to automatically reformat your code when saving, be...
Read more >
The option formatting.local in vscode-go its working?
"formatting.local" is a gopls setting. https://github.com/golang/vscode-go/blob/master/docs/settings.md#settings-for-gopls So, please add it ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found