Skip to content

Commit

Permalink
textDocument/diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jul 23, 2023
1 parent a244efe commit e7f32c4
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
2 changes: 2 additions & 0 deletions Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions Sources/LanguageServerProtocol/Additions/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
63 changes: 63 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/Diagnostics.swift
Original file line number Diff line number Diff line change
@@ -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<DiagnosticTag>?
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Sources/LanguageServerProtocol/ServerCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public struct ServerCapabilities: Codable, Hashable, Sendable {
public var callHierarchyProvider: ThreeTypeOption<Bool, CallHierarchyOptions, CallHierarchyRegistrationOptions>?
public var semanticTokensProvider: TwoTypeOption<SemanticTokensOptions, SemanticTokensRegistrationOptions>?
public var monikerProvider: ThreeTypeOption<Bool, MonikerOptions, MonikerRegistrationOptions>?
public var diagnosticProvider: TwoTypeOption<DiagnosticOptions, DiagnosticRegistrationOptions>?
public var workspaceSymbolProvider: TwoTypeOption<Bool, WorkspaceSymbolOptions>?
public var workspace: Workspace?
public var experimental: LSPAny?
Expand Down

0 comments on commit e7f32c4

Please sign in to comment.