mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 06:55:26 +02:00
feat(server): Add blockUntilNotNil to allow waiting for indexes
This commit is contained in:
parent
65c54595bc
commit
942a9e1d48
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
sshconfig "config-lsp/handlers/ssh_config"
|
||||
"config-lsp/utils"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
@ -10,7 +11,7 @@ func FetchCodeActions(
|
||||
d *sshconfig.SSHDocument,
|
||||
params *protocol.CodeActionParams,
|
||||
) []protocol.CodeAction {
|
||||
if d.Indexes == nil {
|
||||
if utils.BlockUntilIndexesNotNil(d.Indexes) == false {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ func GetRootCompletions(
|
||||
parentMatchBlock *ast.SSHDMatchBlock,
|
||||
suggestValue bool,
|
||||
) ([]protocol.CompletionItem, error) {
|
||||
if d.Indexes == nil {
|
||||
if utils.BlockUntilIndexesNotNil(d.Indexes) == false {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
sshdconfig "config-lsp/handlers/sshd_config"
|
||||
"config-lsp/utils"
|
||||
|
||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||
)
|
||||
@ -10,7 +11,7 @@ func FetchCodeActions(
|
||||
d *sshdconfig.SSHDDocument,
|
||||
params *protocol.CodeActionParams,
|
||||
) []protocol.CodeAction {
|
||||
if d.Indexes == nil {
|
||||
if utils.BlockUntilIndexesNotNil(d.Indexes) == false {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
30
server/utils/time.go
Normal file
30
server/utils/time.go
Normal file
@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
func BlockUntilNotNil(pointer any) {
|
||||
for pointer == nil {
|
||||
// This is a blocking call to wait until the pointer is not nil.
|
||||
// It can be used in scenarios where the pointer is expected to be set by another goroutine.
|
||||
}
|
||||
}
|
||||
|
||||
func BlockUntilNotNilTimeout(pointer any, timeout time.Duration) bool {
|
||||
deadline := time.Now().Add(timeout)
|
||||
|
||||
for pointer == nil {
|
||||
if time.Now().After(deadline) {
|
||||
return false
|
||||
}
|
||||
// This is a blocking call to wait until the pointer is not nil.
|
||||
// It can be used in scenarios where the pointer is expected to be set by another goroutine.
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Waits till the provided pointer is not nil.
|
||||
// Has a default timeout of 3 seconds
|
||||
func BlockUntilIndexesNotNil(d any) bool {
|
||||
return BlockUntilNotNilTimeout(d, 3*time.Second)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user