mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
40 lines
625 B
Go
40 lines
625 B
Go
package handlers
|
|
|
|
import (
|
|
"config-lsp/handlers/aliases/ast"
|
|
"slices"
|
|
)
|
|
|
|
func GetValueAtCursor(
|
|
cursor uint32,
|
|
entry *ast.AliasEntry,
|
|
) *ast.AliasValueInterface {
|
|
if entry.Values == nil || len(entry.Values.Values) == 0 {
|
|
return nil
|
|
}
|
|
|
|
index, found := slices.BinarySearchFunc(
|
|
entry.Values.Values,
|
|
cursor,
|
|
func(entry ast.AliasValueInterface, pos uint32) int {
|
|
value := entry.GetAliasValue()
|
|
|
|
if pos > value.Location.End.Character {
|
|
return -1
|
|
}
|
|
|
|
if pos < value.Location.Start.Character {
|
|
return 1
|
|
}
|
|
|
|
return 0
|
|
},
|
|
)
|
|
|
|
if !found {
|
|
return nil
|
|
}
|
|
|
|
return &entry.Values.Values[index]
|
|
}
|