@@ -700,6 +700,8 @@ extension SourceKitLSPServer: MessageHandler {
700700 await self . handleRequest ( for: request, requestHandler: self . prepareCallHierarchy)
701701 case let request as RequestAndReply < CodeActionRequest > :
702702 await self . handleRequest ( for: request, requestHandler: self . codeAction)
703+ case let request as RequestAndReply < CodeLensRequest > :
704+ await self . handleRequest ( for: request, requestHandler: self . codeLens)
703705 case let request as RequestAndReply < ColorPresentationRequest > :
704706 await self . handleRequest ( for: request, requestHandler: self . colorPresentation)
705707 case let request as RequestAndReply < CompletionRequest > :
@@ -961,14 +963,30 @@ extension SourceKitLSPServer {
961963 // The below is a workaround for the vscode-swift extension since it cannot set client capabilities.
962964 // It passes "workspace/peekDocuments" through the `initializationOptions`.
963965 var clientCapabilities = req. capabilities
964- if case . dictionary( let initializationOptions) = req. initializationOptions,
965- let peekDocuments = initializationOptions [ " workspace/peekDocuments " ]
966- {
967- if case . dictionary( var experimentalCapabilities) = clientCapabilities. experimental {
968- experimentalCapabilities [ " workspace/peekDocuments " ] = peekDocuments
969- clientCapabilities. experimental = . dictionary( experimentalCapabilities)
970- } else {
971- clientCapabilities. experimental = . dictionary( [ " workspace/peekDocuments " : peekDocuments] )
966+ if case . dictionary( let initializationOptions) = req. initializationOptions {
967+ if let peekDocuments = initializationOptions [ " workspace/peekDocuments " ] {
968+ if case . dictionary( var experimentalCapabilities) = clientCapabilities. experimental {
969+ experimentalCapabilities [ " workspace/peekDocuments " ] = peekDocuments
970+ clientCapabilities. experimental = . dictionary( experimentalCapabilities)
971+ } else {
972+ clientCapabilities. experimental = . dictionary( [ " workspace/peekDocuments " : peekDocuments] )
973+ }
974+ }
975+
976+ // The client announces what CodeLenses it supports, and the LSP will only return
977+ // ones found in the supportedCommands dictionary.
978+ if let codeLens = initializationOptions [ " textDocument/codeLens " ] ,
979+ case let . dictionary( codeLensConfig) = codeLens,
980+ case let . dictionary( supportedCommands) = codeLensConfig [ " supportedCommands " ]
981+ {
982+ let commandMap = supportedCommands. compactMap { ( key, value) in
983+ if case let . string( clientCommand) = value {
984+ return ( SupportedCodeLensCommand ( rawValue: key) , clientCommand)
985+ }
986+ return nil
987+ }
988+
989+ clientCapabilities. textDocument? . codeLens? . supportedCommands = Dictionary ( uniqueKeysWithValues: commandMap)
972990 }
973991 }
974992
@@ -1100,6 +1118,7 @@ extension SourceKitLSPServer {
11001118 supportsCodeActions: true
11011119 )
11021120 ) ,
1121+ codeLensProvider: CodeLensOptions ( ) ,
11031122 documentFormattingProvider: . value( DocumentFormattingOptions ( workDoneProgress: false ) ) ,
11041123 renameProvider: . value( RenameOptions ( prepareProvider: true ) ) ,
11051124 colorProvider: . bool( true ) ,
@@ -1642,6 +1661,14 @@ extension SourceKitLSPServer {
16421661 return req. injectMetadata ( toResponse: response)
16431662 }
16441663
1664+ func codeLens(
1665+ _ req: CodeLensRequest ,
1666+ workspace: Workspace ,
1667+ languageService: LanguageService
1668+ ) async throws -> [ CodeLens ] {
1669+ return try await languageService. codeLens ( req)
1670+ }
1671+
16451672 func inlayHint(
16461673 _ req: InlayHintRequest ,
16471674 workspace: Workspace ,
0 commit comments