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)));
33 const QList<WorkspaceFolder> &added =
event.added;
34 QList<QByteArray> toAdd;
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))
63 case FileChangeType::Deleted:
81 QLspSpecification::InitializeResult &serverInfo)
83 if (!clientInfo.capabilities.workspace
84 || !clientInfo.capabilities.workspace->value(u
"workspaceFolders"_s).toBool(
false))
86 WorkspaceFoldersServerCapabilities folders;
87 folders.supported =
true;
88 folders.changeNotifications =
true;
89 if (!serverInfo.capabilities.workspace)
91 serverInfo.capabilities.workspace->insert(u
"workspaceFolders"_s,
92 QTypedJson::toJsonValue(folders));
97 QLanguageServerProtocol *protocol =
server->protocol();
98 const auto clientInfo =
server->clientInfo();
99 QList<Registration> registrations;
100 if (clientInfo.capabilities.workspace
101 && clientInfo.capabilities.workspace
102 ->value(u
"didChangeWatchedFiles"_s)[u
"dynamicRegistration"_s]
105 int(WatchKind::Create) | int(WatchKind::Change) | int(WatchKind::Delete);
106 DidChangeWatchedFilesRegistrationOptions watchedFilesParams;
107 FileSystemWatcher qmlWatcher;
108 qmlWatcher.globPattern =
QByteArray(
"*.{qml,js,mjs}");
109 qmlWatcher.kind = watchAll;
110 FileSystemWatcher qmldirWatcher;
111 qmldirWatcher.globPattern =
"qmldir";
112 qmldirWatcher.kind = watchAll;
113 FileSystemWatcher qmltypesWatcher;
114 qmltypesWatcher.globPattern =
QByteArray(
"*.qmltypes");
115 qmltypesWatcher.kind = watchAll;
116 watchedFilesParams.watchers = QList<FileSystemWatcher>({
117 std::move(qmlWatcher),
118 std::move(qmldirWatcher),
119 std::move(qmltypesWatcher)
121 registrations.append(Registration {
123 ClientCapabilitiesInfo::WorkspaceDidChangeWatchedFiles,
124 ClientCapabilitiesInfo::WorkspaceDidChangeWatchedFiles,
125 QTypedJson::toJsonValue(watchedFilesParams) });
128 if (!registrations.isEmpty()) {
129 RegistrationParams
params;
130 params.registrations = registrations;
131 protocol->requestRegistration(
136 [protocol](
const ResponseError &err) {
137 LogMessageParams msg;
138 msg.message =
QByteArray(
"registration of file udates failed, will miss file "
139 "changes done outside the editor due to error ");
141 if (!err.message.isEmpty())
142 msg.message.append(
" ");
143 msg.message.append(err.message);
144 msg.type = MessageType::Warning;
146 protocol->notifyLogMessage(msg);
150 QSet<QString> rootPaths;
151 if (std::holds_alternative<QByteArray>(clientInfo.rootUri)) {
154 rootPaths.insert(
path);
155 }
else if (clientInfo.rootPath && std::holds_alternative<QByteArray>(*clientInfo.rootPath)) {
157 rootPaths.insert(
path);
160 if (clientInfo.workspaceFolders
161 && std::holds_alternative<QList<WorkspaceFolder>>(*clientInfo.workspaceFolders)) {
162 for (
const WorkspaceFolder &workspace :
163 std::as_const(std::get<QList<WorkspaceFolder>>(*clientInfo.workspaceFolders))) {
165 rootPaths.insert(workspaceUrl.toLocalFile());
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...