From e7f32c47c74195594b707d60399498e80f167484 Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Sun, 23 Jul 2023 07:42:04 -0400 Subject: [PATCH] textDocument/diagnostic --- README.md | 2 +- .../Additions/JSONRPCServer.swift | 2 + .../Additions/Server.swift | 4 ++ .../LanguageFeatures/Diagnostics.swift | 63 +++++++++++++++++++ .../LanguageServerProtocol.swift | 4 ++ .../ServerCapabilities.swift | 1 + 6 files changed, 75 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d73feb9..90c9774 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe | textDocument/completion | ✅ | | textDocument/declaration | ✅ | | textDocument/definition | ✅ | -| textDocument/diagnostic | | +| textDocument/diagnostic | ✅ | | textDocument/didChange | ✅ | | textDocument/didClose | ✅ | | textDocument/didOpen | ✅ | diff --git a/Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift b/Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift index 77c83f8..085ef69 100644 --- a/Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift +++ b/Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift @@ -175,6 +175,8 @@ public actor JSONRPCServer: Server { return try await session.response(to: method, params: params) case .rename(let params): return try await session.response(to: method, params: params) + case .diagnostics(let params): + return try await session.response(to: method, params: params) case .documentLink(let params): return try await session.response(to: method, params: params) case .documentLinkResolve(let params): diff --git a/Sources/LanguageServerProtocol/Additions/Server.swift b/Sources/LanguageServerProtocol/Additions/Server.swift index 142807f..70f1f62 100644 --- a/Sources/LanguageServerProtocol/Additions/Server.swift +++ b/Sources/LanguageServerProtocol/Additions/Server.swift @@ -235,6 +235,10 @@ public extension Server { try await sendRequest(.codeLensResolve(params)) } + func diagnostics(params: DocumentDiagnosticParams) async throws -> DocumentDiagnosticReport { + try await sendRequest(.diagnostics(params)) + } + func selectionRange(params: SelectionRangeParams) async throws -> SelectionRangeResponse { try await sendRequest(.selectionRange(params)) } diff --git a/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift b/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift index 8237e79..defad57 100644 --- a/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift +++ b/Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift @@ -1,5 +1,21 @@ import Foundation +public struct DiagnosticOptions: Codable, Hashable, Sendable { + public let workDoneProgress: Bool? + public let identifier: String? + public let interFileDependencies: Bool + public let workspaceDiagnostics: Bool +} + +public struct DiagnosticRegistrationOptions: Codable, Hashable, Sendable { + public let documentSelector: DocumentSelector? + public let workDoneProgress: Bool? + public let identifier: String? + public let interFileDependencies: Bool + public let workspaceDiagnostics: Bool + public let id: String? +} + public struct PublishDiagnosticsClientCapabilities: Codable, Hashable, Sendable { public var relatedInformation: Bool? public var tagSupport: ValueSet? @@ -50,3 +66,50 @@ public struct PublishDiagnosticsParams: Codable, Hashable, Sendable { public let version: Int? public let diagnostics: [Diagnostic] } + +public struct DocumentDiagnosticParams: Codable, Hashable, Sendable { + public let workDoneToken: ProgressToken? + public let partialResultToken: ProgressToken? + public let textDocument: TextDocumentIdentifier + public let identifier: String? + public let previousResultId: String? + + public init( + workDoneToken: ProgressToken? = nil, + partialResultToken: ProgressToken? = nil, + textDocument: TextDocumentIdentifier, + identifier: String? = nil, + previousResultId: String? = nil + ) { + self.workDoneToken = workDoneToken + self.partialResultToken = partialResultToken + self.textDocument = textDocument + self.identifier = identifier + self.previousResultId = previousResultId + } +} + +public enum DocumentDiagnosticReportKind: String, Codable, Hashable, Sendable, CaseIterable { + case full + case unchanged +} + +public struct BaseDocumentDiagnosticReport: Codable, Hashable, Sendable { + public let kind: DocumentDiagnosticReportKind + public let resultId: String? + public let items: [Diagnostic]? +} + +public struct RelatedDocumentDiagnosticReport: Codable, Hashable, Sendable { + public let kind: DocumentDiagnosticReportKind + public let resultId: String? + public let items: [Diagnostic]? + public let relatedDocuments: [DocumentUri: DocumentDiagnosticReport]? +} + +typealias FullDocumentDiagnosticReport = BaseDocumentDiagnosticReport +typealias UnchangedDocumentDiagnosticReport = BaseDocumentDiagnosticReport +typealias RelatedFullDocumentDiagnosticReport = RelatedDocumentDiagnosticReport +typealias RelatedUnchangedDocumentDiagnosticReport = RelatedDocumentDiagnosticReport + +public typealias DocumentDiagnosticReport = RelatedDocumentDiagnosticReport diff --git a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift index a9f0b79..6894946 100644 --- a/Sources/LanguageServerProtocol/LanguageServerProtocol.swift +++ b/Sources/LanguageServerProtocol/LanguageServerProtocol.swift @@ -107,6 +107,7 @@ public enum ClientRequest: Sendable, Hashable { case codeActionResolve = "codeAction/resolve" case codeLensResolve = "codeLens/resolve" case textDocumentCodeLens = "textDocument/codeLens" + case textDocumentDiagnostic = "textDocument/diagnostic" case textDocumentDocumentLink = "textDocument/documentLink" case documentLinkResolve = "documentLink/resolve" case textDocumentDocumentColor = "textDocument/documentColor" @@ -147,6 +148,7 @@ public enum ClientRequest: Sendable, Hashable { case definition(TextDocumentPositionParams) case typeDefinition(TextDocumentPositionParams) case implementation(TextDocumentPositionParams) + case diagnostics(DocumentDiagnosticParams) case documentHighlight(DocumentHighlightParams) case documentSymbol(DocumentSymbolParams) case codeAction(CodeActionParams) @@ -235,6 +237,8 @@ public enum ClientRequest: Sendable, Hashable { return .documentLinkResolve case .documentColor: return .textDocumentDocumentColor + case .diagnostics: + return .textDocumentDiagnostic case .colorPresentation: return .textDocumentColorPresentation case .formatting: diff --git a/Sources/LanguageServerProtocol/ServerCapabilities.swift b/Sources/LanguageServerProtocol/ServerCapabilities.swift index 417b09d..f679c5e 100644 --- a/Sources/LanguageServerProtocol/ServerCapabilities.swift +++ b/Sources/LanguageServerProtocol/ServerCapabilities.swift @@ -215,6 +215,7 @@ public struct ServerCapabilities: Codable, Hashable, Sendable { public var callHierarchyProvider: ThreeTypeOption? public var semanticTokensProvider: TwoTypeOption? public var monikerProvider: ThreeTypeOption? + public var diagnosticProvider: TwoTypeOption? public var workspaceSymbolProvider: TwoTypeOption? public var workspace: Workspace? public var experimental: LSPAny?