Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/govim: extract text property removal to own func #737

Merged
merged 1 commit into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 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)
leitzler marked this conversation as resolved.
Show resolved Hide resolved

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,26 @@ func (v *vimstate) redefineHighlights(diags []types.Diagnostic, force bool) erro
v.BatchEnd()
return nil
}

func (v *vimstate) removeTextProps(id types.TextPropID) {
var didStart bool
if didStart = v.BatchStartIfNeeded(); didStart {
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})
}

if didStart {
// 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
)
21 changes: 9 additions & 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 Expand Up @@ -203,6 +192,14 @@ func (v *vimstate) BatchStart() {
v.currBatch = &batch{}
}

func (v *vimstate) BatchStartIfNeeded() bool {
if v.currBatch != nil {
return false
}
v.currBatch = &batch{}
return true
}

type batchResult func() json.RawMessage

type AssertExpr string
Expand Down