Skip to content

Commit dd01f6f

Browse files
author
Charlie Egan
committed
lsp: Fix server signature race in test
E.g. https://github.com/StyraInc/regal/actions/runs/16962142183/job/48077281888?pr=1653 Signed-off-by: Charlie Egan <charlie@styra.com>
1 parent ef44b9e commit dd01f6f

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

internal/lsp/server_signature_help_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ func TestTextDocumentSignatureHelp(t *testing.T) {
2020

2121
tempDir := t.TempDir()
2222

23-
ls := NewLanguageServer(ctx, &LanguageServerOptions{
24-
LogWriter: newTestLogger(t),
25-
LogLevel: log.LevelDebug,
26-
})
27-
2823
mainRegoURI := fileURIScheme + filepath.Join(tempDir, "main.rego")
2924

3025
content := `package example
@@ -33,20 +28,12 @@ allow if regex.match(` + "`foo`" + `, "bar")
3328
allow if count([1,2,3]) == 2
3429
allow if concat(",", "a", "b") == "b,a"`
3530

36-
ls.cache.SetFileContents(mainRegoURI, content)
37-
3831
builtins := map[string]*ast.Builtin{
3932
"count": ast.Count,
4033
"concat": ast.Concat,
4134
"regex.match": ast.RegexMatch,
4235
}
4336

44-
// this is needed to prepare the server for signature help queries
45-
err := ls.storeBuiltinsAndCacheSignatureHelp(ctx, builtins)
46-
if err != nil {
47-
t.Fatalf("failed to store builtins and cache signature help: %s", err)
48-
}
49-
5037
testCases := map[string]struct {
5138
position types.Position
5239
expectedLabel string
@@ -77,6 +64,19 @@ allow if concat(",", "a", "b") == "b,a"`
7764
t.Run(name, func(t *testing.T) {
7865
t.Parallel()
7966

67+
ls := NewLanguageServer(ctx, &LanguageServerOptions{
68+
LogWriter: newTestLogger(t),
69+
LogLevel: log.LevelDebug,
70+
})
71+
72+
ls.cache.SetFileContents(mainRegoURI, content)
73+
74+
// this is needed to prepare the server for signature help queries
75+
err := ls.storeBuiltinsAndCacheSignatureHelp(ctx, builtins)
76+
if err != nil {
77+
t.Fatalf("failed to store builtins and cache signature help: %s", err)
78+
}
79+
8080
params := types.SignatureHelpParams{
8181
TextDocumentPositionParams: types.TextDocumentPositionParams{
8282
TextDocument: types.TextDocumentIdentifier{URI: mainRegoURI},

0 commit comments

Comments
 (0)