Skip to content

Commit

Permalink
internal/lsp/source: use the setString method when setting options
Browse files Browse the repository at this point in the history
A couple string options were not using the asString helper. Update them,
and also add a setString helper to be consistent with setBool.

Change-Id: I38caef5b1595a3535b759e5bf1c8d350a8bf061e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/232741
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
  • Loading branch information
findleyr committed May 8, 2020
1 parent cb8d9cd commit 88bf40a
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions internal/lsp/source/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,7 @@ func (o *Options) set(name string, value interface{}) OptionResult {
}

case "linkTarget":
linkTarget, ok := value.(string)
if !ok {
result.errorf("invalid type %T for string option %q", value, name)
break
}
o.LinkTarget = linkTarget
result.setString(&o.LinkTarget)

case "analyses":
result.setBoolMap(&o.UserEnabledAnalyses)
Expand All @@ -446,12 +441,7 @@ func (o *Options) set(name string, value interface{}) OptionResult {
result.setBool(&o.StaticCheck)

case "local":
localPrefix, ok := value.(string)
if !ok {
result.errorf("invalid type %T for string option %q", value, name)
break
}
o.LocalPrefix = localPrefix
result.setString(&o.LocalPrefix)

case "verboseOutput":
result.setBool(&o.VerboseOutput)
Expand Down Expand Up @@ -523,6 +513,12 @@ func (r *OptionResult) asBool() (bool, bool) {
return b, true
}

func (r *OptionResult) setBool(b *bool) {
if v, ok := r.asBool(); ok {
*b = v
}
}

func (r *OptionResult) setBoolMap(bm *map[string]bool) {
all, ok := r.Value.(map[string]interface{})
if !ok {
Expand Down Expand Up @@ -550,9 +546,9 @@ func (r *OptionResult) asString() (string, bool) {
return b, true
}

func (r *OptionResult) setBool(b *bool) {
if v, ok := r.asBool(); ok {
*b = v
func (r *OptionResult) setString(s *string) {
if v, ok := r.asString(); ok {
*s = v
}
}

Expand Down

0 comments on commit 88bf40a

Please sign in to comment.