Skip to content

Update request and notification definitions to LSP 3.17 #669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 55 additions & 6 deletions Sources/LanguageServerProtocol/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,68 @@ public struct ErrorCode: RawRepresentable, Codable, Hashable {
self.rawValue = rawValue
}

// JSON RPC
// MARK: JSON RPC
public static let parseError: ErrorCode = ErrorCode(rawValue: -32700)
public static let invalidRequest: ErrorCode = ErrorCode(rawValue: -32600)
public static let methodNotFound: ErrorCode = ErrorCode(rawValue: -32601)
public static let invalidParams: ErrorCode = ErrorCode(rawValue: -32602)
public static let internalError: ErrorCode = ErrorCode(rawValue: -32603)
public static let serverErrorStart: ErrorCode = ErrorCode(rawValue: -32099)
public static let serverErrorEnd: ErrorCode = ErrorCode(rawValue: -32000)
public static let workspaceNotOpen: ErrorCode = ErrorCode(rawValue: -32003)
public static let unknownErrorCode: ErrorCode = ErrorCode(rawValue: -32001)

// LSP

/// This is the start range of JSON-RPC reserved error codes.
/// It doesn't denote a real error code. No LSP error codes should
/// be defined between the start and end range. For backwards
/// compatibility the `ServerNotInitialized` and the `UnknownErrorCode`
/// are left in the range.
public static let jsonrpcReservedErrorRangeStart = ErrorCode(rawValue: -32099)
public static let serverErrorStart: ErrorCode = jsonrpcReservedErrorRangeStart

/// Error code indicating that a server received a notification or
/// request before the server has received the `initialize` request.
public static let serverNotInitialized = ErrorCode(rawValue: -32002)
public static let unknownErrorCode = ErrorCode(rawValue: -32001)

/// This is the end range of JSON-RPC reserved error codes.
/// It doesn't denote a real error code.
public static let jsonrpcReservedErrorRangeEnd = ErrorCode(rawValue: -32000)
/// Deprecated, use jsonrpcReservedErrorRangeEnd
public static let serverErrorEnd = jsonrpcReservedErrorRangeEnd

/// This is the start range of LSP reserved error codes.
/// It doesn't denote a real error code.
public static let lspReservedErrorRangeStart = ErrorCode(rawValue: -32899)

/// A request failed but it was syntactically correct, e.g the
/// method name was known and the parameters were valid. The error
/// message should contain human readable information about why
/// the request failed.
public static let requestFailed = ErrorCode(rawValue: -32803)

/// The server cancelled the request. This error code should
/// only be used for requests that explicitly support being
/// server cancellable.
public static let serverCancelled = ErrorCode(rawValue: -32802)

/// The server detected that the content of a document got
/// modified outside normal conditions. A server should
/// NOT send this error code if it detects a content change
/// in it unprocessed messages. The result even computed
/// on an older state might still be useful for the client.
///
/// If a client decides that a result is not of any use anymore
/// the client should cancel the request.
public static let contentModified = ErrorCode(rawValue: -32801)

/// The client has canceled a request and a server as detected
/// the cancel.
public static let cancelled: ErrorCode = ErrorCode(rawValue: -32800)

/// This is the end range of LSP reserved error codes.
/// It doesn't denote a real error code.
public static let lspReservedErrorRangeEnd = ErrorCode(rawValue: -32800)

// MARK: SourceKit-LSP specifiic eror codes
public static let workspaceNotOpen: ErrorCode = ErrorCode(rawValue: -32003)
}

/// An error response represented by a code and message.
Expand Down
98 changes: 65 additions & 33 deletions Sources/LanguageServerProtocol/Messages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,48 +16,70 @@
/// If you are adding a message for testing only, you can register it dynamically using
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
public let builtinRequests: [_RequestType.Type] = [
InitializeRequest.self,
ShutdownRequest.self,
WorkspaceFoldersRequest.self,
CompletionRequest.self,
HoverRequest.self,
WorkspaceSemanticTokensRefreshRequest.self,
WorkspaceSymbolsRequest.self,
ApplyEditRequest.self,
CallHierarchyIncomingCallsRequest.self,
CallHierarchyOutgoingCallsRequest.self,
CallHierarchyPrepareRequest.self,
TypeHierarchyPrepareRequest.self,
TypeHierarchySupertypesRequest.self,
TypeHierarchySubtypesRequest.self,
CodeActionRequest.self,
CodeActionResolveRequest.self,
CodeLensRefreshRequest.self,
CodeLensRequest.self,
CodeLensResolveRequest.self,
ColorPresentationRequest.self,
CompletionItemResolveRequest.self,
CompletionRequest.self,
CreateWorkDoneProgressRequest.self,
DeclarationRequest.self,
DefinitionRequest.self,
ImplementationRequest.self,
ReferencesRequest.self,
DocumentHighlightRequest.self,
DiagnosticsRefreshRequest.self,
DocumentColorRequest.self,
DocumentDiagnosticsRequest.self,
DocumentFormattingRequest.self,
DocumentHighlightRequest.self,
DocumentLinkRequest.self,
DocumentLinkResolveRequest.self,
DocumentOnTypeFormattingRequest.self,
DocumentRangeFormattingRequest.self,
DocumentSemanticTokensDeltaRequest.self,
DocumentSemanticTokensRangeRequest.self,
DocumentSemanticTokensRequest.self,
DocumentOnTypeFormattingRequest.self,
FoldingRangeRequest.self,
DocumentSymbolRequest.self,
DocumentColorRequest.self,
ColorPresentationRequest.self,
CodeActionRequest.self,
ExecuteCommandRequest.self,
ApplyEditRequest.self,
FoldingRangeRequest.self,
HoverRequest.self,
ImplementationRequest.self,
InitializeRequest.self,
InlayHintRefreshRequest.self,
InlayHintRequest.self,
InlayHintResolveRequest.self,
InlineValueRefreshRequest.self,
InlineValueRequest.self,
LinkedEditingRangeRequest.self,
MonikersRequest.self,
PollIndexRequest.self,
PrepareRenameRequest.self,
RenameRequest.self,
ReferencesRequest.self,
RegisterCapabilityRequest.self,
RenameRequest.self,
SelectionRangeRequest.self,
ShowMessageRequest.self,
ShutdownRequest.self,
SignatureHelpRequest.self,
SymbolInfoRequest.self,
TypeDefinitionRequest.self,
TypeHierarchyPrepareRequest.self,
TypeHierarchySubtypesRequest.self,
TypeHierarchySupertypesRequest.self,
UnregisterCapabilityRequest.self,
InlayHintRequest.self,

// MARK: LSP Extension Requests

SymbolInfoRequest.self,
PollIndexRequest.self,
WillCreateFilesRequest.self,
WillDeleteFilesRequest.self,
WillRenameFilesRequest.self,
WillSaveWaitUntilTextDocumentRequest.self,
WorkspaceDiagnosticsRequest.self,
WorkspaceFoldersRequest.self,
WorkspaceSemanticTokensRefreshRequest.self,
WorkspaceSymbolResolveRequest.self,
WorkspaceSymbolsRequest.self,
]

