Skip to content

Commit 35c52c7

Browse files
committed
Allow creation of TaskMetadata for all known notification and request types
Previously, we would sometimes log errors for example for the `setTrace` notification sent by VS Code. To avoid those logs, add cases for all known requests and notifications to the `TaskMetadata` initializers.
1 parent 19f8638 commit 35c52c7

File tree

4 files changed

+102
-31
lines changed

4 files changed

+102
-31
lines changed

Sources/LanguageServerProtocol/Requests/DocumentLinkRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// The document links request is sent from the client to the server to request the location of links in a document.
14-
public struct DocumentLinkRequest: RequestType {
14+
public struct DocumentLinkRequest: TextDocumentRequest {
1515
public static let method: String = "textDocument/documentLink"
1616
public typealias Response = [DocumentLink]?
1717

Sources/LanguageServerProtocol/Requests/InlineValueRefreshRequest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
struct InlineValueRefreshRequest: RequestType {
14-
static var method: String = "workspace/inlineValue/refresh"
15-
typealias Response = VoidResponse
13+
public struct InlineValueRefreshRequest: RequestType {
14+
public static var method: String = "workspace/inlineValue/refresh"
15+
public typealias Response = VoidResponse
1616

1717
public init() {}
1818
}

Sources/LanguageServerProtocol/Requests/WillSaveWaitUntilTextDocumentRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// The document will save request is sent from the client to the server before the document is actually saved. The request can return an array of TextEdits which will be applied to the text document before it is saved. Please note that clients might drop results if computing the text edits took too long or if a server constantly fails on this request. This is done to keep the save fast and reliable. If a server has registered for open / close events clients should ensure that the document is open before a willSaveWaitUntil notification is sent since clients can’t change the content of a file without ownership transferal.
14-
public struct WillSaveWaitUntilTextDocumentRequest: RequestType {
14+
public struct WillSaveWaitUntilTextDocumentRequest: TextDocumentRequest {
1515
public static let method: String = "textDocument/willSaveWaitUntil"
1616
public typealias Response = [TextEdit]?
1717

Sources/SourceKitLSP/SourceKitServer.swift

Lines changed: 97 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,26 +176,56 @@ fileprivate enum TaskMetadata: DependencyTracker {
176176

177177
init(_ notification: any NotificationType) {
178178
switch notification {
179-
case is InitializedNotification:
179+
case is CancelRequestNotification:
180+
self = .freestanding
181+
case is CancelWorkDoneProgressNotification:
182+
self = .freestanding
183+
case is DidChangeConfigurationNotification:
180184
self = .globalConfigurationChange
181-
case is CancelRequestNotification:
185+
case let notification as DidChangeNotebookDocumentNotification:
186+
self = .documentUpdate(notification.notebookDocument.uri)
187+
case let notification as DidChangeTextDocumentNotification:
188+
self = .documentUpdate(notification.textDocument.uri)
189+
case is DidChangeWatchedFilesNotification:
182190
self = .freestanding
183-
case is ExitNotification:
191+
case is DidChangeWorkspaceFoldersNotification:
184192
self = .globalConfigurationChange
185-
case let notification as DidOpenTextDocumentNotification:
193+
case let notification as DidCloseNotebookDocumentNotification:
194+
self = .documentUpdate(notification.notebookDocument.uri)
195+
case let notification as DidCloseTextDocumentNotification:
186196
self = .documentUpdate(notification.textDocument.uri)
187-
case let notification as DidCloseTextDocumentNotification:
197+
case is DidCreateFilesNotification:
198+
self = .freestanding
199+
case is DidDeleteFilesNotification:
200+
self = .freestanding
201+
case let notification as DidOpenNotebookDocumentNotification:
202+
self = .documentUpdate(notification.notebookDocument.uri)
203+
case let notification as DidOpenTextDocumentNotification:
188204
self = .documentUpdate(notification.textDocument.uri)
189-
case let notification as DidChangeTextDocumentNotification:
205+
case is DidRenameFilesNotification:
206+
self = .freestanding
207+
case let notification as DidSaveNotebookDocumentNotification:
208+
self = .documentUpdate(notification.notebookDocument.uri)
209+
case let notification as DidSaveTextDocumentNotification:
190210
self = .documentUpdate(notification.textDocument.uri)
191-
case is DidChangeWorkspaceFoldersNotification:
211+
case is ExitNotification:
192212
self = .globalConfigurationChange
193-
case is DidChangeWatchedFilesNotification:
213+
case is InitializedNotification:
214+
self = .globalConfigurationChange
215+
case is LogMessageNotification:
194216
self = .freestanding
195-
case let notification as WillSaveTextDocumentNotification:
196-
self = .documentUpdate(notification.textDocument.uri)
197-
case let notification as DidSaveTextDocumentNotification:
217+
case is LogTraceNotification:
218+
self = .freestanding
219+
case is PublishDiagnosticsNotification:
220+
self = .freestanding
221+
case is SetTraceNotification:
222+
self = .globalConfigurationChange
223+
case is ShowMessageNotification:
224+
self = .freestanding
225+
case let notification as WillSaveTextDocumentNotification:
198226
self = .documentUpdate(notification.textDocument.uri)
227+
case is WorkDoneProgress:
228+
self = .freestanding
199229
default:
200230
logger.error(
201231
"""
@@ -209,32 +239,73 @@ fileprivate enum TaskMetadata: DependencyTracker {
209239

210240
init(_ request: any RequestType) {
211241
switch request {
212-
case is InitializeRequest:
213-
self = .globalConfigurationChange
214-
case is ShutdownRequest:
215-
self = .globalConfigurationChange
216-
case is WorkspaceSymbolsRequest:
242+
case let request as any TextDocumentRequest: self = .documentRequest(request.textDocument.uri)
243+
case is ApplyEditRequest:
217244
self = .freestanding
218-
case is BarrierRequest:
219-
self = .globalConfigurationChange
220-
case is PollIndexRequest:
245+
case is BarrierRequest:
221246
self = .globalConfigurationChange
222-
case let request as ExecuteCommandRequest:
247+
case is CallHierarchyIncomingCallsRequest:
248+
self = .freestanding
249+
case is CallHierarchyOutgoingCallsRequest:
250+
self = .freestanding
251+
case is CodeActionResolveRequest:
252+
self = .freestanding
253+
case is CodeLensRefreshRequest:
254+
self = .freestanding
255+
case is CodeLensResolveRequest:
256+
self = .freestanding
257+
case is CompletionItemResolveRequest:
258+
self = .freestanding
259+
case is CreateWorkDoneProgressRequest:
260+
self = .freestanding
261+
case is DiagnosticsRefreshRequest:
262+
self = .freestanding
263+
case is DocumentLinkResolveRequest:
264+
self = .freestanding
265+
case let request as ExecuteCommandRequest:
223266
if let uri = request.textDocument?.uri {
224267
self = .documentRequest(uri)
225268
} else {
226269
self = .freestanding
227270
}
228-
case is CallHierarchyIncomingCallsRequest:
271+
case is InitializeRequest:
272+
self = .globalConfigurationChange
273+
case is InlayHintRefreshRequest:
274+
self = .freestanding
275+
case is InlayHintResolveRequest:
276+
self = .freestanding
277+
case is InlineValueRefreshRequest:
278+
self = .freestanding
279+
case is PollIndexRequest:
280+
self = .globalConfigurationChange
281+
case is RegisterCapabilityRequest:
282+
self = .globalConfigurationChange
283+
case is ShowMessageRequest:
284+
self = .freestanding
285+
case is ShutdownRequest:
286+
self = .globalConfigurationChange
287+
case is TypeHierarchySubtypesRequest:
288+
self = .freestanding
289+
case is TypeHierarchySupertypesRequest:
290+
self = .freestanding
291+
case is UnregisterCapabilityRequest:
292+
self = .globalConfigurationChange
293+
case is WillCreateFilesRequest:
294+
self = .freestanding
295+
case is WillDeleteFilesRequest:
296+
self = .freestanding
297+
case is WillRenameFilesRequest:
298+
self = .freestanding
299+
case is WorkspaceDiagnosticsRequest:
300+
self = .freestanding
301+
case is WorkspaceFoldersRequest:
229302
self = .freestanding
230-
case is CallHierarchyOutgoingCallsRequest:
303+
case is WorkspaceSemanticTokensRefreshRequest:
231304
self = .freestanding
232-
case is TypeHierarchySupertypesRequest:
305+
case is WorkspaceSymbolResolveRequest:
233306
self = .freestanding
234-
case is TypeHierarchySubtypesRequest:
307+
case is WorkspaceSymbolsRequest:
235308
self = .freestanding
236-
case let request as any TextDocumentRequest:
237-
self = .documentRequest(request.textDocument.uri)
238309
default:
239310
logger.error(
240311
"""

0 commit comments

Comments
 (0)