mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
40 lines
578 B
Go
40 lines
578 B
Go
package ast
|
|
|
|
import (
|
|
"slices"
|
|
)
|
|
|
|
func (c *WGConfig) FindSectionByLine(line uint32) *WGSection {
|
|
index, found := slices.BinarySearchFunc(
|
|
c.Sections,
|
|
line,
|
|
func(current *WGSection, target uint32) int {
|
|
if target < current.Start.Line {
|
|
return 1
|
|
}
|
|
|
|
if target > current.Start.Line {
|
|
return -1
|
|
}
|
|
|
|
return 0
|
|
},
|
|
)
|
|
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
return c.Sections[index]
|
|
}
|
|
|
|
func (c *WGConfig) FindPropertyByLine(line uint32) *WGProperty {
|
|
section := c.FindSectionByLine(line)
|
|
|
|
if section == nil {
|
|
return nil
|
|
}
|
|
|
|
return section.Properties[line]
|
|
}
|