Skip to content

Commit

Permalink
Inlay hint support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Oct 23, 2023
1 parent 0e3bd97 commit 480508d
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe
| exit ||
| initialize ||
| initialized ||
| inlayHint/resolve | - |
| inlayHint/resolve | |
| notebookDocument/didChange | - |
| notebookDocument/didClose | - |
| notebookDocument/didOpen | - |
Expand All @@ -82,7 +82,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe
| textDocument/formatting ||
| textDocument/hover ||
| textDocument/implementation ||
| textDocument/inlayHint | - |
| textDocument/inlayHint | |
| textDocument/inlineValue | - |
| textDocument/linkedEditingRange | - |
| textDocument/moniker | - |
Expand Down Expand Up @@ -122,7 +122,7 @@ The LSP [specification](https://microsoft.github.io/language-server-protocol/spe
| workspace/didDeleteFiles ||
| workspace/didRenameFiles ||
| workspace/executeCommand ||
| workspace/inlayHint/refresh | - |
| workspace/inlayHint/refresh | |
| workspace/inlineValue/refresh | - |
| workspace/semanticTokens/refresh ||
| workspace/symbol ||
Expand Down
6 changes: 6 additions & 0 deletions Sources/LanguageServerProtocol/Additions/JSONRPCServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public actor JSONRPCServer: Server {
return try await session.response(to: method)
case .workspaceExecuteCommand(let params):
return try await session.response(to: method, params: params)
case .workspaceInlayHintRefresh:
return try await session.response(to: method)
case .workspaceWillCreateFiles(let params):
return try await session.response(to: method, params: params)
case .workspaceWillRenameFiles(let params):
Expand Down Expand Up @@ -175,6 +177,10 @@ 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 .inlayHint(let params):
return try await session.response(to: method, params: params)
case .inlayHintResolve(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):
Expand Down
12 changes: 12 additions & 0 deletions Sources/LanguageServerProtocol/Additions/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public extension Server {

// Workspace Requests
public extension Server {
func inlayHintRefresh() async throws {
try await sendRequestWithErrorOnlyResult(.workspaceInlayHintRefresh)
}

func willCreateFiles(params: CreateFilesParams) async throws -> WorkspaceWillCreateFilesResponse {
try await sendRequest(.workspaceWillCreateFiles(params))
}
Expand Down Expand Up @@ -258,4 +262,12 @@ public extension Server {
func colorPresentation(params: ColorPresentationParams) async throws -> ColorPresentationResponse {
try await sendRequest(.colorPresentation(params))
}

func inlayHint(params: InlayHintParams) async throws -> InlayHintResponse {
try await sendRequest(.inlayHint(params))
}

func inlayHintResolve(params: InlayHint) async throws -> InlayHint {
try await sendRequest(.inlayHintResolve(params))
}
}
2 changes: 2 additions & 0 deletions Sources/LanguageServerProtocol/ClientCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public struct TextDocumentClientCapabilities: Codable, Hashable, Sendable {
public var callHierarchy: CallHierarchyClientCapabilities?
public var semanticTokens: SemanticTokensClientCapabilities?
public var moniker: MonikerClientCapabilities?
public var inlayHint: InlayHintClientCapabilities?
public var diagnostic: DiagnosticClientCapabilities?

public init(synchronization: TextDocumentSyncClientCapabilities? = nil,
Expand Down Expand Up @@ -176,6 +177,7 @@ public struct TextDocumentClientCapabilities: Codable, Hashable, Sendable {
callHierarchy: CallHierarchyClientCapabilities? = nil,
semanticTokens: SemanticTokensClientCapabilities? = nil,
moniker: MonikerClientCapabilities? = nil,
inlayHint: InlayHintClientCapabilities? = nil,
diagnostic: DiagnosticClientCapabilities? = nil) {
self.synchronization = synchronization
self.completion = completion
Expand Down
104 changes: 104 additions & 0 deletions Sources/LanguageServerProtocol/LanguageFeatures/InlayHint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import Foundation

public struct InlayHintClientCapabilities: Codable, Hashable, Sendable {
public struct ResolveSupport: Codable, Hashable, Sendable {
public var properties: [String]

public init(properties: [String]) {
self.properties = properties
}
}

public var dynamicRegistration: Bool?
public var resolveSupport: ResolveSupport?

public init(dynamicRegistration: Bool?, resolveSupport: ResolveSupport? = nil) {
self.dynamicRegistration = dynamicRegistration
}
}

public typealias InlayHintOptions = WorkDoneProgressOptions

public struct InlayHintRegistrationOptions: Codable, Hashable, Sendable {
public var documentSelector: DocumentSelector?
public var workDoneProgress: Bool?
public var id: String?

public init(documentSelector: DocumentSelector? = nil, workDoneProgress: Bool? = nil, id: String? = nil) {
self.documentSelector = documentSelector
self.workDoneProgress = workDoneProgress
self.id = id
}
}

public struct InlayHintWorkspaceClientCapabilities: Codable, Hashable, Sendable {
public var refreshSupport: Bool?

public init(refreshSupport: Bool? = nil) {
self.refreshSupport = refreshSupport
}
}

public struct InlayHintParams: Codable, Hashable, Sendable {
public var workDoneToken: ProgressToken?
public var textDocument: TextDocumentIdentifier
public var range: LSPRange

public init(workDoneToken: ProgressToken? = nil, textDocument: TextDocumentIdentifier, range: LSPRange) {
self.workDoneToken = workDoneToken
self.textDocument = textDocument
self.range = range
}
}

public struct InlayHintLabelPart: Codable, Hashable, Sendable {
public var value: String
public var tooltop: TwoTypeOption<String, MarkupContent>?
public var location: Location?
public var command: Command?

public init(value: String, tooltop: TwoTypeOption<String, MarkupContent>? = nil, location: Location? = nil, command: Command? = nil) {
self.value = value
self.tooltop = tooltop
self.location = location
self.command = command
}
}

public enum InlayHintKind: Int, Codable, Hashable, Sendable {
case type = 1
case parameter = 2
}

public struct InlayHint: Codable, Hashable, Sendable {
public var position: Position
public var label: TwoTypeOption<String, [InlayHintLabelPart]>
public var kind: InlayHintKind?
public var textEdits: [TextEdit]?
public var tooltip: TwoTypeOption<String, MarkupContent>?
public var paddingLeft: Bool?
public var paddingRight: Bool?
public var data: LSPAny?

public init(
position: Position,
label: TwoTypeOption<String, [InlayHintLabelPart]>,
kind: InlayHintKind? = nil,
textEdits: [TextEdit]? = nil,
tooltip: TwoTypeOption<String, MarkupContent>? = nil,
paddingLeft: Bool? = nil,
paddingRight: Bool? = nil,
data: LSPAny? = nil
) {
self.position = position
self.label = label
self.kind = kind
self.textEdits = textEdits
self.tooltip = tooltip
self.paddingLeft = paddingLeft
self.paddingRight = paddingRight
self.data = data
}
}

public typealias InlayHintResponse = [InlayHint]?
12 changes: 12 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public enum ClientRequest: Sendable, Hashable {
case initialize
case shutdown
case workspaceExecuteCommand = "workspace/executeCommand"
case workspaceInlayHintRefresh = "workspace/inlayHint/refresh"
case workspaceWillCreateFiles = "workspace/willCreateFiles"
case workspaceWillRenameFiles = "workspace/willRenameFiles"
case workspaceWillDeleteFiles = "workspace/willDeleteFiles"
Expand Down Expand Up @@ -116,6 +117,8 @@ public enum ClientRequest: Sendable, Hashable {
case textDocumentRangeFormatting = "textDocument/rangeFormatting"
case textDocumentOnTypeFormatting = "textDocument/onTypeFormatting"
case textDocumentRename = "textDocument/rename"
case textDocumentInlayHint = "textDocument/inlayHint"
case inlayHintResolve = "inlayHint/resolve"
case textDocumentPrepareRename = "textDocument/prepareRename"
case textDocumentPrepareCallHierarchy = "textDocument/prepareCallHierarchy"
case textDocumentFoldingRange = "textDocument/foldingRange"
Expand All @@ -134,6 +137,7 @@ public enum ClientRequest: Sendable, Hashable {
case initialize(InitializeParams)
case shutdown
case workspaceExecuteCommand(ExecuteCommandParams)
case workspaceInlayHintRefresh
case workspaceWillCreateFiles(CreateFilesParams)
case workspaceWillRenameFiles(RenameFilesParams)
case workspaceWillDeleteFiles(DeleteFilesParams)
Expand All @@ -159,6 +163,8 @@ public enum ClientRequest: Sendable, Hashable {
case prepareCallHierarchy(CallHierarchyPrepareParams)
case prepareRename(PrepareRenameParams)
case rename(RenameParams)
case inlayHint(InlayHintParams)
case inlayHintResolve(InlayHint)
case documentLink(DocumentLinkParams)
case documentLinkResolve(DocumentLink)
case documentColor(DocumentColorParams)
Expand All @@ -183,6 +189,8 @@ public enum ClientRequest: Sendable, Hashable {
return .shutdown
case .workspaceExecuteCommand:
return .workspaceExecuteCommand
case .workspaceInlayHintRefresh:
return .workspaceInlayHintRefresh
case .workspaceWillCreateFiles:
return .workspaceWillCreateFiles
case .workspaceWillRenameFiles:
Expand Down Expand Up @@ -231,6 +239,10 @@ public enum ClientRequest: Sendable, Hashable {
return .textDocumentPrepareRename
case .rename:
return .textDocumentRename
case .inlayHint:
return .textDocumentInlayHint
case .inlayHintResolve:
return .inlayHintResolve
case .documentLink:
return .textDocumentDocumentLink
case .documentLinkResolve:
Expand Down
1 change: 1 addition & 0 deletions Sources/LanguageServerProtocol/ServerCapabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,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 inlayHintProvider: ThreeTypeOption<Bool, InlayHintOptions, InlayHintRegistrationOptions>?
public var diagnosticProvider: TwoTypeOption<DiagnosticOptions, DiagnosticRegistrationOptions>?
public var workspaceSymbolProvider: TwoTypeOption<Bool, WorkspaceSymbolOptions>?
public var workspace: Workspace?
Expand Down

0 comments on commit 480508d

Please sign in to comment.