mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
69 lines
1.0 KiB
Go
69 lines
1.0 KiB
Go
package ast
|
|
|
|
import "slices"
|
|
|
|
func (c *GitConfig) Clear() {
|
|
c.Sections = []*GitSection{}
|
|
c.CommentLines = map[uint32]struct{}{}
|
|
}
|
|
|
|
func (c *GitConfig) FindSection(line uint32) *GitSection {
|
|
index, found := slices.BinarySearchFunc(
|
|
c.Sections,
|
|
line,
|
|
func(current *GitSection, target uint32) int {
|
|
if target > current.End.Line {
|
|
return -1
|
|
}
|
|
|
|
if target < current.Start.Line {
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
},
|
|
)
|
|
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
return c.Sections[index]
|
|
}
|
|
|
|
func (c *GitConfig) FindOption(line uint32) (*GitSection, *GitEntry) {
|
|
section := c.FindSection(line)
|
|
|
|
if section == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
entry := section.FindOption(line)
|
|
|
|
return section, entry
|
|
}
|
|
|
|
func (s *GitSection) FindOption(line uint32) *GitEntry {
|
|
index, found := slices.BinarySearchFunc(
|
|
s.Entries,
|
|
line,
|
|
func(current *GitEntry, target uint32) int {
|
|
if target > current.End.Line {
|
|
return -1
|
|
}
|
|
|
|
if target < current.Start.Line {
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
},
|
|
)
|
|
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
return s.Entries[index]
|
|
}
|