// Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include "jsonkeys.h" #include "lsptypes.h" #include "semantictokens.h" namespace LanguageServerProtocol { class LANGUAGESERVERPROTOCOL_EXPORT DynamicRegistrationCapabilities : public JsonObject { public: using JsonObject::JsonObject; std::optional dynamicRegistration() const { return optionalValue(dynamicRegistrationKey); } void setDynamicRegistration(bool dynamicRegistration) { insert(dynamicRegistrationKey, dynamicRegistration); } void clearDynamicRegistration() { remove(dynamicRegistrationKey); } }; class LANGUAGESERVERPROTOCOL_EXPORT FullSemanticTokenOptions : public JsonObject { public: using JsonObject::JsonObject; /** * The client will send the `textDocument/semanticTokens/full/delta` * request if the server provides a corresponding handler. */ std::optional delta() const { return optionalValue(deltaKey); } void setDelta(bool delta) { insert(deltaKey, delta); } void clearDelta() { remove(deltaKey); } }; class LANGUAGESERVERPROTOCOL_EXPORT SemanticTokensClientCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; class LANGUAGESERVERPROTOCOL_EXPORT Requests : public JsonObject { /** * Which requests the client supports and might send to the server * depending on the server's capability. Please note that clients might not * show semantic tokens or degrade some of the user experience if a range * or full request is advertised by the client but not provided by the * server. If for example the client capability `requests.full` and * `request.range` are both set to true but the server only provides a * range provider the client might not render a minimap correctly or might * even decide to not show any semantic tokens at all. */ public: using JsonObject::JsonObject; /** * The client will send the `textDocument/semanticTokens/range` request * if the server provides a corresponding handler. */ std::optional> range() const; void setRange(const std::variant &range); void clearRange() { remove(rangeKey); } /** * The client will send the `textDocument/semanticTokens/full` request * if the server provides a corresponding handler. */ std::optional> full() const; void setFull(const std::variant &full); void clearFull() { remove(fullKey); } }; Requests requests() const { return typedValue(requestsKey); } void setRequests(const Requests &requests) { insert(requestsKey, requests); } /// The token types that the client supports. QList tokenTypes() const { return array(tokenTypesKey); } void setTokenTypes(const QList &value) { insertArray(tokenTypesKey, value); } /// The token modifiers that the client supports. QList tokenModifiers() const { return array(tokenModifiersKey); } void setTokenModifiers(const QList &value) { insertArray(tokenModifiersKey, value); } /// The formats the clients supports. QList formats() const { return array(formatsKey); } void setFormats(const QList &value) { insertArray(formatsKey, value); } /// Whether the client supports tokens that can overlap each other. std::optional overlappingTokenSupport() const { return optionalValue(overlappingTokenSupportKey); } void setOverlappingTokenSupport(bool overlappingTokenSupport) { insert(overlappingTokenSupportKey, overlappingTokenSupport); } void clearOverlappingTokenSupport() { remove(overlappingTokenSupportKey); } /// Whether the client supports tokens that can span multiple lines. std::optional multiLineTokenSupport() const { return optionalValue(multiLineTokenSupportKey); } void setMultiLineTokenSupport(bool multiLineTokenSupport) { insert(multiLineTokenSupportKey, multiLineTokenSupport); } void clearMultiLineTokenSupport() { remove(multiLineTokenSupportKey); } bool isValid() const override; }; class LANGUAGESERVERPROTOCOL_EXPORT SymbolCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; class LANGUAGESERVERPROTOCOL_EXPORT SymbolKindCapabilities : public JsonObject { public: using JsonObject::JsonObject; /* * The symbol kind values the client supports. When this * property exists the client also guarantees that it will * handle values outside its set gracefully and falls back * to a default value when unknown. * * If this property is not present the client only supports * the symbol kinds from `File` to `Array` as defined in * the initial version of the protocol. */ std::optional> valueSet() const; void setValueSet(const QList &valueSet); void clearValueSet() { remove(valueSetKey); } }; // Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. std::optional symbolKind() const { return optionalValue(symbolKindKey); } void setSymbolKind(const SymbolKindCapabilities &symbolKind) { insert(symbolKindKey, symbolKind); } void clearSymbolKind() { remove(symbolKindKey); } std::optional hierarchicalDocumentSymbolSupport() const { return optionalValue(hierarchicalDocumentSymbolSupportKey); } void setHierarchicalDocumentSymbolSupport(bool hierarchicalDocumentSymbolSupport) { insert(hierarchicalDocumentSymbolSupportKey, hierarchicalDocumentSymbolSupport); } void clearHierachicalDocumentSymbolSupport() { remove(hierarchicalDocumentSymbolSupportKey); } }; class LANGUAGESERVERPROTOCOL_EXPORT TextDocumentClientCapabilities : public JsonObject { public: using JsonObject::JsonObject; class LANGUAGESERVERPROTOCOL_EXPORT SynchronizationCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; // The client supports sending will save notifications. std::optional willSave() const { return optionalValue(willSaveKey); } void setWillSave(bool willSave) { insert(willSaveKey, willSave); } void clearWillSave() { remove(willSaveKey); } /* * The client supports sending a will save request and * waits for a response providing text edits which will * be applied to the document before it is saved. */ std::optional willSaveWaitUntil() const { return optionalValue(willSaveWaitUntilKey); } void setWillSaveWaitUntil(bool willSaveWaitUntil) { insert(willSaveWaitUntilKey, willSaveWaitUntil); } void clearWillSaveWaitUntil() { remove(willSaveWaitUntilKey); } // The client supports did save notifications. std::optional didSave() const { return optionalValue(didSaveKey); } void setDidSave(bool didSave) { insert(didSaveKey, didSave); } void clearDidSave() { remove(didSaveKey); } }; std::optional synchronization() const { return optionalValue(synchronizationKey); } void setSynchronization(const SynchronizationCapabilities &synchronization) { insert(synchronizationKey, synchronization); } void clearSynchronization() { remove(synchronizationKey); } class LANGUAGESERVERPROTOCOL_EXPORT CompletionCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; class LANGUAGESERVERPROTOCOL_EXPORT CompletionItemCapbilities : public JsonObject { public: using JsonObject::JsonObject; /* * Client supports snippets as insert text. * * A snippet can define tab stops and placeholders with `$1`, `$2` * and `${3:foo}`. `$0` defines the final tab stop, it defaults to * the end of the snippet. Placeholders with equal identifiers are linked, * that is typing in one will update others too. */ std::optional snippetSupport() const { return optionalValue(snippetSupportKey); } void setSnippetSupport(bool snippetSupport) { insert(snippetSupportKey, snippetSupport); } void clearSnippetSupport() { remove(snippetSupportKey); } // Client supports commit characters on a completion item. std::optional commitCharacterSupport() const { return optionalValue(commitCharacterSupportKey); } void setCommitCharacterSupport(bool commitCharacterSupport) { insert(commitCharacterSupportKey, commitCharacterSupport); } void clearCommitCharacterSupport() { remove(commitCharacterSupportKey); } /* * Client supports the follow content formats for the documentation * property. The order describes the preferred format of the client. */ std::optional> documentationFormat() const; void setDocumentationFormat(const QList &documentationFormat); void clearDocumentationFormat() { remove(documentationFormatKey); } }; // The client supports the following `CompletionItem` specific capabilities. std::optional completionItem() const { return optionalValue(completionItemKey); } void setCompletionItem(const CompletionItemCapbilities &completionItem) { insert(completionItemKey, completionItem); } void clearCompletionItem() { remove(completionItemKey); } class LANGUAGESERVERPROTOCOL_EXPORT CompletionItemKindCapabilities : public JsonObject { public: CompletionItemKindCapabilities(); using JsonObject::JsonObject; /* * The completion item kind values the client supports. When this * property exists the client also guarantees that it will * handle values outside its set gracefully and falls back * to a default value when unknown. * * If this property is not present the client only supports * the completion items kinds from `Text` to `Reference` as defined in * the initial version of the protocol. */ std::optional> valueSet() const; void setValueSet(const QList &valueSet); void clearValueSet() { remove(valueSetKey); } }; std::optional completionItemKind() const { return optionalValue(completionItemKindKey); } void setCompletionItemKind(const CompletionItemKindCapabilities &completionItemKind) { insert(completionItemKindKey, completionItemKind); } void clearCompletionItemKind() { remove(completionItemKindKey); } /* * The client supports to send additional context information for a * `textDocument/completion` request. */ std::optional contextSupport() const { return optionalValue(contextSupportKey); } void setContextSupport(bool contextSupport) { insert(contextSupportKey, contextSupport); } void clearContextSupport() { remove(contextSupportKey); } }; // Capabilities specific to the `textDocument/completion` std::optional completion() const { return optionalValue(completionKey); } void setCompletion(const CompletionCapabilities &completion) { insert(completionKey, completion); } void clearCompletion() { remove(completionKey); } class LANGUAGESERVERPROTOCOL_EXPORT HoverCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; /* * Client supports the follow content formats for the content * property. The order describes the preferred format of the client. */ std::optional> contentFormat() const; void setContentFormat(const QList &contentFormat); void clearContentFormat() { remove(contentFormatKey); } }; std::optional hover() const { return optionalValue(hoverKey); } void setHover(const HoverCapabilities &hover) { insert(hoverKey, hover); } void clearHover() { remove(hoverKey); } class LANGUAGESERVERPROTOCOL_EXPORT SignatureHelpCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; class LANGUAGESERVERPROTOCOL_EXPORT SignatureInformationCapabilities : public JsonObject { public: using JsonObject::JsonObject; /* * Client supports the follow content formats for the documentation * property. The order describes the preferred format of the client. */ std::optional> documentationFormat() const; void setDocumentationFormat(const QList &documentationFormat); void clearDocumentationFormat() { remove(documentationFormatKey); } std::optional activeParameterSupport() const { return optionalValue(activeParameterSupportKey); } void setActiveParameterSupport(bool activeParameterSupport) { insert(activeParameterSupportKey, activeParameterSupport); } void clearActiveParameterSupport() { remove(activeParameterSupportKey); } }; // The client supports the following `SignatureInformation` specific properties. std::optional signatureInformation() const { return optionalValue(signatureInformationKey); } void setSignatureInformation(const SignatureInformationCapabilities &signatureInformation) { insert(signatureInformationKey, signatureInformation); } void clearSignatureInformation() { remove(signatureInformationKey); } }; // Capabilities specific to the `textDocument/signatureHelp` std::optional signatureHelp() const { return optionalValue(signatureHelpKey); } void setSignatureHelp(const SignatureHelpCapabilities &signatureHelp) { insert(signatureHelpKey, signatureHelp); } void clearSignatureHelp() { remove(signatureHelpKey); } // Whether references supports dynamic registration. std::optional references() const { return optionalValue(referencesKey); } void setReferences(const DynamicRegistrationCapabilities &references) { insert(referencesKey, references); } void clearReferences() { remove(referencesKey); } // Whether document highlight supports dynamic registration. std::optional documentHighlight() const { return optionalValue(documentHighlightKey); } void setDocumentHighlight(const DynamicRegistrationCapabilities &documentHighlight) { insert(documentHighlightKey, documentHighlight); } void clearDocumentHighlight() { remove(documentHighlightKey); } // Capabilities specific to the `textDocument/documentSymbol` std::optional documentSymbol() const { return optionalValue(documentSymbolKey); } void setDocumentSymbol(const SymbolCapabilities &documentSymbol) { insert(documentSymbolKey, documentSymbol); } void clearDocumentSymbol() { remove(documentSymbolKey); } // Whether formatting supports dynamic registration. std::optional formatting() const { return optionalValue(formattingKey); } void setFormatting(const DynamicRegistrationCapabilities &formatting) { insert(formattingKey, formatting); } void clearFormatting() { remove(formattingKey); } // Whether range formatting supports dynamic registration. std::optional rangeFormatting() const { return optionalValue(rangeFormattingKey); } void setRangeFormatting(const DynamicRegistrationCapabilities &rangeFormatting) { insert(rangeFormattingKey, rangeFormatting); } void clearRangeFormatting() { remove(rangeFormattingKey); } // Whether on type formatting supports dynamic registration. std::optional onTypeFormatting() const { return optionalValue(onTypeFormattingKey); } void setOnTypeFormatting(const DynamicRegistrationCapabilities &onTypeFormatting) { insert(onTypeFormattingKey, onTypeFormatting); } void clearOnTypeFormatting() { remove(onTypeFormattingKey); } // Whether definition supports dynamic registration. std::optional definition() const { return optionalValue(definitionKey); } void setDefinition(const DynamicRegistrationCapabilities &definition) { insert(definitionKey, definition); } void clearDefinition() { remove(definitionKey); } /* * Whether typeDefinition supports dynamic registration. If this is set to `true` * the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)` * return value for the corresponding server capability as well. */ std::optional typeDefinition() const { return optionalValue(typeDefinitionKey); } void setTypeDefinition(const DynamicRegistrationCapabilities &typeDefinition) { insert(typeDefinitionKey, typeDefinition); } void clearTypeDefinition() { remove(typeDefinitionKey); } /* * Whether implementation supports dynamic registration. If this is set to `true` * the client supports the new `(TextDocumentRegistrationOptions & StaticRegistrationOptions)` * return value for the corresponding server capability as well. */ std::optional implementation() const { return optionalValue(implementationKey); } void setImplementation(const DynamicRegistrationCapabilities &implementation) { insert(implementationKey, implementation); } void clearImplementation() { remove(implementationKey); } class LANGUAGESERVERPROTOCOL_EXPORT CodeActionCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; class LANGUAGESERVERPROTOCOL_EXPORT CodeActionLiteralSupport : public JsonObject { public: using JsonObject::JsonObject; class LANGUAGESERVERPROTOCOL_EXPORT CodeActionKind : public JsonObject { public: using JsonObject::JsonObject; CodeActionKind() : CodeActionKind(QList()) {} explicit CodeActionKind(const QList &kinds) { setValueSet(kinds); } QList valueSet() const { return array(valueSetKey); } void setValueSet(const QList &valueSet) { insertArray(valueSetKey, valueSet); } bool isValid() const override { return contains(valueSetKey); } }; CodeActionKind codeActionKind() const { return typedValue(codeActionKindKey); } void setCodeActionKind(const CodeActionKind &codeActionKind) { insert(codeActionKindKey, codeActionKind); } bool isValid() const override { return contains(codeActionKindKey); } }; std::optional codeActionLiteralSupport() const { return optionalValue(codeActionLiteralSupportKey); } void setCodeActionLiteralSupport(const CodeActionLiteralSupport &codeActionLiteralSupport) { insert(codeActionLiteralSupportKey, codeActionLiteralSupport); } void clearCodeActionLiteralSupport() { remove(codeActionLiteralSupportKey); } }; // Whether code action supports dynamic registration. std::optional codeAction() const { return optionalValue(codeActionKey); } void setCodeAction(const CodeActionCapabilities &codeAction) { insert(codeActionKey, codeAction); } void clearCodeAction() { remove(codeActionKey); } // Whether code lens supports dynamic registration. std::optional codeLens() const { return optionalValue(codeLensKey); } void setCodeLens(const DynamicRegistrationCapabilities &codeLens) { insert(codeLensKey, codeLens); } void clearCodeLens() { remove(codeLensKey); } // Whether document link supports dynamic registration. std::optional documentLink() const { return optionalValue(documentLinkKey); } void setDocumentLink(const DynamicRegistrationCapabilities &documentLink) { insert(documentLinkKey, documentLink); } void clearDocumentLink() { remove(documentLinkKey); } /* * Whether colorProvider supports dynamic registration. If this is set to `true` * the client supports the new `(ColorProviderOptions & TextDocumentRegistrationOptions & StaticRegistrationOptions)` * return value for the corresponding server capability as well. */ std::optional colorProvider() const { return optionalValue(colorProviderKey); } void setColorProvider(const DynamicRegistrationCapabilities &colorProvider) { insert(colorProviderKey, colorProvider); } void clearColorProvider() { remove(colorProviderKey); } class LANGUAGESERVERPROTOCOL_EXPORT RenameClientCapabilities : public DynamicRegistrationCapabilities { public: using DynamicRegistrationCapabilities::DynamicRegistrationCapabilities; /** * Client supports testing for validity of rename operations * before execution. * * @since version 3.12.0 */ std::optional prepareSupport() const { return optionalValue(prepareSupportKey); } void setPrepareSupport(bool prepareSupport) { insert(prepareSupportKey, prepareSupport); } void clearPrepareSupport() { remove(prepareSupportKey); } }; // Whether rename supports dynamic registration. std::optional rename() const { return optionalValue(renameKey); } void setRename(const RenameClientCapabilities &rename) { insert(renameKey, rename); } void clearRename() { remove(renameKey); } std::optional semanticTokens() const; void setSemanticTokens(const SemanticTokensClientCapabilities &semanticTokens); void clearSemanticTokens() { remove(semanticTokensKey); } std::optional callHierarchy() const { return optionalValue(callHierarchyKey); } void setCallHierarchy(const DynamicRegistrationCapabilities &callHierarchy) { insert(callHierarchyKey, callHierarchy); } void clearCallHierarchy() { remove(callHierarchyKey); } }; class LANGUAGESERVERPROTOCOL_EXPORT SemanticTokensWorkspaceClientCapabilities : public JsonObject { public: using JsonObject::JsonObject; /** * Whether the client implementation supports a refresh request sent from * the server to the client. * * Note that this event is global and will force the client to refresh all * semantic tokens currently shown. It should be used with absolute care * and is useful for situation where a server for example detect a project * wide change that requires such a calculation. */ std::optional refreshSupport() const { return optionalValue(refreshSupportKey); } void setRefreshSupport(bool refreshSupport) { insert(refreshSupportKey, refreshSupport); } void clearRefreshSupport() { remove(refreshSupportKey); } }; class LANGUAGESERVERPROTOCOL_EXPORT WorkspaceClientCapabilities : public JsonObject { public: WorkspaceClientCapabilities(); using JsonObject::JsonObject; /* * The client supports applying batch edits to the workspace by supporting the request * 'workspace/applyEdit' */ std::optional applyEdit() const { return optionalValue(applyEditKey); } void setApplyEdit(bool applyEdit) { insert(applyEditKey, applyEdit); } void clearApplyEdit() { remove(applyEditKey); } class LANGUAGESERVERPROTOCOL_EXPORT WorkspaceEditCapabilities : public JsonObject { public: using JsonObject::JsonObject; // The client supports versioned document changes in `WorkspaceEdit`s std::optional documentChanges() const { return optionalValue(documentChangesKey); } void setDocumentChanges(bool documentChanges) { insert(documentChangesKey, documentChanges); } void clearDocumentChanges() { remove(documentChangesKey); } }; // Capabilities specific to `WorkspaceEdit`s std::optional workspaceEdit() const { return optionalValue(workspaceEditKey); } void setWorkspaceEdit(const WorkspaceEditCapabilities &workspaceEdit) { insert(workspaceEditKey, workspaceEdit); } void clearWorkspaceEdit() { remove(workspaceEditKey); } // Capabilities specific to the `workspace/didChangeConfiguration` notification. std::optional didChangeConfiguration() const { return optionalValue(didChangeConfigurationKey); } void setDidChangeConfiguration(const DynamicRegistrationCapabilities &didChangeConfiguration) { insert(didChangeConfigurationKey, didChangeConfiguration); } void clearDidChangeConfiguration() { remove(didChangeConfigurationKey); } // Capabilities specific to the `workspace/didChangeWatchedFiles` notification. std::optional didChangeWatchedFiles() const { return optionalValue(didChangeWatchedFilesKey); } void setDidChangeWatchedFiles(const DynamicRegistrationCapabilities &didChangeWatchedFiles) { insert(didChangeWatchedFilesKey, didChangeWatchedFiles); } void clearDidChangeWatchedFiles() { remove(didChangeWatchedFilesKey); } // Specific capabilities for the `SymbolKind` in the `workspace/symbol` request. std::optional symbol() const { return optionalValue(symbolKey); } void setSymbol(const SymbolCapabilities &symbol) { insert(symbolKey, symbol); } void clearSymbol() { remove(symbolKey); } // Capabilities specific to the `workspace/executeCommand` request. std::optional executeCommand() const { return optionalValue(executeCommandKey); } void setExecuteCommand(const DynamicRegistrationCapabilities &executeCommand) { insert(executeCommandKey, executeCommand); } void clearExecuteCommand() { remove(executeCommandKey); } // The client has support for workspace folders. Since 3.6.0 std::optional workspaceFolders() const { return optionalValue(workspaceFoldersKey); } void setWorkspaceFolders(bool workspaceFolders) { insert(workspaceFoldersKey, workspaceFolders); } void clearWorkspaceFolders() { remove(workspaceFoldersKey); } // The client supports `workspace/configuration` requests. Since 3.6.0 std::optional configuration() const { return optionalValue(configurationKey); } void setConfiguration(bool configuration) { insert(configurationKey, configuration); } void clearConfiguration() { remove(configurationKey); } std::optional semanticTokens() const { return optionalValue(semanticTokensKey); } void setSemanticTokens(const SemanticTokensWorkspaceClientCapabilities &semanticTokens) { insert(semanticTokensKey, semanticTokens); } void clearSemanticTokens() { remove(semanticTokensKey); } }; class WindowClientClientCapabilities : public JsonObject { public: using JsonObject::JsonObject; /** * Whether client supports handling progress notifications. * If set, servers are allowed to report in `workDoneProgress` property * in the request specific server capabilities. * */ std::optional workDoneProgress() const { return optionalValue(workDoneProgressKey); } void setWorkDoneProgress(bool workDoneProgress) { insert(workDoneProgressKey, workDoneProgress); } void clearWorkDoneProgress() { remove(workDoneProgressKey); } private: constexpr static const char16_t workDoneProgressKey[] = u"workDoneProgress"; }; class LANGUAGESERVERPROTOCOL_EXPORT ClientCapabilities : public JsonObject { public: using JsonObject::JsonObject; // Workspace specific client capabilities. std::optional workspace() const { return optionalValue(workspaceKey); } void setWorkspace(const WorkspaceClientCapabilities &workspace) { insert(workspaceKey, workspace); } void clearWorkspace() { remove(workspaceKey); } // Text document specific client capabilities. std::optional textDocument() const { return optionalValue(textDocumentKey); } void setTextDocument(const TextDocumentClientCapabilities &textDocument) { insert(textDocumentKey, textDocument); } void clearTextDocument() { remove(textDocumentKey); } // Window specific client capabilities. std::optional window() const { return optionalValue(windowKey); } void setWindow(const WindowClientClientCapabilities &window) { insert(windowKey, window); } void clearWindow() { remove(windowKey); } // Experimental client capabilities. QJsonValue experimental() const { return value(experimentalKey); } void setExperimental(const QJsonValue &experimental) { insert(experimentalKey, experimental); } void clearExperimental() { remove(experimentalKey); } }; } // namespace LanguageServerProtocol