-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
potential issue with goimports #914
Comments
How did you configure it? GoSublime/margo doesn't do much except call the |
I configured it to use goimports, but as you're saying that doesn't do what the vscode plugin does. This is more of a feature request I'm guessing so maybe it should not be an issue. |
I think I understand what you're saying, but it sounds like what Alternatively, if you just want them to be added while typing, you can use AddUnimportedPackages but it doesn't have a very good UX. |
Okay I see, so I think maybe I didn't configure GoSublime properly, given this go file package main
import "fmt"
func main() {
spew.Dump("test")
} running diff -u main.go.orig main.go
--- main.go.orig 2019-02-16 17:16:57.000000000 +0000
+++ main.go 2019-02-16 17:16:57.000000000 +0000
@@ -1,6 +1,6 @@
package main
-import "fmt"
+import "github.com/davecgh/go-spew/spew"
func main() {
spew.Dump("test") so that's exactly what I want, but if I save that file in sublime (latest dev build) with this config package margo
import (
"time"
"margo.sh/golang"
"margo.sh/mg"
)
// Margo is the entry-point to margo
func Margo(m mg.Args) {
// See the documentation for `mg.Reducer`
// comments beginning with `gs:` denote features that replace old GoSublime settings
// add our reducers (margo plugins) to the store
// they are run in the specified order
// and should ideally not block for more than a couple milliseconds
m.Use(
// MOTD keeps you updated about new versions and important announcements
//
// It adds a new command `motd.sync` available via the UserCmd palette as `Sync MOTD`
//
// Interval can be set in order to enable automatic update fetching.
//
// When new updates are found, it displays the message in the status bar
// e.g. `★ margo.sh/cl/18.09.14 ★` a url where you see the upcoming changes before updating
//
// It sends the following data to the url https://api.margo.sh/motd.json:
// * current editor plugin name e.g. `?client=gosublime`
// this tells us which editor plugin's changelog to check
// * current editor plugin version e.g. `?tag=r18.09.14-1`
// this allows us to determine if there any updates
// * whether or not this is the first request of the day e.g. `?firstHit=1`
// this allows us to get an estimated count of active users without storing
// any personally identifiable data
//
// No other data is sent. For more info contact privacy at kuroku.io
//
&mg.MOTD{
// Interval, if set, specifies how often to automatically fetch messages from Endpoint
// Interval: 3600e9, // automatically fetch updates every hour
},
mg.NewReducer(func(mx *mg.Ctx) *mg.State {
// By default, events (e.g. ViewSaved) are triggered in all files.
// Replace `mg.AllLangs` with `mg.Go` to restrict events to Go(-lang) files.
// Please note, however, that this mode is not tested
// and saving a non-go file will not trigger linters, etc. for that go pkg
return mx.SetConfig(mx.Config.EnabledForLangs(
mg.AllLangs,
))
}),
// Add `go` command integration
// this adds a new commands:
// gs: these commands are all callable through 9o:
// * go: Wrapper around the go command, adding linter support
// * go.play: Automatically build and run go commands or run go test for packages
// with support for linting and unsaved files
// * go.replay: Wrapper around go.play limited to a single instance
// by default this command is bound to ctrl+.,ctrl+r or cmd+.,cmd+r
//
// UserCmds are also added for `Go Play` and `Go RePlay`
&golang.GoCmd{},
// add the day and time to the status bar
// &DayTimeStatus{},
// both GoFmt and GoImports will automatically disable the GoSublime version
// you will need to install the `goimports` tool manually
// https://godoc.org/golang.org/x/tools/cmd/goimports
//
// gs: this replaces settings `fmt_enabled`, `fmt_tab_indent`, `fmt_tab_width`, `fmt_cmd`
//
// golang.GoFmt,
// or
golang.GoImports,
// Configure general auto-completion behaviour
&golang.MarGocodeCtl{
// whether or not to include Test*, Benchmark* and Example* functions in the auto-completion list
// gs: this replaces the `autocomplete_tests` setting
ProposeTests: false,
// Don't try to automatically import packages when auto-compeltion fails
// e.g. when `json.` is typed, if auto-complete fails
// "encoding/json" is imported and auto-complete attempted on that package instead
// See AddUnimportedPackages
NoUnimportedPackages: false,
// If a package was imported internally for use in auto-completion,
// insert it in the source code
// See NoUnimportedPackages
// e.g. after `json.` is typed, `import "encoding/json"` added to the code
AddUnimportedPackages: false,
// Don't preload packages to speed up auto-completion, etc.
NoPreloading: false,
// Don't suggest builtin types and functions
// gs: this replaces the `autocomplete_builtins` setting
NoBuiltins: false,
},
// Enable auto-completion
// gs: this replaces the `gscomplete_enabled` setting
&golang.Gocode{
// show the function parameters. this can take up a lot of space
ShowFuncParams: true,
},
// show func arguments/calltips in the status bar
// gs: this replaces the `calltips` setting
&golang.GocodeCalltips{},
// use guru for goto-definition
// new commands `goto.definition` and `guru.definition` are defined
// gs: by default `goto.definition` is bound to ctrl+.,ctrl+g or cmd+.,cmd+g
&golang.Guru{},
// add some default context aware-ish snippets
// gs: this replaces the `autocomplete_snippets` and `default_snippets` settings
golang.Snippets,
// add our own snippets
// gs: this replaces the `snippets` setting
MySnippets,
// check the file for syntax errors
// gs: this and other linters e.g. below,
// replaces the settings `gslint_enabled`, `lint_filter`, `comp_lint_enabled`,
// `comp_lint_commands`, `gslint_timeout`, `lint_enabled`, `linters`
&golang.SyntaxCheck{},
// Add user commands for running tests and benchmarks
// gs: this adds support for the tests command palette `ctrl+.`,`ctrl+t` or `cmd+.`,`cmd+t`
&golang.TestCmds{
// additional args to add to the command when running tests and examples
TestArgs: []string{},
// additional args to add to the command when running benchmarks
BenchArgs: []string{"-benchmem"},
},
// run `go install -i` on save
// golang.GoInstall("-i"),
// or
// golang.GoInstallDiscardBinaries("-i"),
//
// GoInstallDiscardBinaries will additionally set $GOBIN
// to a temp directory so binaries are not installed into your $GOPATH/bin
//
// the -i flag is used to install imported packages as well
// it's only supported in go1.10 or newer
// run `go vet` on save. go vet is ran automatically as part of `go test` in go1.10
golang.GoVet(),
// run `go test -race` on save
// golang.GoTest("-race"),
// run `golint` on save
&golang.Linter{Name: "golint", Label: "Go/Lint"},
// run gometalinter on save
&golang.Linter{Name: "gometalinter", Args: []string{
"--disable=gas",
//"--fast",
}},
)
}
// DayTimeStatus adds the current day and time to the status bar
type DayTimeStatus struct {
mg.ReducerType
}
func (dts DayTimeStatus) RMount(mx *mg.Ctx) {
// kick off the ticker when we start
dispatch := mx.Store.Dispatch
go func() {
ticker := time.NewTicker(1 * time.Second)
for range ticker.C {
dispatch(mg.Render)
}
}()
}
func (dts DayTimeStatus) Reduce(mx *mg.Ctx) *mg.State {
// we always want to render the time
// otherwise it will sometimes disappear from the status bar
now := time.Now()
format := "Mon, 15:04"
if now.Second()%2 == 0 {
format = "Mon, 15 04"
}
return mx.AddStatus(now.Format(format))
}
// MySnippets is a slice of functions returning our own snippets
var MySnippets = golang.SnippetFuncs(
func(cx *golang.CompletionCtx) []mg.Completion {
// if we're not in a block (i.e. function), do nothing
if !cx.Scope.Is(golang.BlockScope) {
return nil
}
return []mg.Completion{
{
Query: "if err",
Title: "err != nil { return }",
Src: "if ${1:err} != nil {\n\treturn $0\n}",
},
}
},
) the file stays as it is, I get an underline GoVet error for the spew line and that's it Am I missing something? Maybe I misconfigured GoSublime? |
The config looks fine. Does it fmt at all? Maybe it can't find Also make sure margo restarted after saving the |
First of all, thanks for helping out. So, if I make Here's the output from the console just from opening the test file, adding a few spaces as shown above and hitting save.
I usually run Sublime by doing Any idea? Thanks 👍 |
You always have to check for the existence of command by running them through I thought I could reproduce this with a file that's not in Do you get auto-completion for You can debug
It creates a new command |
Hey again, sorry I've been really busy with work and whatnot. I think that I am missing some crucial piece of information regarding Go and their new Go Modules, I really don't understand how the whole modules thing works and I'm pretty sure this issue is related to me not setting up my workspace outside of GOPATH properly. I will try to learn modules properly in the coming weeks as time allows and try to see if this keeps happening after I have learned my stuff regarding modules. In the mean time, please feel free to close this issue if you can't replicate it as I'm pretty sure it's just something not properly configured on my side... Thanks for your time 👍 edit: I tried to add that reducer and after I did, the behaviour changed, now I get proper imports regardless of whether I'm in GOPATH or not, so that's pretty cool? This is the output of the console
I'm not too sure why it seems to work now... but it does so I'll leave it like that. When I remove the reducer, it stops working again. |
Hey all,
Not sure if this is an issue with GoSublime itself but thought I'd ask in case it is possible.
My main editor has always been Sublime as it seems like it's the only editor worth using nowadays, apart from Vim. Since the features for Go were really lacking and Go is so picky with formatting, unused variables and whatnot I decided to give vscode a go. It works fine but it's ridiculously slow, I guess due to it being Electron based.
I've been trying GoSublime and it's pretty good, the only feature I'm missing really would be the automatic imports. I've enabled goimports in my margo.go file but it only works for stdlib imports, such as fmt or errors, etc. For example, I use
spew
(https://github.com/davecgh/go-spew) a lot to quickly debug stuff. Vscode would automatically importhttps://github.com/davecgh/go-spew
, but it seems like GoSublime with goimports does not.Is this behaviour expected? Configurable? It really is the only thing keeping me from switching back to Sublime, it's pretty annoying having to import the package every time I need to debug something quickly.
Thanks in advance.
The text was updated successfully, but these errors were encountered: