mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-26 01:21:57 +00:00
Move BuildWorkspaceEdit to text_document_rename.cc
This commit is contained in:
parent
2bc44d59f2
commit
64f094d347
@ -2,6 +2,52 @@
|
|||||||
#include "query_utils.h"
|
#include "query_utils.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
|
||||||
|
WorkingFiles* working_files,
|
||||||
|
const std::vector<QueryLocation>& locations,
|
||||||
|
const std::string& new_text) {
|
||||||
|
std::unordered_map<QueryFileId, lsTextDocumentEdit> path_to_edit;
|
||||||
|
|
||||||
|
for (auto& location : locations) {
|
||||||
|
optional<lsLocation> ls_location =
|
||||||
|
GetLsLocation(db, working_files, location);
|
||||||
|
if (!ls_location)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (path_to_edit.find(location.path) == path_to_edit.end()) {
|
||||||
|
path_to_edit[location.path] = lsTextDocumentEdit();
|
||||||
|
|
||||||
|
QueryFile& file = db->files[location.path.id];
|
||||||
|
if (!file.def)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const std::string& path = file.def->path;
|
||||||
|
path_to_edit[location.path].textDocument.uri =
|
||||||
|
lsDocumentUri::FromPath(path);
|
||||||
|
|
||||||
|
WorkingFile* working_file = working_files->GetFileByFilename(path);
|
||||||
|
if (working_file)
|
||||||
|
path_to_edit[location.path].textDocument.version =
|
||||||
|
working_file->version;
|
||||||
|
}
|
||||||
|
|
||||||
|
lsTextEdit edit;
|
||||||
|
edit.range = ls_location->range;
|
||||||
|
edit.newText = new_text;
|
||||||
|
|
||||||
|
// vscode complains if we submit overlapping text edits.
|
||||||
|
auto& edits = path_to_edit[location.path].edits;
|
||||||
|
if (std::find(edits.begin(), edits.end(), edit) == edits.end())
|
||||||
|
edits.push_back(edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
lsWorkspaceEdit edit;
|
||||||
|
for (const auto& changes : path_to_edit)
|
||||||
|
edit.documentChanges.push_back(changes.second);
|
||||||
|
return edit;
|
||||||
|
}
|
||||||
|
|
||||||
struct Ipc_TextDocumentRename : public IpcMessage<Ipc_TextDocumentRename> {
|
struct Ipc_TextDocumentRename : public IpcMessage<Ipc_TextDocumentRename> {
|
||||||
struct Params {
|
struct Params {
|
||||||
// The document to format.
|
// The document to format.
|
||||||
|
@ -470,51 +470,6 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
|
|
||||||
WorkingFiles* working_files,
|
|
||||||
const std::vector<QueryLocation>& locations,
|
|
||||||
const std::string& new_text) {
|
|
||||||
std::unordered_map<QueryFileId, lsTextDocumentEdit> path_to_edit;
|
|
||||||
|
|
||||||
for (auto& location : locations) {
|
|
||||||
optional<lsLocation> ls_location =
|
|
||||||
GetLsLocation(db, working_files, location);
|
|
||||||
if (!ls_location)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (path_to_edit.find(location.path) == path_to_edit.end()) {
|
|
||||||
path_to_edit[location.path] = lsTextDocumentEdit();
|
|
||||||
|
|
||||||
QueryFile& file = db->files[location.path.id];
|
|
||||||
if (!file.def)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
const std::string& path = file.def->path;
|
|
||||||
path_to_edit[location.path].textDocument.uri =
|
|
||||||
lsDocumentUri::FromPath(path);
|
|
||||||
|
|
||||||
WorkingFile* working_file = working_files->GetFileByFilename(path);
|
|
||||||
if (working_file)
|
|
||||||
path_to_edit[location.path].textDocument.version =
|
|
||||||
working_file->version;
|
|
||||||
}
|
|
||||||
|
|
||||||
lsTextEdit edit;
|
|
||||||
edit.range = ls_location->range;
|
|
||||||
edit.newText = new_text;
|
|
||||||
|
|
||||||
// vscode complains if we submit overlapping text edits.
|
|
||||||
auto& edits = path_to_edit[location.path].edits;
|
|
||||||
if (std::find(edits.begin(), edits.end(), edit) == edits.end())
|
|
||||||
edits.push_back(edit);
|
|
||||||
}
|
|
||||||
|
|
||||||
lsWorkspaceEdit edit;
|
|
||||||
for (const auto& changes : path_to_edit)
|
|
||||||
edit.documentChanges.push_back(changes.second);
|
|
||||||
return edit;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
||||||
QueryFile* file,
|
QueryFile* file,
|
||||||
lsPosition position) {
|
lsPosition position) {
|
||||||
|
@ -59,11 +59,6 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
|||||||
SymbolIdx symbol,
|
SymbolIdx symbol,
|
||||||
bool use_short_name);
|
bool use_short_name);
|
||||||
|
|
||||||
lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
|
|
||||||
WorkingFiles* working_files,
|
|
||||||
const std::vector<QueryLocation>& locations,
|
|
||||||
const std::string& new_text);
|
|
||||||
|
|
||||||
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
||||||
QueryFile* file,
|
QueryFile* file,
|
||||||
lsPosition position);
|
lsPosition position);
|
||||||
|
Loading…
Reference in New Issue
Block a user