8#include <QtLanguageServer/private/qlanguageserverspectypes_p.h>
9#include <QtLanguageServer/private/qlspnotifysignals_p.h>
11#include <QtCore/qfile.h>
21 &QLspNotifySignals::receivedDidChangeWorkspaceFoldersNotification,
this,
22 [
server,
this](
const DidChangeWorkspaceFoldersParams &
params) {
23 const WorkspaceFoldersChangeEvent &event = params.event;
25 const QList<WorkspaceFolder> &removed = event.removed;
26 QList<QByteArray> toRemove;
27 for (const WorkspaceFolder &folder : removed) {
28 toRemove.append(QQmlLSUtils::lspUriToQmlUrl(folder.uri));
29 m_codeModel->removeDirectory(m_codeModel->url2Path(
30 QQmlLSUtils::lspUriToQmlUrl(folder.uri)));
36 for (
const WorkspaceFolder &folder : added) {
38 pathsToAdd.append(m_codeModel->
url2Path(
46 &QLspNotifySignals::receivedDidChangeWatchedFilesNotification,
this,
47 [
this](
const DidChangeWatchedFilesParams &
params) {
48 const QList<FileEvent> &changes = params.changes;
49 for (const FileEvent &change : changes) {
50 const QString filename =
51 m_codeModel->url2Path(QQmlLSUtils::lspUriToQmlUrl(change.uri));
52 switch (FileChangeType(change.type)) {
53 case FileChangeType::Created:
56 case FileChangeType::Changed: {
58 if (file.open(QIODevice::ReadOnly))
62 case FileChangeType::Deleted:
76 return u
"Workspace"_s;
80 QLspSpecification::InitializeResult &serverInfo)
82 if (!clientInfo.capabilities.workspace
83 || !clientInfo.capabilities.workspace->value(u
"workspaceFolders"_s).toBool(
false))
85 WorkspaceFoldersServerCapabilities folders;
86 folders.supported =
true;
87 folders.changeNotifications =
true;
88 if (!serverInfo.capabilities.workspace)
90 serverInfo.capabilities.workspace->insert(u
"workspaceFolders"_s,
91 QTypedJson::toJsonValue(folders));
96 QLanguageServerProtocol *protocol =
server->protocol();
97 const auto clientInfo =
server->clientInfo();
99 if (clientInfo.capabilities.workspace
100 && clientInfo.capabilities.workspace
101 ->value(u
"didChangeWatchedFiles"_s)[u
"dynamicRegistration"_s]
104 int(WatchKind::Create) | int(WatchKind::Change) | int(WatchKind::Delete);
105 DidChangeWatchedFilesRegistrationOptions watchedFilesParams;
106 FileSystemWatcher qmlWatcher;
107 qmlWatcher.globPattern =
QByteArray(
"*.{qml,js,mjs}");
108 qmlWatcher.kind = watchAll;
109 FileSystemWatcher qmldirWatcher;
110 qmldirWatcher.globPattern =
"qmldir";
111 qmldirWatcher.kind = watchAll;
112 FileSystemWatcher qmltypesWatcher;
113 qmltypesWatcher.globPattern =
QByteArray(
"*.qmltypes");
114 qmltypesWatcher.kind = watchAll;
115 watchedFilesParams.watchers =
117 registrations.
append(Registration {
119 ClientCapabilitiesInfo::WorkspaceDidChangeWatchedFiles,
120 ClientCapabilitiesInfo::WorkspaceDidChangeWatchedFiles,
121 QTypedJson::toJsonValue(watchedFilesParams) });
124 if (!registrations.
isEmpty()) {
125 RegistrationParams
params;
126 params.registrations = registrations;
127 protocol->requestRegistration(
132 [protocol](
const ResponseError &err) {
133 LogMessageParams msg;
134 msg.message =
QByteArray(
"registration of file udates failed, will miss file "
135 "changes done outside the editor due to error ");
137 if (!err.message.isEmpty())
138 msg.message.append(
" ");
139 msg.message.append(err.message);
140 msg.type = MessageType::Warning;
142 protocol->notifyLogMessage(msg);
147 if (std::holds_alternative<QByteArray>(clientInfo.rootUri)) {
151 }
else if (clientInfo.rootPath && std::holds_alternative<QByteArray>(*clientInfo.rootPath)) {
156 if (clientInfo.workspaceFolders
158 for (
const WorkspaceFolder &workspace :
\inmodule QtCore\reentrant
Implements a server for the language server protocol.
void clientInitialized(QLanguageServer *server)
bool isEmpty() const noexcept
void append(parameter_type t)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static QByteArray lspUriToQmlUrl(const QByteArray &uri)
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray toUtf8() const &
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
void addRootUrls(const QList< QByteArray > &urls)
QString url2Path(const QByteArray &url, UrlLookup options=UrlLookup::Caching)
void removeRootUrls(const QList< QByteArray > &urls)
void addDirectoriesToIndex(const QStringList &paths, QLanguageServer *server)
void setupCapabilities(const QLspSpecification::InitializeParams &clientInfo, QLspSpecification::InitializeResult &) override
void clientInitialized(QLanguageServer *)
void registerHandlers(QLanguageServer *server, QLanguageServerProtocol *protocol) override
QString name() const override
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return DBusPendingCall DBusPendingCall return DBusPendingCall return dbus_int32_t return DBusServer * server
#define qCWarning(category,...)
GLsizei const GLchar *const * path