Commit 876cb4ce authored by Mark Nauwelaerts's avatar Mark Nauwelaerts

lspclient: sprinkle some clang-format

parent 231d52d6
This diff is collapsed.
......@@ -31,20 +31,18 @@
#include <KTextEditor/CodeCompletionModel>
#include <KTextEditor/CodeCompletionModelControllerInterface>
class LSPClientCompletion : public KTextEditor::CodeCompletionModel, public KTextEditor::CodeCompletionModelControllerInterface
class LSPClientCompletion : public KTextEditor::CodeCompletionModel,
public KTextEditor::CodeCompletionModelControllerInterface
{
Q_OBJECT
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
public:
// implementation factory method
static LSPClientCompletion* new_(QSharedPointer<LSPClientServerManager> manager);
static LSPClientCompletion *new_(QSharedPointer<LSPClientServerManager> manager);
LSPClientCompletion(QObject * parent)
: KTextEditor::CodeCompletionModel(parent)
{}
LSPClientCompletion(QObject *parent) : KTextEditor::CodeCompletionModel(parent) {}
virtual void setServer(QSharedPointer<LSPClientServer> server) = 0;
virtual void setSelectedDocumentation(bool) = 0;
......
......@@ -82,16 +82,15 @@ LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugi
reset();
for (const auto & cb : {m_symbolDetails, m_symbolExpand, m_symbolSort, m_symbolTree,
m_complDoc, m_refDeclaration, m_diagnostics, m_diagnosticsMark,
m_onTypeFormatting, m_incrementalSync})
for (const auto &cb : { m_symbolDetails, m_symbolExpand, m_symbolSort, m_symbolTree, m_complDoc,
m_refDeclaration, m_diagnostics, m_diagnosticsMark, m_onTypeFormatting,
m_incrementalSync })
connect(cb, &QCheckBox::toggled, this, &LSPClientConfigPage::changed);
connect(m_configPath, &KUrlRequester::textChanged, this, &LSPClientConfigPage::changed);
connect(m_configPath, &KUrlRequester::urlSelected, this, &LSPClientConfigPage::changed);
// custom control logic
auto h = [this] ()
{
auto h = [this]() {
bool enabled = m_diagnostics->isChecked();
m_diagnosticsHighlight->setEnabled(enabled);
m_diagnosticsMark->setEnabled(enabled);
......
......@@ -38,7 +38,7 @@ class LSPClientConfigPage : public KTextEditor::ConfigPage
{
Q_OBJECT
public:
public:
explicit LSPClientConfigPage(QWidget *parent = nullptr, LSPClientPlugin *plugin = nullptr);
~LSPClientConfigPage() override {};
......@@ -46,23 +46,23 @@ class LSPClientConfigPage : public KTextEditor::ConfigPage
QString fullName() const override;
QIcon icon() const override;
public Q_SLOTS:
public Q_SLOTS:
void apply() override;
void defaults() override;
void reset() override;
private:
QCheckBox* m_symbolDetails;
QCheckBox* m_symbolExpand;
QCheckBox* m_symbolTree;
QCheckBox* m_symbolSort;
QCheckBox* m_complDoc;
QCheckBox* m_refDeclaration;
QCheckBox* m_diagnostics;
QCheckBox* m_diagnosticsHighlight;
QCheckBox* m_diagnosticsMark;
QCheckBox* m_onTypeFormatting;
QCheckBox* m_incrementalSync;
private:
QCheckBox *m_symbolDetails;
QCheckBox *m_symbolExpand;
QCheckBox *m_symbolTree;
QCheckBox *m_symbolSort;
QCheckBox *m_complDoc;
QCheckBox *m_refDeclaration;
QCheckBox *m_diagnostics;
QCheckBox *m_diagnosticsHighlight;
QCheckBox *m_diagnosticsMark;
QCheckBox *m_onTypeFormatting;
QCheckBox *m_incrementalSync;
KUrlRequester *m_configPath;
LSPClientPlugin *m_plugin;
......
......@@ -49,8 +49,8 @@ static const QString CONFIG_DIAGNOSTICS_HIGHLIGHT { QStringLiteral("DiagnosticsH
static const QString CONFIG_DIAGNOSTICS_MARK { QStringLiteral("DiagnosticsMark") };
static const QString CONFIG_SERVER_CONFIG { QStringLiteral("ServerConfiguration") };
K_PLUGIN_FACTORY_WITH_JSON(LSPClientPluginFactory, "lspclientplugin.json", registerPlugin<LSPClientPlugin>();)
K_PLUGIN_FACTORY_WITH_JSON(LSPClientPluginFactory, "lspclientplugin.json",
registerPlugin<LSPClientPlugin>();)
LSPClientPlugin::LSPClientPlugin(QObject *parent, const QList<QVariant> &)
: KTextEditor::Plugin(parent)
......@@ -61,17 +61,17 @@ LSPClientPlugin::LSPClientPlugin(QObject *parent, const QList<QVariant> &)
*/
m_debugMode = (qgetenv("LSPCLIENT_DEBUG") == QByteArray("1"));
if (!m_debugMode) {
QLoggingCategory::setFilterRules(QStringLiteral("katelspclientplugin.debug=false\nkatelspclientplugin.info=false"));
QLoggingCategory::setFilterRules(
QStringLiteral("katelspclientplugin.debug=false\nkatelspclientplugin.info=false"));
} else {
QLoggingCategory::setFilterRules(QStringLiteral("katelspclientplugin.debug=true\nkatelspclientplugin.info=true"));
QLoggingCategory::setFilterRules(
QStringLiteral("katelspclientplugin.debug=true\nkatelspclientplugin.info=true"));
}
readConfig();
}
LSPClientPlugin::~LSPClientPlugin()
{
}
LSPClientPlugin::~LSPClientPlugin() {}
QObject *LSPClientPlugin::createView(KTextEditor::MainWindow *mainWindow)
{
......
......@@ -35,8 +35,9 @@ class LSPClientPlugin : public KTextEditor::Plugin
{
Q_OBJECT
public:
explicit LSPClientPlugin(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>());
public:
explicit LSPClientPlugin(QObject *parent = nullptr,
const QList<QVariant> & = QList<QVariant>());
~LSPClientPlugin() override;
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
......@@ -65,7 +66,7 @@ class LSPClientPlugin : public KTextEditor::Plugin
bool m_debugMode = false;
private:
Q_SIGNALS:
Q_SIGNALS:
// signal settings update
void update() const;
};
......
This diff is collapsed.
......@@ -30,16 +30,14 @@
class LSPClientPlugin;
namespace KTextEditor {
class MainWindow;
class MainWindow;
}
class LSPClientPluginView
{
public:
// only needs a factory; no other public interface
static QObject*
new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin);
static QObject *new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin);
};
#endif
......@@ -41,8 +41,7 @@
// Moreover, to avoid introducing a custom 'optional' type, absence of an optional
// part/member is usually signalled by some 'invalid' marker (empty, negative).
enum class LSPErrorCode
{
enum class LSPErrorCode {
// Defined by JSON RPC
ParseError = -32700,
InvalidRequest = -32600,
......@@ -59,31 +58,24 @@ enum class LSPErrorCode
ContentModified = -32801
};
enum class LSPDocumentSyncKind
{
None = 0,
Full = 1,
Incremental = 2
};
enum class LSPDocumentSyncKind { None = 0, Full = 1, Incremental = 2 };
struct LSPCompletionOptions
{
struct LSPCompletionOptions {
bool provider = false;
bool resolveProvider = false;
QVector<QChar> triggerCharacters;
};
struct LSPSignatureHelpOptions
{
struct LSPSignatureHelpOptions {
bool provider = false;
QVector<QChar> triggerCharacters;
};
// ensure distinct type
struct LSPDocumentOnTypeFormattingOptions : public LSPSignatureHelpOptions {};
struct LSPDocumentOnTypeFormattingOptions : public LSPSignatureHelpOptions {
};
struct LSPServerCapabilities
{
struct LSPServerCapabilities {
LSPDocumentSyncKind textDocumentSync = LSPDocumentSyncKind::None;
bool hoverProvider = false;
LSPCompletionOptions completionProvider;
......@@ -102,15 +94,9 @@ struct LSPServerCapabilities
bool codeActionProvider = false;
};
enum class LSPMarkupKind
{
None = 0,
PlainText = 1,
MarkDown = 2
};
enum class LSPMarkupKind { None = 0, PlainText = 1, MarkDown = 2 };
struct LSPMarkupContent
{
struct LSPMarkupContent {
LSPMarkupKind kind = LSPMarkupKind::None;
QString value;
};
......@@ -129,34 +115,26 @@ using LSPPosition = KTextEditor::Cursor;
*/
using LSPRange = KTextEditor::Range;
struct LSPLocation
{
struct LSPLocation {
QUrl uri;
LSPRange range;
};
struct LSPTextDocumentContentChangeEvent
{
struct LSPTextDocumentContentChangeEvent {
LSPRange range;
QString text;
};
enum class LSPDocumentHighlightKind
{
Text = 1,
Read = 2,
Write = 3
};
enum class LSPDocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
struct LSPDocumentHighlight
{
struct LSPDocumentHighlight {
LSPRange range;
LSPDocumentHighlightKind kind;
};
struct LSPHover
{
// vector for contents to support all three variants: MarkedString | MarkedString[] | MarkupContent
struct LSPHover {
// vector for contents to support all three variants:
// MarkedString | MarkedString[] | MarkupContent
// vector variant is still in use e.g. by Rust rls
QVector<LSPMarkupContent> contents;
LSPRange range;
......@@ -183,12 +161,12 @@ enum class LSPSymbolKind {
Array = 18,
};
struct LSPSymbolInformation
{
LSPSymbolInformation(const QString & _name, LSPSymbolKind _kind,
LSPRange _range, const QString & _detail)
struct LSPSymbolInformation {
LSPSymbolInformation(const QString &_name, LSPSymbolKind _kind, LSPRange _range,
const QString &_detail)
: name(_name), detail(_detail), kind(_kind), range(_range)
{}
{
}
QString name;
QString detail;
LSPSymbolKind kind;
......@@ -196,8 +174,7 @@ struct LSPSymbolInformation
QList<LSPSymbolInformation> children;
};
enum class LSPCompletionItemKind
{
enum class LSPCompletionItemKind {
Text = 1,
Method = 2,
Function = 3,
......@@ -225,8 +202,7 @@ enum class LSPCompletionItemKind
TypeParameter = 25,
};
struct LSPCompletionItem
{
struct LSPCompletionItem {
QString label;
LSPCompletionItemKind kind;
QString detail;
......@@ -235,44 +211,38 @@ struct LSPCompletionItem
QString insertText;
};
struct LSPParameterInformation
{
struct LSPParameterInformation {
// offsets into overall signature label
// (-1 if invalid)
int start;
int end;
};
struct LSPSignatureInformation
{
struct LSPSignatureInformation {
QString label;
LSPMarkupContent documentation;
QList<LSPParameterInformation> parameters;
};
struct LSPSignatureHelp
{
struct LSPSignatureHelp {
QList<LSPSignatureInformation> signatures;
int activeSignature;
int activeParameter;
};
struct LSPFormattingOptions
{
struct LSPFormattingOptions {
int tabSize;
bool insertSpaces;
// additional fields
QJsonObject extra;
};
struct LSPTextEdit
{
struct LSPTextEdit {
LSPRange range;
QString newText;
};
enum class LSPDiagnosticSeverity
{
enum class LSPDiagnosticSeverity {
Unknown = 0,
Error = 1,
Warning = 2,
......@@ -280,15 +250,13 @@ enum class LSPDiagnosticSeverity
Hint = 4,
};
struct LSPDiagnosticRelatedInformation
{
struct LSPDiagnosticRelatedInformation {
// empty url / invalid range when absent
LSPLocation location;
QString message;
};
struct LSPDiagnostic
{
struct LSPDiagnostic {
LSPRange range;
LSPDiagnosticSeverity severity;
QString code;
......@@ -297,28 +265,24 @@ struct LSPDiagnostic
LSPDiagnosticRelatedInformation relatedInformation;
};
struct LSPPublishDiagnosticsParams
{
struct LSPPublishDiagnosticsParams {
QUrl uri;
QList<LSPDiagnostic> diagnostics;
};
struct LSPCommand
{
struct LSPCommand {
QString title;
QString command;
// pretty opaque
QJsonArray arguments;
};
struct LSPWorkspaceEdit
{
struct LSPWorkspaceEdit {
// supported part for now
QHash<QUrl, QList<LSPTextEdit>> changes;
};
struct LSPCodeAction
{
struct LSPCodeAction {
QString title;
QString kind;
QList<LSPDiagnostic> diagnostics;
......@@ -326,14 +290,12 @@ struct LSPCodeAction
LSPCommand command;
};
struct LSPApplyWorkspaceEditParams
{
struct LSPApplyWorkspaceEditParams {
QString label;
LSPWorkspaceEdit edit;
};
struct LSPApplyWorkspaceEditResponse
{
struct LSPApplyWorkspaceEditResponse {
bool applied;
QString failureReason;
};
......
This diff is collapsed.
......@@ -37,35 +37,30 @@
#include <functional>
namespace utils
{
namespace utils {
// template helper
// function bind helpers
template<typename R, typename T, typename Tp, typename... Args>
inline std::function<R(Args ...)>
mem_fun(R (T::*pm)(Args ...), Tp object)
inline std::function<R(Args...)> mem_fun(R (T::*pm)(Args...), Tp object)
{
return [object, pm](Args... args) {
return (object->*pm)(std::forward<Args>(args)...);
};
return [object, pm](Args... args) { return (object->*pm)(std::forward<Args>(args)...); };
}
template<typename R, typename T, typename Tp, typename... Args>
inline std::function<R(Args...)>
mem_fun(R (T::*pm)(Args ...) const, Tp object)
inline std::function<R(Args...)> mem_fun(R (T::*pm)(Args...) const, Tp object)
{
return [object, pm](Args... args) {
return (object->*pm)(std::forward<Args>(args)...);
};
return [object, pm](Args... args) { return (object->*pm)(std::forward<Args>(args)...); };
}
// prevent argument deduction
template<typename T> struct identity { typedef T type; };
template<typename T>
struct identity {
typedef T type;
};
} // namespace utils
static const int TIMEOUT_SHUTDOWN = 200;
template<typename T>
......@@ -87,13 +82,7 @@ class LSPClientServer : public QObject
Q_OBJECT
public:
enum class State
{
None,
Started,
Running,
Shutdown
};
enum class State { None, Started, Running, Shutdown };
class LSPClientServerPrivate;
class RequestHandle
......@@ -101,8 +90,9 @@ public:
friend class LSPClientServerPrivate;
QPointer<LSPClientServer> m_server;
int m_id = -1;
public:
RequestHandle& cancel()
RequestHandle &cancel()
{
if (m_server)
m_server->cancel(m_id);
......@@ -110,8 +100,8 @@ public:
}
};
LSPClientServer(const QStringList & server, const QUrl & root,
const QJsonValue & init = QJsonValue());
LSPClientServer(const QStringList &server, const QUrl &root,
const QJsonValue &init = QJsonValue());
~LSPClientServer();
// server management
......@@ -123,65 +113,70 @@ public:
int cancel(int id);
// properties
const QStringList& cmdline() const;
const QStringList &cmdline() const;
State state() const;
Q_SIGNAL void stateChanged(LSPClientServer * server);
Q_SIGNAL void stateChanged(LSPClientServer *server);
const LSPServerCapabilities& capabilities() const;
const LSPServerCapabilities &capabilities() const;
// language
RequestHandle documentSymbols(const QUrl & document, const QObject *context,
const DocumentSymbolsReplyHandler & h);
RequestHandle documentDefinition(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentDefinitionReplyHandler & h);
RequestHandle documentDeclaration(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentDefinitionReplyHandler & h);
RequestHandle documentHighlight(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHighlightReplyHandler & h);
RequestHandle documentHover(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentHoverReplyHandler & h);
RequestHandle documentReferences(const QUrl & document, const LSPPosition & pos, bool decl,
const QObject *context, const DocumentDefinitionReplyHandler & h);
RequestHandle documentCompletion(const QUrl & document, const LSPPosition & pos,
const QObject *context, const DocumentCompletionReplyHandler & h);
RequestHandle signatureHelp(const QUrl & document, const LSPPosition & pos,
const QObject *context, const SignatureHelpReplyHandler & h);
RequestHandle documentFormatting(const QUrl & document, const LSPFormattingOptions & options,
const QObject *context, const FormattingReplyHandler & h);
RequestHandle documentRangeFormatting(const QUrl & document, const LSPRange & range,
const LSPFormattingOptions & options,
const QObject *context, const FormattingReplyHandler & h);
RequestHandle documentOnTypeFormatting(const QUrl & document, const LSPPosition & pos,
QChar lastChar, const LSPFormattingOptions & options,
const QObject *context, const FormattingReplyHandler & h);
RequestHandle documentRename(const QUrl & document, const LSPPosition & pos,
const QString newName,
const QObject *context, const WorkspaceEditReplyHandler & h);
RequestHandle documentCodeAction(const QUrl & document, const LSPRange & range,
const QList<QString> & kinds, QList<LSPDiagnostic> diagnostics,
const QObject *context, const CodeActionReplyHandler & h);
void executeCommand(const QString & command, const QJsonValue & args);
RequestHandle documentSymbols(const QUrl &document, const QObject *context,
const DocumentSymbolsReplyHandler &h);
RequestHandle documentDefinition(const QUrl &document, const LSPPosition &pos,
const QObject *context,
const DocumentDefinitionReplyHandler &h);
RequestHandle documentDeclaration(const QUrl &document, const LSPPosition &pos,
const QObject *context,
const DocumentDefinitionReplyHandler &h);
RequestHandle documentHighlight(const QUrl &document, const LSPPosition &pos,
const QObject *context, const DocumentHighlightReplyHandler &h);
RequestHandle documentHover(const QUrl &document, const LSPPosition &pos,
const QObject *context, const DocumentHoverReplyHandler &h);
RequestHandle documentReferences(const QUrl &document, const LSPPosition &pos, bool decl,
const QObject *context,
const DocumentDefinitionReplyHandler &h);
RequestHandle documentCompletion(const QUrl &document, const LSPPosition &pos,
const QObject *context,
const DocumentCompletionReplyHandler &h);
RequestHandle signatureHelp(const QUrl &document, const LSPPosition &pos,
const QObject *context, const SignatureHelpReplyHandler &h);
RequestHandle documentFormatting(const QUrl &document, const LSPFormattingOptions &options,
const QObject *context, const FormattingReplyHandler &h);
RequestHandle documentRangeFormatting(const QUrl &document, const LSPRange &range,
const LSPFormattingOptions &options,
const QObject *context, const FormattingReplyHandler &h);
RequestHandle documentOnTypeFormatting(const QUrl &document, const LSPPosition &pos,
QChar lastChar, const LSPFormattingOptions &options,
const QObject *context, const FormattingReplyHandler &h);
RequestHandle documentRename(const QUrl &document, const LSPPosition &pos,
const QString newName, const QObject *context,
const WorkspaceEditReplyHandler &h);
RequestHandle documentCodeAction(const QUrl &document, const LSPRange &range,
const QList<QString> &kinds, QList<LSPDiagnostic> diagnostics,
const QObject *context, const CodeActionReplyHandler &h);
void executeCommand(const QString &command, const QJsonValue &args);
// sync
void didOpen(const QUrl & document, int version, const QString & langId, const QString & text);
void didOpen(const QUrl &document, int version, const QString &langId, const QString &text);
// only 1 of text or changes should be non-empty and is considered
void didChange(const QUrl & document, int version, const QString & text,
const QList<LSPTextDocumentContentChangeEvent> & changes = {});
void didSave(const QUrl & document, const QString & text);
void didClose(const QUrl & document);
void didChange(const QUrl &document, int version, const QString &text,
const QList<LSPTextDocumentContentChangeEvent> &changes = {});
void didSave(const QUrl &document, const QString &text);
void didClose(const QUrl &document);
// notifcation = signal
Q_SIGNALS:
void publishDiagnostics(const LSPPublishDiagnosticsParams & );
void publishDiagnostics(const LSPPublishDiagnosticsParams &);
// request = signal
void applyEdit(const LSPApplyWorkspaceEditParams &req, const ApplyEditReplyHandler &h, bool &handled);
void applyEdit(const LSPApplyWorkspaceEditParams &req, const ApplyEditReplyHandler &h,
bool &handled);
private:
// pimpl data holder
LSPClientServerPrivate * const d;
LSPClientServerPrivate *const d;
};
#endif
This diff is collapsed.
......@@ -31,10 +31,10 @@
#include <QSharedPointer>
namespace KTextEditor {
class MainWindow;
class Document;
class View;
class MovingInterface;
class MainWindow;
class Document;
class View;
class MovingInterface;
}
class LSPClientRevisionSnapshot;
......@@ -54,14 +54,14 @@ class LSPClientServerManager : public QObject
public:
// factory method; private implementation by interface
static QSharedPointer<LSPClientServerManager>
new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin);
static QSharedPointer<LSPClientServerManager> new_(LSPClientPlugin *plugin,
KTextEditor::MainWindow *mainWin);
virtual QSharedPointer<LSPClientServer>
findServer(KTextEditor::Document *document, bool updatedoc = true) = 0;
virtual QSharedPointer<LSPClientServer> findServer(KTextEditor::Document *document,
bool updatedoc = true) = 0;
virtual QSharedPointer<LSPClientServer>
findServer(KTextEditor::View *view, bool updatedoc = true) = 0;
virtual QSharedPointer<LSPClientServer> findServer(KTextEditor::View *view,
bool updatedoc = true) = 0;
virtual void update(KTextEditor::Document *doc, bool force) = 0;
......@@ -74,7 +74,7 @@ public:
// lock all relevant documents' current revision and sync that to server
// locks are released when returned snapshot is delete'd
virtual LSPClientRevisionSnapshot* snapshot(LSPClientServer *server) = 0;
virtual LSPClientRevisionSnapshot *snapshot(LSPClientServer *server) = 0;
public:
Q_SIGNALS:
......@@ -87,7 +87,8 @@ class LSPClientRevisionSnapshot : public QObject
public:
// find a locked revision for url in snapshot
virtual void find(const QUrl & url, KTextEditor::MovingInterface* & miface, qint64 & revision) const = 0;
virtual void find(const QUrl &url, KTextEditor::MovingInterface *&miface,
qint64 &revision) const = 0;
};
#endif
This diff is collapsed.
......@@ -35,8 +35,7 @@ class LSPClientSymbolView
{
public:
// only needs a factory; no other public interface
static QObject*
new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin,
static QObject *new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin,
QSharedPointer<LSPClientServerManager> manager);
};
......@@ -45,8 +44,7 @@ class LSPClientViewTracker : public QObject
Q_OBJECT
public:
// factory method; private implementation by interface
static LSPClientViewTracker*
new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin,
static LSPClientViewTracker *new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin,
int change_ms, int motion_ms);
enum State {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment