forked from qt-creator/qt-creator
LSP: rename Create/Rename/DeleteFile classes
Since they clash with default windows functions and cause issues with PCH build. Change-Id: Ice0339c7dad14b40e172c885ffb71d923469614a Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -419,16 +419,16 @@ DocumentChange::DocumentChange(const QJsonValue &value)
|
|||||||
{
|
{
|
||||||
const QString kind = value["kind"].toString();
|
const QString kind = value["kind"].toString();
|
||||||
if (kind == "create")
|
if (kind == "create")
|
||||||
emplace<CreateFile>(value);
|
emplace<CreateFileOperation>(value);
|
||||||
else if (kind == "rename")
|
else if (kind == "rename")
|
||||||
emplace<RenameFile>(value);
|
emplace<RenameFileOperation>(value);
|
||||||
else if (kind == "delete")
|
else if (kind == "delete")
|
||||||
emplace<DeleteFile>(value);
|
emplace<DeleteFileOperation>(value);
|
||||||
else
|
else
|
||||||
emplace<TextDocumentEdit>(value);
|
emplace<TextDocumentEdit>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
using DocumentChangeBase = std::variant<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>;
|
using DocumentChangeBase = std::variant<TextDocumentEdit, CreateFileOperation, RenameFileOperation, DeleteFileOperation>;
|
||||||
|
|
||||||
bool DocumentChange::isValid() const
|
bool DocumentChange::isValid() const
|
||||||
{
|
{
|
||||||
@@ -440,49 +440,49 @@ DocumentChange::operator const QJsonValue () const
|
|||||||
return std::visit([](const auto &v) { return QJsonValue(v); }, DocumentChangeBase(*this));
|
return std::visit([](const auto &v) { return QJsonValue(v); }, DocumentChangeBase(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateFile::CreateFile()
|
CreateFileOperation::CreateFileOperation()
|
||||||
{
|
{
|
||||||
insert(kindKey, "create");
|
insert(kindKey, "create");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CreateFile::message(const DocumentUri::PathMapper &mapToHostPath) const
|
QString CreateFileOperation::message(const DocumentUri::PathMapper &mapToHostPath) const
|
||||||
{
|
{
|
||||||
return Tr::tr("Create %1").arg(uri().toFilePath(mapToHostPath).toUserOutput());
|
return Tr::tr("Create %1").arg(uri().toFilePath(mapToHostPath).toUserOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LanguageServerProtocol::CreateFile::isValid() const
|
bool LanguageServerProtocol::CreateFileOperation::isValid() const
|
||||||
{
|
{
|
||||||
return contains(uriKey) && value(kindKey) == "create";
|
return contains(uriKey) && value(kindKey) == "create";
|
||||||
}
|
}
|
||||||
|
|
||||||
RenameFile::RenameFile()
|
RenameFileOperation::RenameFileOperation()
|
||||||
{
|
{
|
||||||
insert(kindKey, "rename");
|
insert(kindKey, "rename");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString RenameFile::message(const DocumentUri::PathMapper &mapToHostPath) const
|
QString RenameFileOperation::message(const DocumentUri::PathMapper &mapToHostPath) const
|
||||||
{
|
{
|
||||||
return Tr::tr("Rename %1 to %2")
|
return Tr::tr("Rename %1 to %2")
|
||||||
.arg(oldUri().toFilePath(mapToHostPath).toUserOutput(),
|
.arg(oldUri().toFilePath(mapToHostPath).toUserOutput(),
|
||||||
newUri().toFilePath(mapToHostPath).toUserOutput());
|
newUri().toFilePath(mapToHostPath).toUserOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenameFile::isValid() const
|
bool RenameFileOperation::isValid() const
|
||||||
{
|
{
|
||||||
return contains(oldUriKey) && contains(newUriKey) && value(kindKey) == "rename";
|
return contains(oldUriKey) && contains(newUriKey) && value(kindKey) == "rename";
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteFile::DeleteFile()
|
DeleteFileOperation::DeleteFileOperation()
|
||||||
{
|
{
|
||||||
insert(kindKey, "delete");
|
insert(kindKey, "delete");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DeleteFile::message(const DocumentUri::PathMapper &mapToHostPath) const
|
QString DeleteFileOperation::message(const DocumentUri::PathMapper &mapToHostPath) const
|
||||||
{
|
{
|
||||||
return Tr::tr("Delete %1").arg(uri().toFilePath(mapToHostPath).toUserOutput());
|
return Tr::tr("Delete %1").arg(uri().toFilePath(mapToHostPath).toUserOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteFile::isValid() const
|
bool DeleteFileOperation::isValid() const
|
||||||
{
|
{
|
||||||
return contains(uriKey) && value(kindKey) == "delete";
|
return contains(uriKey) && value(kindKey) == "delete";
|
||||||
}
|
}
|
||||||
|
@@ -299,11 +299,11 @@ public:
|
|||||||
void clearIgnoreIfExists() { remove(ignoreIfExistsKey); }
|
void clearIgnoreIfExists() { remove(ignoreIfExistsKey); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class LANGUAGESERVERPROTOCOL_EXPORT CreateFile : public JsonObject
|
class LANGUAGESERVERPROTOCOL_EXPORT CreateFileOperation : public JsonObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using JsonObject::JsonObject;
|
using JsonObject::JsonObject;
|
||||||
CreateFile();
|
CreateFileOperation();
|
||||||
|
|
||||||
DocumentUri uri() const { return DocumentUri::fromProtocol(typedValue<QString>(uriKey)); }
|
DocumentUri uri() const { return DocumentUri::fromProtocol(typedValue<QString>(uriKey)); }
|
||||||
void setUri(const DocumentUri &uri) { insert(uriKey, uri); }
|
void setUri(const DocumentUri &uri) { insert(uriKey, uri); }
|
||||||
@@ -318,11 +318,11 @@ public:
|
|||||||
bool isValid() const override;
|
bool isValid() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class LANGUAGESERVERPROTOCOL_EXPORT RenameFile : public JsonObject
|
class LANGUAGESERVERPROTOCOL_EXPORT RenameFileOperation : public JsonObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using JsonObject::JsonObject;
|
using JsonObject::JsonObject;
|
||||||
RenameFile();
|
RenameFileOperation();
|
||||||
|
|
||||||
DocumentUri oldUri() const { return DocumentUri::fromProtocol(typedValue<QString>(oldUriKey)); }
|
DocumentUri oldUri() const { return DocumentUri::fromProtocol(typedValue<QString>(oldUriKey)); }
|
||||||
void setOldUri(const DocumentUri &oldUri) { insert(oldUriKey, oldUri); }
|
void setOldUri(const DocumentUri &oldUri) { insert(oldUriKey, oldUri); }
|
||||||
@@ -354,11 +354,11 @@ public:
|
|||||||
void clearIgnoreIfNotExists() { remove(ignoreIfNotExistsKey); }
|
void clearIgnoreIfNotExists() { remove(ignoreIfNotExistsKey); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class LANGUAGESERVERPROTOCOL_EXPORT DeleteFile : public JsonObject
|
class LANGUAGESERVERPROTOCOL_EXPORT DeleteFileOperation : public JsonObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using JsonObject::JsonObject;
|
using JsonObject::JsonObject;
|
||||||
DeleteFile();
|
DeleteFileOperation();
|
||||||
|
|
||||||
DocumentUri uri() const { return DocumentUri::fromProtocol(typedValue<QString>(uriKey)); }
|
DocumentUri uri() const { return DocumentUri::fromProtocol(typedValue<QString>(uriKey)); }
|
||||||
void setUri(const DocumentUri &uri) { insert(uriKey, uri); }
|
void setUri(const DocumentUri &uri) { insert(uriKey, uri); }
|
||||||
@@ -374,7 +374,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class LANGUAGESERVERPROTOCOL_EXPORT DocumentChange
|
class LANGUAGESERVERPROTOCOL_EXPORT DocumentChange
|
||||||
: public std::variant<TextDocumentEdit, CreateFile, RenameFile, DeleteFile>
|
: public std::variant<TextDocumentEdit, CreateFileOperation, RenameFileOperation, DeleteFileOperation>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using variant::variant;
|
using variant::variant;
|
||||||
|
@@ -556,18 +556,18 @@ Utils::SearchResultItems generateReplaceItems(const WorkspaceEdit &edits,
|
|||||||
} else {
|
} else {
|
||||||
Utils::SearchResultItem item;
|
Utils::SearchResultItem item;
|
||||||
|
|
||||||
if (std::holds_alternative<LanguageServerProtocol::CreateFile>(documentChange)) {
|
if (std::holds_alternative<CreateFileOperation>(documentChange)) {
|
||||||
auto op = std::get<LanguageServerProtocol::CreateFile>(documentChange);
|
auto op = std::get<CreateFileOperation>(documentChange);
|
||||||
item.setLineText(op.message(pathMapper));
|
item.setLineText(op.message(pathMapper));
|
||||||
item.setFilePath(op.uri().toFilePath(pathMapper));
|
item.setFilePath(op.uri().toFilePath(pathMapper));
|
||||||
item.setUserData(QVariant(op));
|
item.setUserData(QVariant(op));
|
||||||
} else if (std::holds_alternative<RenameFile>(documentChange)) {
|
} else if (std::holds_alternative<RenameFileOperation>(documentChange)) {
|
||||||
auto op = std::get<RenameFile>(documentChange);
|
auto op = std::get<RenameFileOperation>(documentChange);
|
||||||
item.setLineText(op.message(pathMapper));
|
item.setLineText(op.message(pathMapper));
|
||||||
item.setFilePath(op.oldUri().toFilePath(pathMapper));
|
item.setFilePath(op.oldUri().toFilePath(pathMapper));
|
||||||
item.setUserData(QVariant(op));
|
item.setUserData(QVariant(op));
|
||||||
} else if (std::holds_alternative<LanguageServerProtocol::DeleteFile>(documentChange)) {
|
} else if (std::holds_alternative<DeleteFileOperation>(documentChange)) {
|
||||||
auto op = std::get<LanguageServerProtocol::DeleteFile>(documentChange);
|
auto op = std::get<DeleteFileOperation>(documentChange);
|
||||||
item.setLineText(op.message(pathMapper));
|
item.setLineText(op.message(pathMapper));
|
||||||
item.setFilePath(op.uri().toFilePath(pathMapper));
|
item.setFilePath(op.uri().toFilePath(pathMapper));
|
||||||
item.setUserData(QVariant(op));
|
item.setUserData(QVariant(op));
|
||||||
@@ -693,11 +693,11 @@ void SymbolSupport::applyRename(const Utils::SearchResultItems &checkedItems,
|
|||||||
const QJsonObject jsonObject = item.userData().toJsonObject();
|
const QJsonObject jsonObject = item.userData().toJsonObject();
|
||||||
if (const TextEdit edit(jsonObject); edit.isValid())
|
if (const TextEdit edit(jsonObject); edit.isValid())
|
||||||
editsForDocuments[filePath] << edit;
|
editsForDocuments[filePath] << edit;
|
||||||
else if (const LanguageServerProtocol::CreateFile createFile(jsonObject); createFile.isValid())
|
else if (const CreateFileOperation createFile(jsonObject); createFile.isValid())
|
||||||
changes << createFile;
|
changes << createFile;
|
||||||
else if (const RenameFile renameFile(jsonObject); renameFile.isValid())
|
else if (const RenameFileOperation renameFile(jsonObject); renameFile.isValid())
|
||||||
changes << renameFile;
|
changes << renameFile;
|
||||||
else if (const LanguageServerProtocol::DeleteFile deleteFile(jsonObject); deleteFile.isValid())
|
else if (const DeleteFileOperation deleteFile(jsonObject); deleteFile.isValid())
|
||||||
changes << deleteFile;
|
changes << deleteFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -351,8 +351,8 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
|
|
||||||
if (std::holds_alternative<TextDocumentEdit>(change)) {
|
if (std::holds_alternative<TextDocumentEdit>(change)) {
|
||||||
return applyTextDocumentEdit(client, std::get<TextDocumentEdit>(change));
|
return applyTextDocumentEdit(client, std::get<TextDocumentEdit>(change));
|
||||||
} else if (std::holds_alternative<LanguageServerProtocol::CreateFile>(change)) {
|
} else if (std::holds_alternative<CreateFileOperation>(change)) {
|
||||||
const auto createOperation = std::get<LanguageServerProtocol::CreateFile>(change);
|
const auto createOperation = std::get<CreateFileOperation>(change);
|
||||||
const FilePath filePath = createOperation.uri().toFilePath(client->hostPathMapper());
|
const FilePath filePath = createOperation.uri().toFilePath(client->hostPathMapper());
|
||||||
if (filePath.exists()) {
|
if (filePath.exists()) {
|
||||||
if (const std::optional<CreateFileOptions> options = createOperation.options()) {
|
if (const std::optional<CreateFileOptions> options = createOperation.options()) {
|
||||||
@@ -365,8 +365,8 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filePath.ensureExistingFile();
|
return filePath.ensureExistingFile();
|
||||||
} else if (std::holds_alternative<RenameFile>(change)) {
|
} else if (std::holds_alternative<RenameFileOperation>(change)) {
|
||||||
const RenameFile renameOperation = std::get<RenameFile>(change);
|
const RenameFileOperation renameOperation = std::get<RenameFileOperation>(change);
|
||||||
const FilePath oldPath = renameOperation.oldUri().toFilePath(client->hostPathMapper());
|
const FilePath oldPath = renameOperation.oldUri().toFilePath(client->hostPathMapper());
|
||||||
if (!oldPath.exists())
|
if (!oldPath.exists())
|
||||||
return false;
|
return false;
|
||||||
@@ -384,8 +384,8 @@ bool applyDocumentChange(const Client *client, const DocumentChange &change)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return oldPath.renameFile(newPath);
|
return oldPath.renameFile(newPath);
|
||||||
} else if (std::holds_alternative<LanguageServerProtocol::DeleteFile>(change)) {
|
} else if (std::holds_alternative<DeleteFileOperation>(change)) {
|
||||||
const auto deleteOperation = std::get<LanguageServerProtocol::DeleteFile>(change);
|
const auto deleteOperation = std::get<DeleteFileOperation>(change);
|
||||||
const FilePath filePath = deleteOperation.uri().toFilePath(client->hostPathMapper());
|
const FilePath filePath = deleteOperation.uri().toFilePath(client->hostPathMapper());
|
||||||
if (const std::optional<DeleteFileOptions> options = deleteOperation.options()) {
|
if (const std::optional<DeleteFileOptions> options = deleteOperation.options()) {
|
||||||
if (!filePath.exists())
|
if (!filePath.exists())
|
||||||
|
Reference in New Issue
Block a user