Skip to content

Commit

Permalink
cmd/govim: Ensure text prop highlights aren't placed when disabled (#730
Browse files Browse the repository at this point in the history
)

The config HighlightDiagnostics can be used to disable in-code
highlights. PR #700 accidently broke that feature so that it was
possible to get highlights even when disabled.

This PR ensures that text prop highlights aren't placed when they
are disabled by the config.

Fixes #724
  • Loading branch information
leitzler committed Jan 27, 2020
1 parent 013f992 commit 60a1430
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/govim/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (v *vimstate) textpropDefine() error {
}

func (v *vimstate) redefineHighlights(diags []types.Diagnostic, force bool) error {
if !force && (v.config.HighlightDiagnostics == nil || !*v.config.HighlightDiagnostics) {
if v.config.HighlightDiagnostics == nil || !*v.config.HighlightDiagnostics {
return nil
}
v.diagnosticsChangedLock.Lock()
Expand Down
13 changes: 12 additions & 1 deletion cmd/govim/vimstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,18 @@ func (v *vimstate) setConfig(args ...json.RawMessage) (interface{}, error) {
if !vimconfig.EqualBool(v.config.HighlightDiagnostics, preConfig.HighlightDiagnostics) {
if v.config.HighlightDiagnostics == nil || !*v.config.HighlightDiagnostics {
// HighlightDiagnostics is now not on - remove existing text properties
v.redefineHighlights([]types.Diagnostic{}, true)
v.BatchStart()
for bufnr, buf := range v.buffers {
if !buf.Loaded {
continue // vim removes properties when a buffer is unloaded
}
v.BatchChannelCall("prop_remove", struct {
ID int `json:"id"`
BufNr int `json:"bufnr"`
All int `json:"all"`
}{0, bufnr, 1})
}
v.BatchEnd()
} else {
if err := v.redefineHighlights(v.diagnostics(), true); err != nil {
return nil, fmt.Errorf("failed to update diagnostic highlights: %v", err)
Expand Down

0 comments on commit 60a1430

Please sign in to comment.