From a0b285f7dbbf1f77043583d44297b9dd9f8d7ba6 Mon Sep 17 00:00:00 2001 From: Yuki Ito Date: Tue, 5 Feb 2019 15:59:58 +0900 Subject: [PATCH] adds build tags support --- langserver/config.go | 5 +++++ langserver/fs.go | 6 +++--- langserver/handler.go | 4 ++-- langserver/internal/cache/view.go | 12 +++++++----- main.go | 3 +++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/langserver/config.go b/langserver/config.go index 20bd572..a6fe1f1 100644 --- a/langserver/config.go +++ b/langserver/config.go @@ -51,6 +51,11 @@ type Config struct { // // Defaults to false EnhanceSignatureHelp bool + + // BuildTags controls build tag constraints and will be passed to build flags. + // + // Defaults to empty + BuildTags []string } // Apply sets the corresponding field in c for each non-nil field in o. diff --git a/langserver/fs.go b/langserver/fs.go index acc4c83..a28c776 100644 --- a/langserver/fs.go +++ b/langserver/fs.go @@ -8,7 +8,7 @@ import ( "github.com/saibing/bingo/langserver/internal/cache" "github.com/saibing/bingo/langserver/internal/source" - "github.com/sourcegraph/go-lsp" + lsp "github.com/sourcegraph/go-lsp" "github.com/sourcegraph/jsonrpc2" ) @@ -72,8 +72,8 @@ type overlay struct { diagnosticsStyle DiagnosticsStyleEnum } -func newOverlay(conn *jsonrpc2.Conn, diagnosticsStyle DiagnosticsStyleEnum) *overlay { - return &overlay{conn: conn, view: cache.NewView(), diagnosticsStyle: diagnosticsStyle} +func newOverlay(conn *jsonrpc2.Conn, diagnosticsStyle DiagnosticsStyleEnum, buildTags []string) *overlay { + return &overlay{conn: conn, view: cache.NewView(buildTags), diagnosticsStyle: diagnosticsStyle} } func (h *overlay) didOpen(ctx context.Context, params *lsp.DidOpenTextDocumentParams) { diff --git a/langserver/handler.go b/langserver/handler.go index 2857ed9..3041d9a 100644 --- a/langserver/handler.go +++ b/langserver/handler.go @@ -9,7 +9,7 @@ import ( "sync" "github.com/saibing/bingo/langserver/internal/cache" - "github.com/sourcegraph/go-lsp" + lsp "github.com/sourcegraph/go-lsp" "github.com/sourcegraph/go-lsp/lspext" "github.com/sourcegraph/jsonrpc2" @@ -83,7 +83,7 @@ func (h *LangHandler) doInit(ctx context.Context, conn *jsonrpc2.Conn, init *Ini h.init = init h.cancel = &cancel{} - h.overlay = newOverlay(conn, DiagnosticsStyleEnum(h.DefaultConfig.DiagnosticsStyle)) + h.overlay = newOverlay(conn, DiagnosticsStyleEnum(h.DefaultConfig.DiagnosticsStyle), h.config.BuildTags) h.project = cache.NewProject(conn, h.FilePath(init.Root()), h.overlay.view) if err := h.project.Init(ctx, h.DefaultConfig.GolistDuration, h.DefaultConfig.GlobalCacheStyle); err != nil { return err diff --git a/langserver/internal/cache/view.go b/langserver/internal/cache/view.go index 8de8226..e992390 100644 --- a/langserver/internal/cache/view.go +++ b/langserver/internal/cache/view.go @@ -10,6 +10,7 @@ import ( "go/parser" "go/token" "path/filepath" + "strings" "sync" "github.com/saibing/bingo/langserver/internal/source" @@ -29,13 +30,14 @@ type View struct { } // NewView create a new view -func NewView() *View { +func NewView(buildTags []string) *View { return &View{ Config: &packages.Config{ - Mode: packages.LoadAllSyntax, - Fset: token.NewFileSet(), - Tests: true, - Overlay: make(map[string][]byte), + Mode: packages.LoadAllSyntax, + Fset: token.NewFileSet(), + Tests: true, + Overlay: make(map[string][]byte), + BuildFlags: []string{fmt.Sprintf("-tags='%s'", strings.Join(buildTags, " "))}, }, files: make(map[source.URI]*File), tempOverlay: make(map[string][]byte), diff --git a/main.go b/main.go index 7293afc..43f3dba 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "runtime/debug" + "strings" "time" "github.com/saibing/bingo/langserver" @@ -35,6 +36,7 @@ var ( formatStyle = flag.String("format-style", "goimports", "which format style is used to format documents. Supported: gofmt and goimports. Can be overridden by InitializationOptions.") golistDuration = flag.Int("golist-duration", 0, "the interval of refresh the go list cache, unit: second, 0 means that does not use go list cache. Can be overridden by InitializationOptions.") enhanceSignatureHelp = flag.Bool("enhance-signature-help", false, "enhance signature help with return result. Can be overridden by InitializationOptions.") + buildTags = flag.String("build-tags", "", "build tags, separated by spaces.") ) // version is the version field we report back. If you are releasing a new version: @@ -66,6 +68,7 @@ func main() { cfg.FormatStyle = *formatStyle cfg.GolistDuration = *golistDuration cfg.EnhanceSignatureHelp = *enhanceSignatureHelp + cfg.BuildTags = strings.Split(*buildTags, " ") if *maxparallelism > 0 { cfg.MaxParallelism = *maxparallelism