Skip to content

Commit 11764c1

Browse files
charlieegan3anderseknert
authored andcommitted
lsp: Use notify for sending messages
Previously, we were using Call, this will wait for a request and can block. This PR uses Notify instead, which is non-blocking and follows the spec. Signed-off-by: Charlie Egan <[email protected]>
1 parent f078127 commit 11764c1

5 files changed

+10
-10
lines changed

internal/lsp/server_aggregates_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import rego.v1
7474

7575
barURI := fileURIScheme + filepath.Join(tempDir, "bar.rego")
7676

77-
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
77+
err = connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
7878
TextDocument: types.TextDocumentIdentifier{
7979
URI: barURI,
8080
},
@@ -111,7 +111,7 @@ import rego.v1
111111

112112
fooURI := fileURIScheme + filepath.Join(tempDir, "foo.rego")
113113

114-
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
114+
err = connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
115115
TextDocument: types.TextDocumentIdentifier{
116116
URI: fooURI,
117117
},
@@ -249,7 +249,7 @@ import data.quz
249249
}
250250

251251
// 2. check the aggregates for a file are updated after an update
252-
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
252+
err = connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
253253
TextDocument: types.TextDocumentIdentifier{
254254
URI: fileURIScheme + filepath.Join(tempDir, "bar.rego"),
255255
},
@@ -355,7 +355,7 @@ import rego.v1
355355
// update the contents of the bar.rego file to address the unresolved-import
356356
barURI := fileURIScheme + filepath.Join(tempDir, "bar.rego")
357357

358-
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
358+
err = connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
359359
TextDocument: types.TextDocumentIdentifier{
360360
URI: barURI,
361361
},
@@ -397,7 +397,7 @@ import rego.v1
397397
}
398398

399399
// update the contents of the bar.rego to bring back the violation
400-
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
400+
err = connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
401401
TextDocument: types.TextDocumentIdentifier{
402402
URI: barURI,
403403
},

internal/lsp/server_config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ rules:
193193
}
194194

195195
// this event is sent to allow the server to detect the new config
196-
if err := connClient.Call(ctx, "workspace/didChangeWatchedFiles", types.WorkspaceDidChangeWatchedFilesParams{
196+
if err := connClient.Notify(ctx, "workspace/didChangeWatchedFiles", types.WorkspaceDidChangeWatchedFilesParams{
197197
Changes: []types.FileEvent{
198198
{
199199
URI: fileURIScheme + filepath.Join(tempDir, ".regal/config.yaml"),

internal/lsp/server_multi_file_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ ignore:
130130

131131
// 3. Client sends textDocument/didChange notification with new contents
132132
// for authz.rego no response to the call is expected
133-
if err := connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
133+
if err := connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
134134
TextDocument: types.TextDocumentIdentifier{
135135
URI: fileURIScheme + filepath.Join(tempDir, "authz.rego"),
136136
},

internal/lsp/server_single_file_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ rules:
9595

9696
// Client sends textDocument/didChange notification with new contents for main.rego
9797
// no response to the call is expected
98-
if err := connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
98+
if err := connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
9999
TextDocument: types.TextDocumentIdentifier{
100100
URI: mainRegoURI,
101101
},
@@ -220,7 +220,7 @@ capabilities:
220220
// the start of an EOPA-specific call, so if the capabilities were
221221
// loaded correctly, we should see a completion later after we ask for
222222
// it.
223-
if err := connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
223+
if err := connClient.Notify(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
224224
TextDocument: types.TextDocumentIdentifier{
225225
URI: mainRegoURI,
226226
},

internal/lsp/server_template_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func TestNewFileTemplating(t *testing.T) {
262262
}
263263

264264
// Client sends workspace/didCreateFiles notification
265-
if err := connClient.Call(ctx, "workspace/didCreateFiles", types.WorkspaceDidCreateFilesParams{
265+
if err := connClient.Notify(ctx, "workspace/didCreateFiles", types.WorkspaceDidCreateFilesParams{
266266
Files: []types.WorkspaceDidCreateFilesParamsCreatedFile{
267267
{URI: newFileURI},
268268
},

0 commit comments

Comments
 (0)