Skip to content

Commit

Permalink
cmd/govim: extract text property removal to own func
Browse files Browse the repository at this point in the history
This change extracts text property removal to it's own func.

It acts as gardening for implementing references highlights where we'll
start using another text property ID, and therefore it is added as an
internal type.
  • Loading branch information
leitzler committed Jan 28, 2020
1 parent 01c8f58 commit ccfeb82
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
32 changes: 21 additions & 11 deletions cmd/govim/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,10 @@ func (v *vimstate) redefineHighlights(diags []types.Diagnostic, force bool) erro
return nil
}

v.removeTextProps(types.DiagnosticTextPropID)

v.BatchStart()
defer v.BatchCancelIfNotEnded()
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})
}

for _, d := range diags {
// Do not add textprops to unknown buffers
if d.Buf < 0 {
Expand Down Expand Up @@ -106,3 +97,22 @@ func (v *vimstate) redefineHighlights(diags []types.Diagnostic, force bool) erro
v.BatchEnd()
return nil
}

func (v *vimstate) removeTextProps(id types.TextPropID) {
v.BatchStart()
defer v.BatchCancelIfNotEnded()

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"`
}{int(id), bufnr, 1})
}

// prop_remove returns number of removed properties per call
v.BatchEnd()
}
7 changes: 7 additions & 0 deletions cmd/govim/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,10 @@ var SeverityHoverHighlight = map[Severity]config.Highlight{
SeverityInfo: config.HighlightHoverInfo,
SeverityHint: config.HighlightHoverHint,
}

// TextPropID is the govim internal mapping of ID used when adding/removing text properties
type TextPropID int

const (
DiagnosticTextPropID = 0
)
13 changes: 1 addition & 12 deletions cmd/govim/vimstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,7 @@ 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.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()
v.removeTextProps(types.DiagnosticTextPropID)
} 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 ccfeb82

Please sign in to comment.