/// The set of known notifications.
Expand All @@ -66,19 +88,29 @@ public let builtinRequests: [_RequestType.Type] = [
/// here. If you are adding a message for testing only, you can register it dynamically using
/// `MessageRegistry._register()` which allows you to avoid bloating the real server implementation.
public let builtinNotifications: [NotificationType.Type] = [
InitializedNotification.self,
ExitNotification.self,
CancelRequestNotification.self,
LogMessageNotification.self,
CancelWorkDoneProgressNotification.self,
DidChangeConfigurationNotification.self,
DidChangeNotebookDocumentNotification.self,
DidChangeTextDocumentNotification.self,
DidChangeWatchedFilesNotification.self,
DidChangeWorkspaceFoldersNotification.self,
DidOpenTextDocumentNotification.self,
DidCloseNotebookDocumentNotification.self,
DidCloseTextDocumentNotification.self,
DidChangeTextDocumentNotification.self,
DidSaveTextDocumentNotification.self,
WillSaveTextDocumentNotification.self,
DidCreateFilesNotification.self,
DidDeleteFilesNotification.self,
DidOpenNotebookDocumentNotification.self,
DidOpenTextDocumentNotification.self,
DidRenameFilesNotification.self,
DidSaveNotebookDocumentNotification.self,
ExitNotification.self,
InitializedNotification.self,
LogMessageNotification.self,
LogTraceNotification.self,
PublishDiagnosticsNotification.self,
SetTraceNotification.self,
ShowMessageNotification.self,
WorkDoneProgress.self,
]

// MARK: Miscellaneous Message Types
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

public struct CancelWorkDoneProgressNotification: NotificationType {
public static var method: String = "window/workDoneProgress/cancel"

public var token: ProgressToken

public init(token: ProgressToken) {
self.token = token
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

public struct DidCreateFilesNotification: NotificationType {
public static var method: String = "workspace/didCreateFiles"

/// An array of all files/folders created in this operation.
public var files: [FileCreate]

public init(files: [FileCreate]) {
self.files = files
}
}

public struct DidRenameFilesNotification: NotificationType {
public static var method: String = "workspace/didRenameFiles"

/// An array of all files/folders renamed in this operation. When a folder
/// is renamed, only the folder will be included, and not its children.
public var files: [FileRename]

public init(files: [FileRename]) {
self.files = files
}
}

public struct DidDeleteFilesNotification: NotificationType {
public static var method: String = "workspace/didDeleteFiles"

/// An array of all files/folders created in this operation.
public var files: [FileDelete]

public init(files: [FileDelete]) {
self.files = files
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A notification to log the trace of the server’s execution. The amount and content of these notifications depends on the current trace configuration. If trace is 'off', the server should not send any logTrace notification. If trace is 'messages', the server should not add the 'verbose' field in the LogTraceParams.
///
/// $/logTrace should be used for systematic trace reporting. For single debugging messages, the server should send window/logMessage notifications.
public struct LogTraceNotification: NotificationType, Hashable, Codable {
public static let method: String = "$/logTrace"

/// The message to be logged.
public var message: String

/// Additional information that can be computed if the `trace` configuration
/// is set to `'verbose'`
public var verbose: String?

public init(message: String, verbose: String?) {
self.message = message
self.verbose = verbose
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A notification that should be used by the client to modify the trace setting of the server.
public struct SetTraceNotification: NotificationType, Hashable, Codable {
public static let method: String = "$/setTrace"

/// The new value that should be assigned to the trace setting.
public var value: Tracing

public init(value: Tracing) {
self.value = value
}
}
Loading