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 @@ ...@@ -31,20 +31,18 @@
#include <KTextEditor/CodeCompletionModel> #include <KTextEditor/CodeCompletionModel>
#include <KTextEditor/CodeCompletionModelControllerInterface> #include <KTextEditor/CodeCompletionModelControllerInterface>
class LSPClientCompletion : public KTextEditor::CodeCompletionModel, public KTextEditor::CodeCompletionModelControllerInterface class LSPClientCompletion : public KTextEditor::CodeCompletionModel,
public KTextEditor::CodeCompletionModelControllerInterface
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface) Q_INTERFACES(KTextEditor::CodeCompletionModelControllerInterface)
public: public:
// implementation factory method // implementation factory method
static LSPClientCompletion* new_(QSharedPointer<LSPClientServerManager> manager); static LSPClientCompletion *new_(QSharedPointer<LSPClientServerManager> manager);
LSPClientCompletion(QObject * parent) LSPClientCompletion(QObject *parent) : KTextEditor::CodeCompletionModel(parent) {}
: KTextEditor::CodeCompletionModel(parent)
{}
virtual void setServer(QSharedPointer<LSPClientServer> server) = 0; virtual void setServer(QSharedPointer<LSPClientServer> server) = 0;
virtual void setSelectedDocumentation(bool) = 0; virtual void setSelectedDocumentation(bool) = 0;
......
...@@ -82,16 +82,15 @@ LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugi ...@@ -82,16 +82,15 @@ LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugi
reset(); reset();
for (const auto & cb : {m_symbolDetails, m_symbolExpand, m_symbolSort, m_symbolTree, for (const auto &cb : { m_symbolDetails, m_symbolExpand, m_symbolSort, m_symbolTree, m_complDoc,
m_complDoc, m_refDeclaration, m_diagnostics, m_diagnosticsMark, m_refDeclaration, m_diagnostics, m_diagnosticsMark, m_onTypeFormatting,
m_onTypeFormatting, m_incrementalSync}) m_incrementalSync })
connect(cb, &QCheckBox::toggled, this, &LSPClientConfigPage::changed); connect(cb, &QCheckBox::toggled, this, &LSPClientConfigPage::changed);
connect(m_configPath, &KUrlRequester::textChanged, this, &LSPClientConfigPage::changed); connect(m_configPath, &KUrlRequester::textChanged, this, &LSPClientConfigPage::changed);
connect(m_configPath, &KUrlRequester::urlSelected, this, &LSPClientConfigPage::changed); connect(m_configPath, &KUrlRequester::urlSelected, this, &LSPClientConfigPage::changed);
// custom control logic // custom control logic
auto h = [this] () auto h = [this]() {
{
bool enabled = m_diagnostics->isChecked(); bool enabled = m_diagnostics->isChecked();
m_diagnosticsHighlight->setEnabled(enabled); m_diagnosticsHighlight->setEnabled(enabled);
m_diagnosticsMark->setEnabled(enabled); m_diagnosticsMark->setEnabled(enabled);
......
...@@ -38,34 +38,34 @@ class LSPClientConfigPage : public KTextEditor::ConfigPage ...@@ -38,34 +38,34 @@ class LSPClientConfigPage : public KTextEditor::ConfigPage
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit LSPClientConfigPage(QWidget *parent = nullptr, LSPClientPlugin *plugin = nullptr); explicit LSPClientConfigPage(QWidget *parent = nullptr, LSPClientPlugin *plugin = nullptr);
~LSPClientConfigPage() override {}; ~LSPClientConfigPage() override {};
QString name() const override; QString name() const override;
QString fullName() const override; QString fullName() const override;
QIcon icon() const override; QIcon icon() const override;
public Q_SLOTS: public Q_SLOTS:
void apply() override; void apply() override;
void defaults() override; void defaults() override;
void reset() override; void reset() override;
private: private:
QCheckBox* m_symbolDetails; QCheckBox *m_symbolDetails;
QCheckBox* m_symbolExpand; QCheckBox *m_symbolExpand;
QCheckBox* m_symbolTree; QCheckBox *m_symbolTree;
QCheckBox* m_symbolSort; QCheckBox *m_symbolSort;
QCheckBox* m_complDoc; QCheckBox *m_complDoc;
QCheckBox* m_refDeclaration; QCheckBox *m_refDeclaration;
QCheckBox* m_diagnostics; QCheckBox *m_diagnostics;
QCheckBox* m_diagnosticsHighlight; QCheckBox *m_diagnosticsHighlight;
QCheckBox* m_diagnosticsMark; QCheckBox *m_diagnosticsMark;
QCheckBox* m_onTypeFormatting; QCheckBox *m_onTypeFormatting;
QCheckBox* m_incrementalSync; QCheckBox *m_incrementalSync;
KUrlRequester *m_configPath; KUrlRequester *m_configPath;
LSPClientPlugin *m_plugin; LSPClientPlugin *m_plugin;
}; };
#endif #endif
...@@ -49,8 +49,8 @@ static const QString CONFIG_DIAGNOSTICS_HIGHLIGHT { QStringLiteral("DiagnosticsH ...@@ -49,8 +49,8 @@ static const QString CONFIG_DIAGNOSTICS_HIGHLIGHT { QStringLiteral("DiagnosticsH
static const QString CONFIG_DIAGNOSTICS_MARK { QStringLiteral("DiagnosticsMark") }; static const QString CONFIG_DIAGNOSTICS_MARK { QStringLiteral("DiagnosticsMark") };
static const QString CONFIG_SERVER_CONFIG { QStringLiteral("ServerConfiguration") }; static const QString CONFIG_SERVER_CONFIG { QStringLiteral("ServerConfiguration") };
K_PLUGIN_FACTORY_WITH_JSON(LSPClientPluginFactory, "lspclientplugin.json",
K_PLUGIN_FACTORY_WITH_JSON(LSPClientPluginFactory, "lspclientplugin.json", registerPlugin<LSPClientPlugin>();) registerPlugin<LSPClientPlugin>();)
LSPClientPlugin::LSPClientPlugin(QObject *parent, const QList<QVariant> &) LSPClientPlugin::LSPClientPlugin(QObject *parent, const QList<QVariant> &)
: KTextEditor::Plugin(parent) : KTextEditor::Plugin(parent)
...@@ -61,17 +61,17 @@ LSPClientPlugin::LSPClientPlugin(QObject *parent, const QList<QVariant> &) ...@@ -61,17 +61,17 @@ LSPClientPlugin::LSPClientPlugin(QObject *parent, const QList<QVariant> &)
*/ */
m_debugMode = (qgetenv("LSPCLIENT_DEBUG") == QByteArray("1")); m_debugMode = (qgetenv("LSPCLIENT_DEBUG") == QByteArray("1"));
if (!m_debugMode) { if (!m_debugMode) {
QLoggingCategory::setFilterRules(QStringLiteral("katelspclientplugin.debug=false\nkatelspclientplugin.info=false")); QLoggingCategory::setFilterRules(
QStringLiteral("katelspclientplugin.debug=false\nkatelspclientplugin.info=false"));
} else { } else {
QLoggingCategory::setFilterRules(QStringLiteral("katelspclientplugin.debug=true\nkatelspclientplugin.info=true")); QLoggingCategory::setFilterRules(
QStringLiteral("katelspclientplugin.debug=true\nkatelspclientplugin.info=true"));
} }
readConfig(); readConfig();
} }
LSPClientPlugin::~LSPClientPlugin() LSPClientPlugin::~LSPClientPlugin() {}
{
}
QObject *LSPClientPlugin::createView(KTextEditor::MainWindow *mainWindow) QObject *LSPClientPlugin::createView(KTextEditor::MainWindow *mainWindow)
{ {
......
...@@ -35,39 +35,40 @@ class LSPClientPlugin : public KTextEditor::Plugin ...@@ -35,39 +35,40 @@ class LSPClientPlugin : public KTextEditor::Plugin
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit LSPClientPlugin(QObject *parent = nullptr, const QList<QVariant> & = QList<QVariant>()); explicit LSPClientPlugin(QObject *parent = nullptr,
~LSPClientPlugin() override; const QList<QVariant> & = QList<QVariant>());
~LSPClientPlugin() override;
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
QObject *createView(KTextEditor::MainWindow *mainWindow) override;
int configPages() const override;
KTextEditor::ConfigPage *configPage(int number = 0, QWidget *parent = nullptr) override; int configPages() const override;
KTextEditor::ConfigPage *configPage(int number = 0, QWidget *parent = nullptr) override;
void readConfig();
void writeConfig() const; void readConfig();
void writeConfig() const;
// settings
bool m_symbolDetails; // settings
bool m_symbolExpand; bool m_symbolDetails;
bool m_symbolTree; bool m_symbolExpand;
bool m_symbolSort; bool m_symbolTree;
bool m_complDoc; bool m_symbolSort;
bool m_refDeclaration; bool m_complDoc;
bool m_diagnostics; bool m_refDeclaration;
bool m_diagnosticsHighlight; bool m_diagnostics;
bool m_diagnosticsMark; bool m_diagnosticsHighlight;
bool m_onTypeFormatting; bool m_diagnosticsMark;
bool m_incrementalSync; bool m_onTypeFormatting;
QUrl m_configPath; bool m_incrementalSync;
QUrl m_configPath;
// debug mode?
bool m_debugMode = false; // debug mode?
bool m_debugMode = false;
private: private:
Q_SIGNALS: Q_SIGNALS:
// signal settings update // signal settings update
void update() const; void update() const;
}; };
#endif #endif
This diff is collapsed.
...@@ -30,16 +30,14 @@ ...@@ -30,16 +30,14 @@
class LSPClientPlugin; class LSPClientPlugin;
namespace KTextEditor { namespace KTextEditor {
class MainWindow; class MainWindow;
} }
class LSPClientPluginView class LSPClientPluginView
{ {
public: public:
// only needs a factory; no other public interface // only needs a factory; no other public interface
static QObject* static QObject *new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin);
new_(LSPClientPlugin *plugin, KTextEditor::MainWindow *mainWin);
}; };
#endif #endif
...@@ -41,8 +41,7 @@ ...@@ -41,8 +41,7 @@
// Moreover, to avoid introducing a custom 'optional' type, absence of an optional // Moreover, to avoid introducing a custom 'optional' type, absence of an optional
// part/member is usually signalled by some 'invalid' marker (empty, negative). // part/member is usually signalled by some 'invalid' marker (empty, negative).
enum class LSPErrorCode enum class LSPErrorCode {
{
// Defined by JSON RPC // Defined by JSON RPC
ParseError = -32700, ParseError = -32700,
InvalidRequest = -32600, InvalidRequest = -32600,
...@@ -59,31 +58,24 @@ enum class LSPErrorCode ...@@ -59,31 +58,24 @@ enum class LSPErrorCode
ContentModified = -32801 ContentModified = -32801
}; };
enum class LSPDocumentSyncKind enum class LSPDocumentSyncKind { None = 0, Full = 1, Incremental = 2 };
{
None = 0,
Full = 1,
Incremental = 2
};
struct LSPCompletionOptions struct LSPCompletionOptions {
{
bool provider = false; bool provider = false;
bool resolveProvider = false; bool resolveProvider = false;
QVector<QChar> triggerCharacters; QVector<QChar> triggerCharacters;
}; };
struct LSPSignatureHelpOptions struct LSPSignatureHelpOptions {
{
bool provider = false; bool provider = false;
QVector<QChar> triggerCharacters; QVector<QChar> triggerCharacters;
}; };
// ensure distinct type // ensure distinct type
struct LSPDocumentOnTypeFormattingOptions : public LSPSignatureHelpOptions {}; struct LSPDocumentOnTypeFormattingOptions : public LSPSignatureHelpOptions {
};
struct LSPServerCapabilities struct LSPServerCapabilities {
{
LSPDocumentSyncKind textDocumentSync = LSPDocumentSyncKind::None; LSPDocumentSyncKind textDocumentSync = LSPDocumentSyncKind::None;
bool hoverProvider = false; bool hoverProvider = false;
LSPCompletionOptions completionProvider; LSPCompletionOptions completionProvider;
...@@ -102,15 +94,9 @@ struct LSPServerCapabilities ...@@ -102,15 +94,9 @@ struct LSPServerCapabilities
bool codeActionProvider = false; bool codeActionProvider = false;
}; };
enum class LSPMarkupKind enum class LSPMarkupKind { None = 0, PlainText = 1, MarkDown = 2 };
{
None = 0,
PlainText = 1,
MarkDown = 2
};
struct LSPMarkupContent struct LSPMarkupContent {
{
LSPMarkupKind kind = LSPMarkupKind::None; LSPMarkupKind kind = LSPMarkupKind::None;
QString value; QString value;
}; };
...@@ -129,34 +115,26 @@ using LSPPosition = KTextEditor::Cursor; ...@@ -129,34 +115,26 @@ using LSPPosition = KTextEditor::Cursor;
*/ */
using LSPRange = KTextEditor::Range; using LSPRange = KTextEditor::Range;
struct LSPLocation struct LSPLocation {
{
QUrl uri; QUrl uri;
LSPRange range; LSPRange range;
}; };
struct LSPTextDocumentContentChangeEvent struct LSPTextDocumentContentChangeEvent {
{
LSPRange range; LSPRange range;
QString text; QString text;
}; };
enum class LSPDocumentHighlightKind enum class LSPDocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
{
Text = 1,
Read = 2,
Write = 3
};
struct LSPDocumentHighlight struct LSPDocumentHighlight {
{
LSPRange range; LSPRange range;
LSPDocumentHighlightKind kind; LSPDocumentHighlightKind kind;
}; };
struct LSPHover struct LSPHover {
{ // vector for contents to support all three variants:
// vector for contents to support all three variants: MarkedString | MarkedString[] | MarkupContent // MarkedString | MarkedString[] | MarkupContent
// vector variant is still in use e.g. by Rust rls // vector variant is still in use e.g. by Rust rls
QVector<LSPMarkupContent> contents; QVector<LSPMarkupContent> contents;
LSPRange range; LSPRange range;
...@@ -183,12 +161,12 @@ enum class LSPSymbolKind { ...@@ -183,12 +161,12 @@ enum class LSPSymbolKind {
Array = 18, Array = 18,
}; };
struct LSPSymbolInformation struct LSPSymbolInformation {
{ LSPSymbolInformation(const QString &_name, LSPSymbolKind _kind, LSPRange _range,
LSPSymbolInformation(const QString & _name, LSPSymbolKind _kind, const QString &_detail)
LSPRange _range, const QString & _detail)
: name(_name), detail(_detail), kind(_kind), range(_range) : name(_name), detail(_detail), kind(_kind), range(_range)
{} {
}
QString name; QString name;
QString detail; QString detail;
LSPSymbolKind kind; LSPSymbolKind kind;
...@@ -196,8 +174,7 @@ struct LSPSymbolInformation ...@@ -196,8 +174,7 @@ struct LSPSymbolInformation
QList<LSPSymbolInformation> children; QList<LSPSymbolInformation> children;
}; };
enum class LSPCompletionItemKind enum class LSPCompletionItemKind {
{
Text = 1, Text = 1,
Method = 2, Method = 2,
Function = 3, Function = 3,
...@@ -225,8 +202,7 @@ enum class LSPCompletionItemKind ...@@ -225,8 +202,7 @@ enum class LSPCompletionItemKind
TypeParameter = 25, TypeParameter = 25,
}; };
struct LSPCompletionItem struct LSPCompletionItem {
{
QString label; QString label;
LSPCompletionItemKind kind; LSPCompletionItemKind kind;
QString detail; QString detail;
...@@ -235,44 +211,38 @@ struct LSPCompletionItem ...@@ -235,44 +211,38 @@ struct LSPCompletionItem
QString insertText; QString insertText;
}; };
struct LSPParameterInformation struct LSPParameterInformation {
{
// offsets into overall signature label // offsets into overall signature label
// (-1 if invalid) // (-1 if invalid)
int start; int start;
int end; int end;
}; };
struct LSPSignatureInformation struct LSPSignatureInformation {
{
QString label; QString label;
LSPMarkupContent documentation; LSPMarkupContent documentation;
QList<LSPParameterInformation> parameters; QList<LSPParameterInformation> parameters;
}; };
struct LSPSignatureHelp struct LSPSignatureHelp {
{
QList<LSPSignatureInformation> signatures; QList<LSPSignatureInformation> signatures;
int activeSignature; int activeSignature;
int activeParameter; int activeParameter;
}; };
struct LSPFormattingOptions struct LSPFormattingOptions {
{
int tabSize; int tabSize;
bool insertSpaces; bool insertSpaces;
// additional fields // additional fields
QJsonObject extra; QJsonObject extra;
}; };
struct LSPTextEdit struct LSPTextEdit {
{
LSPRange range; LSPRange range;
QString newText; QString newText;
}; };
enum class LSPDiagnosticSeverity enum class LSPDiagnosticSeverity {
{
Unknown = 0, Unknown = 0,
Error = 1, Error = 1,
Warning = 2, Warning = 2,
...@@ -280,15 +250,13 @@ enum class LSPDiagnosticSeverity ...@@ -280,15 +250,13 @@ enum class LSPDiagnosticSeverity
Hint = 4, Hint = 4,
}; };
struct LSPDiagnosticRelatedInformation struct LSPDiagnosticRelatedInformation {
{
// empty url / invalid range when absent // empty url / invalid range when absent
LSPLocation location; LSPLocation location;
QString message; QString message;
}; };
struct LSPDiagnostic struct LSPDiagnostic {
{
LSPRange range; LSPRange range;
LSPDiagnosticSeverity severity; LSPDiagnosticSeverity severity;
QString code; QString code;
...@@ -297,28 +265,24 @@ struct LSPDiagnostic ...@@ -297,28 +265,24 @@ struct LSPDiagnostic
LSPDiagnosticRelatedInformation relatedInformation; LSPDiagnosticRelatedInformation relatedInformation;
}; };
struct LSPPublishDiagnosticsParams struct LSPPublishDiagnosticsParams {
{
QUrl uri; QUrl uri;
QList<LSPDiagnostic> diagnostics; QList<LSPDiagnostic> diagnostics;
}; };
struct LSPCommand struct LSPCommand {
{
QString title; QString title;
QString command; QString command;
// pretty opaque // pretty opaque
QJsonArray arguments; QJsonArray arguments;
}; };
struct LSPWorkspaceEdit struct LSPWorkspaceEdit {
{
// supported part for now // supported part for now
QHash<QUrl, QList<LSPTextEdit>> changes; QHash<QUrl, QList<LSPTextEdit>> changes;
}; };
struct LSPCodeAction struct LSPCodeAction {
{
QString title; QString title;
QString kind; QString kind;
QList<LSPDiagnostic> diagnostics; QList<LSPDiagnostic> diagnostics;
...@@ -326,14 +290,12 @@ struct LSPCodeAction ...@@ -326,14 +290,12 @@ struct LSPCodeAction
LSPCommand command; LSPCommand command;
}; };
struct LSPApplyWorkspaceEditParams struct LSPApplyWorkspaceEditParams {
{
QString label; QString label;
LSPWorkspaceEdit edit; LSPWorkspaceEdit edit;
}; };
struct LSPApplyWorkspaceEditResponse struct LSPApplyWorkspaceEditResponse {
{
bool applied; bool applied;
QString failureReason; QString failureReason;
}; };
......
This diff is collapsed.
...@@ -37,35 +37,30 @@ ...@@ -37,35 +37,30 @@
#include <functional> #include <functional>
namespace utils namespace utils {
{
// template helper // template helper
// function bind helpers // function bind helpers
template<typename R, typename T, typename Tp, typename... Args> template<typename R, typename T, typename Tp, typename... Args>
inline std::function<R(Args ...)> inline std::function<R(Args...)> mem_fun(R (T::*pm)(Args...), Tp object)
mem_fun(R (T::*pm)(Args ...), Tp object)
{ {
return [object, pm](Args... args) { return [object, pm](Args... args) { return (object->*pm)(std::forward<Args>(args)...); };
return (object->*pm)(std::forward<Args>(args)...);
};
} }
template<typename R, typename T, typename Tp, typename... Args> template<typename R, typename T, typename Tp, typename... Args>
inline std::function<R(Args...)> inline std::function<R(Args...)> mem_fun(R (T::*pm)(Args...) const, Tp object)
mem_fun(R (T::*pm)(Args ...) const, Tp object)
{ {
return [object, pm](Args... args) { return [object, pm](Args... args) { return (object->*pm)(std::forward<Args>(args)...); };
return (object->*pm)(std::forward<Args>(args)...);
};
} }
// prevent argument deduction // prevent argument deduction
template<typename T> struct identity { typedef T type; }; template<typename T>
struct identity {
typedef T type;
};
} // namespace utils } // namespace utils
static const int TIMEOUT_SHUTDOWN = 200; static const int TIMEOUT_SHUTDOWN = 200;
template<typename T> template<typename T>
...@@ -87,13 +82,7 @@ class LSPClientServer : public QObject ...@@ -87,13 +82,7 @@ class LSPClientServer : public QObject
Q_OBJECT Q_OBJECT
public: public:
enum class State enum class State { None, Started, Running, Shutdown };
{
None,
Started,
Running,
Shutdown
};
class LSPClientServerPrivate; class LSPClientServerPrivate;
class RequestHandle class RequestHandle
...@@ -101,8 +90,9 @@ public: ...@@ -101,8 +90,9 @@ public:
friend class LSPClientServerPrivate; friend class LSPClientServerPrivate;
QPointer<LSPClientServer> m_server; QPointer<LSPClientServer> m_server;
int m_id = -1; int m_id = -1;
public: public: