2018-07-13 12:33:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-04-04 14:36:28 +02:00
|
|
|
#include "documentsymbolcache.h"
|
2018-07-13 12:33:46 +02:00
|
|
|
#include "dynamiccapabilities.h"
|
2019-01-29 13:20:58 +01:00
|
|
|
#include "languageclientcompletionassist.h"
|
|
|
|
|
#include "languageclientquickfix.h"
|
2018-07-13 12:33:46 +02:00
|
|
|
#include "languageclientsettings.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/id.h>
|
|
|
|
|
#include <coreplugin/messagemanager.h>
|
|
|
|
|
#include <utils/link.h>
|
|
|
|
|
|
2019-02-01 14:08:02 +01:00
|
|
|
#include <languageserverprotocol/client.h>
|
|
|
|
|
#include <languageserverprotocol/diagnostics.h>
|
2018-07-13 12:33:46 +02:00
|
|
|
#include <languageserverprotocol/initializemessages.h>
|
2019-02-01 14:08:02 +01:00
|
|
|
#include <languageserverprotocol/languagefeatures.h>
|
|
|
|
|
#include <languageserverprotocol/messages.h>
|
2018-07-13 12:33:46 +02:00
|
|
|
#include <languageserverprotocol/shutdownmessages.h>
|
|
|
|
|
#include <languageserverprotocol/textsynchronization.h>
|
|
|
|
|
|
|
|
|
|
#include <QBuffer>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
|
|
|
|
|
namespace Core { class IDocument; }
|
|
|
|
|
namespace ProjectExplorer { class Project; }
|
|
|
|
|
namespace TextEditor
|
|
|
|
|
{
|
2019-02-01 14:08:02 +01:00
|
|
|
class TextDocument;
|
|
|
|
|
class TextEditorWidget;
|
|
|
|
|
class TextMark;
|
2018-07-13 12:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace LanguageClient {
|
|
|
|
|
|
2019-01-31 08:46:23 +01:00
|
|
|
class BaseClientInterface;
|
2019-02-01 14:08:02 +01:00
|
|
|
class TextMark;
|
2019-01-31 08:46:23 +01:00
|
|
|
|
2019-01-31 12:15:43 +01:00
|
|
|
class Client : public QObject
|
2018-07-13 12:33:46 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2019-01-31 12:15:43 +01:00
|
|
|
explicit Client(BaseClientInterface *clientInterface); // takes ownership
|
|
|
|
|
~Client() override;
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2019-01-31 12:15:43 +01:00
|
|
|
Client(const Client &) = delete;
|
|
|
|
|
Client(Client &&) = delete;
|
|
|
|
|
Client &operator=(const Client &) = delete;
|
|
|
|
|
Client &operator=(Client &&) = delete;
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
enum State {
|
|
|
|
|
Uninitialized,
|
|
|
|
|
InitializeRequested,
|
|
|
|
|
Initialized,
|
|
|
|
|
ShutdownRequested,
|
|
|
|
|
Shutdown,
|
|
|
|
|
Error
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void initialize();
|
|
|
|
|
void shutdown();
|
|
|
|
|
State state() const;
|
|
|
|
|
bool reachable() const { return m_state == Initialized; }
|
|
|
|
|
|
|
|
|
|
// document synchronization
|
2019-03-26 13:48:06 +01:00
|
|
|
bool openDocument(Core::IDocument *document);
|
2018-07-13 12:33:46 +02:00
|
|
|
void closeDocument(const LanguageServerProtocol::DidCloseTextDocumentParams ¶ms);
|
2019-03-26 13:48:06 +01:00
|
|
|
bool documentOpen(const Core::IDocument *document) const;
|
2018-07-13 12:33:46 +02:00
|
|
|
void documentContentsSaved(Core::IDocument *document);
|
|
|
|
|
void documentWillSave(Core::IDocument *document);
|
|
|
|
|
void documentContentsChanged(Core::IDocument *document);
|
|
|
|
|
void registerCapabilities(const QList<LanguageServerProtocol::Registration> ®istrations);
|
|
|
|
|
void unregisterCapabilities(const QList<LanguageServerProtocol::Unregistration> &unregistrations);
|
|
|
|
|
bool findLinkAt(LanguageServerProtocol::GotoDefinitionRequest &request);
|
2018-11-28 08:16:19 +01:00
|
|
|
bool findUsages(LanguageServerProtocol::FindReferencesRequest &request);
|
2018-07-13 12:33:46 +02:00
|
|
|
void requestDocumentSymbols(TextEditor::TextDocument *document);
|
|
|
|
|
void cursorPositionChanged(TextEditor::TextEditorWidget *widget);
|
|
|
|
|
|
2019-01-25 09:48:44 +01:00
|
|
|
void requestCodeActions(const LanguageServerProtocol::DocumentUri &uri,
|
|
|
|
|
const QList<LanguageServerProtocol::Diagnostic> &diagnostics);
|
2019-01-29 13:20:58 +01:00
|
|
|
void requestCodeActions(const LanguageServerProtocol::CodeActionRequest &request);
|
2019-01-25 09:48:44 +01:00
|
|
|
void handleCodeActionResponse(const LanguageServerProtocol::CodeActionRequest::Response &response,
|
|
|
|
|
const LanguageServerProtocol::DocumentUri &uri);
|
|
|
|
|
void executeCommand(const LanguageServerProtocol::Command &command);
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
// workspace control
|
|
|
|
|
void projectOpened(ProjectExplorer::Project *project);
|
|
|
|
|
void projectClosed(ProjectExplorer::Project *project);
|
|
|
|
|
|
|
|
|
|
void sendContent(const LanguageServerProtocol::IContent &content);
|
|
|
|
|
void sendContent(const LanguageServerProtocol::DocumentUri &uri,
|
|
|
|
|
const LanguageServerProtocol::IContent &content);
|
|
|
|
|
void cancelRequest(const LanguageServerProtocol::MessageId &id);
|
|
|
|
|
|
2018-10-10 14:26:57 +02:00
|
|
|
void setSupportedLanguage(const LanguageFilter &filter);
|
|
|
|
|
bool isSupportedDocument(const Core::IDocument *document) const;
|
2018-11-28 08:16:19 +01:00
|
|
|
bool isSupportedFile(const Utils::FileName &filePath, const QString &mimeType) const;
|
|
|
|
|
bool isSupportedUri(const LanguageServerProtocol::DocumentUri &uri) const;
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
void setName(const QString &name) { m_displayName = name; }
|
|
|
|
|
QString name() const { return m_displayName; }
|
|
|
|
|
|
|
|
|
|
Core::Id id() const { return m_id; }
|
|
|
|
|
|
2018-09-18 10:43:17 +02:00
|
|
|
bool needsRestart(const BaseSettings *) const;
|
|
|
|
|
|
2019-01-29 13:20:58 +01:00
|
|
|
QList<LanguageServerProtocol::Diagnostic> diagnosticsAt(
|
|
|
|
|
const LanguageServerProtocol::DocumentUri &uri,
|
|
|
|
|
const LanguageServerProtocol::Range &range) const;
|
|
|
|
|
|
2019-01-31 08:46:23 +01:00
|
|
|
bool start();
|
|
|
|
|
bool reset();
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
void log(const QString &message,
|
|
|
|
|
Core::MessageManager::PrintToOutputPaneFlag flag = Core::MessageManager::NoModeSwitch);
|
2018-11-20 09:44:22 +01:00
|
|
|
template<typename Error>
|
|
|
|
|
void log(const LanguageServerProtocol::ResponseError<Error> &responseError,
|
|
|
|
|
Core::MessageManager::PrintToOutputPaneFlag flag = Core::MessageManager::NoModeSwitch)
|
|
|
|
|
{ log(responseError.toString(), flag); }
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2018-11-23 09:45:51 +01:00
|
|
|
const LanguageServerProtocol::ServerCapabilities &capabilities() const;
|
|
|
|
|
const DynamicCapabilities &dynamicCapabilities() const;
|
2019-03-11 07:33:07 +01:00
|
|
|
const BaseClientInterface *clientInterface() const;
|
2019-04-04 14:36:28 +02:00
|
|
|
DocumentSymbolCache *documentSymbolCache();
|
2018-11-23 09:45:51 +01:00
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
signals:
|
|
|
|
|
void initialized(LanguageServerProtocol::ServerCapabilities capabilities);
|
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void setError(const QString &message);
|
2019-01-31 08:46:23 +01:00
|
|
|
void handleMessage(const LanguageServerProtocol::BaseMessage &message);
|
2018-07-13 12:33:46 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void handleResponse(const LanguageServerProtocol::MessageId &id, const QByteArray &content,
|
|
|
|
|
QTextCodec *codec);
|
|
|
|
|
void handleMethod(const QString &method, LanguageServerProtocol::MessageId id,
|
|
|
|
|
const LanguageServerProtocol::IContent *content);
|
|
|
|
|
|
2019-02-01 14:08:02 +01:00
|
|
|
void handleDiagnostics(const LanguageServerProtocol::PublishDiagnosticsParams ¶ms);
|
|
|
|
|
|
2018-11-20 07:45:22 +01:00
|
|
|
void intializeCallback(const LanguageServerProtocol::InitializeRequest::Response &initResponse);
|
|
|
|
|
void shutDownCallback(const LanguageServerProtocol::ShutdownRequest::Response &shutdownResponse);
|
2018-07-13 12:33:46 +02:00
|
|
|
bool sendWorkspceFolderChanges() const;
|
2018-09-12 10:24:02 +02:00
|
|
|
void log(const LanguageServerProtocol::ShowMessageParams &message,
|
|
|
|
|
Core::MessageManager::PrintToOutputPaneFlag flag = Core::MessageManager::NoModeSwitch);
|
|
|
|
|
|
|
|
|
|
void showMessageBox(const LanguageServerProtocol::ShowMessageRequestParams &message,
|
|
|
|
|
const LanguageServerProtocol::MessageId &id);
|
2018-07-13 12:33:46 +02:00
|
|
|
|
2019-02-01 14:08:02 +01:00
|
|
|
void showDiagnostics(const LanguageServerProtocol::DocumentUri &uri);
|
|
|
|
|
void removeDiagnostics(const LanguageServerProtocol::DocumentUri &uri);
|
|
|
|
|
|
2018-07-13 12:33:46 +02:00
|
|
|
using ContentHandler = std::function<void(const QByteArray &, QTextCodec *, QString &,
|
|
|
|
|
LanguageServerProtocol::ResponseHandlers,
|
|
|
|
|
LanguageServerProtocol::MethodHandler)>;
|
|
|
|
|
|
|
|
|
|
State m_state = Uninitialized;
|
|
|
|
|
QHash<LanguageServerProtocol::MessageId, LanguageServerProtocol::ResponseHandler> m_responseHandlers;
|
|
|
|
|
QHash<QByteArray, ContentHandler> m_contentHandler;
|
|
|
|
|
QString m_displayName;
|
2018-10-10 14:26:57 +02:00
|
|
|
LanguageFilter m_languagFilter;
|
2018-07-13 12:33:46 +02:00
|
|
|
QList<Utils::FileName> m_openedDocument;
|
|
|
|
|
Core::Id m_id;
|
|
|
|
|
LanguageServerProtocol::ServerCapabilities m_serverCapabilities;
|
|
|
|
|
DynamicCapabilities m_dynamicCapabilities;
|
2018-10-16 07:00:48 +02:00
|
|
|
LanguageClientCompletionAssistProvider m_completionProvider;
|
2019-01-29 13:20:58 +01:00
|
|
|
LanguageClientQuickFixProvider m_quickFixProvider;
|
|
|
|
|
QSet<TextEditor::TextDocument *> m_resetAssistProvider;
|
2018-07-13 12:33:46 +02:00
|
|
|
QHash<LanguageServerProtocol::DocumentUri, LanguageServerProtocol::MessageId> m_highlightRequests;
|
2018-09-14 10:00:29 +02:00
|
|
|
int m_restartsLeft = 5;
|
2019-01-31 08:46:23 +01:00
|
|
|
QScopedPointer<BaseClientInterface> m_clientInterface;
|
2019-02-01 14:08:02 +01:00
|
|
|
QMap<LanguageServerProtocol::DocumentUri, QList<TextMark *>> m_diagnostics;
|
2019-04-04 14:36:28 +02:00
|
|
|
DocumentSymbolCache m_documentSymbolCache;
|
2018-07-13 12:33:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace LanguageClient
|