mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15: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 (
|
import (
|
||||||
sshconfig "config-lsp/handlers/ssh_config"
|
sshconfig "config-lsp/handlers/ssh_config"
|
||||||
|
"config-lsp/utils"
|
||||||
|
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
)
|
)
|
||||||
@ -10,7 +11,7 @@ func FetchCodeActions(
|
|||||||
d *sshconfig.SSHDocument,
|
d *sshconfig.SSHDocument,
|
||||||
params *protocol.CodeActionParams,
|
params *protocol.CodeActionParams,
|
||||||
) []protocol.CodeAction {
|
) []protocol.CodeAction {
|
||||||
if d.Indexes == nil {
|
if utils.BlockUntilIndexesNotNil(d.Indexes) == false {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ func GetRootCompletions(
|
|||||||
parentMatchBlock *ast.SSHDMatchBlock,
|
parentMatchBlock *ast.SSHDMatchBlock,
|
||||||
suggestValue bool,
|
suggestValue bool,
|
||||||
) ([]protocol.CompletionItem, error) {
|
) ([]protocol.CompletionItem, error) {
|
||||||
if d.Indexes == nil {
|
if utils.BlockUntilIndexesNotNil(d.Indexes) == false {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
sshdconfig "config-lsp/handlers/sshd_config"
|
sshdconfig "config-lsp/handlers/sshd_config"
|
||||||
|
"config-lsp/utils"
|
||||||
|
|
||||||
protocol "github.com/tliron/glsp/protocol_3_16"
|
protocol "github.com/tliron/glsp/protocol_3_16"
|
||||||
)
|
)
|
||||||
@ -10,7 +11,7 @@ func FetchCodeActions(
|
|||||||
d *sshdconfig.SSHDDocument,
|
d *sshdconfig.SSHDDocument,
|
||||||
params *protocol.CodeActionParams,
|
params *protocol.CodeActionParams,
|
||||||
) []protocol.CodeAction {
|
) []protocol.CodeAction {
|
||||||
if d.Indexes == nil {
|
if utils.BlockUntilIndexesNotNil(d.Indexes) == false {
|
||||||
return nil
|
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