From 60a1430268fb2fe39e9b1e9beab2fd7a778bd1c6 Mon Sep 17 00:00:00 2001 From: Pontus Leitzler Date: Mon, 27 Jan 2020 22:13:17 +0100 Subject: [PATCH] cmd/govim: Ensure text prop highlights aren't placed when disabled (#730) 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 --- cmd/govim/highlight.go | 2 +- cmd/govim/vimstate.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/govim/highlight.go b/cmd/govim/highlight.go index d13c70e3d..617441525 100644 --- a/cmd/govim/highlight.go +++ b/cmd/govim/highlight.go @@ -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() diff --git a/cmd/govim/vimstate.go b/cmd/govim/vimstate.go index af4c99754..1d42e8993 100644 --- a/cmd/govim/vimstate.go +++ b/cmd/govim/vimstate.go @@ -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)