Commit f853ae9d authored by Ole Christian Eidheim's avatar Ole Christian Eidheim
Browse files

Language client: workaround for buggy language servers that report double equal codeAction edits

parent 5d06b6fd
Pipeline #238065313 passed with stages
in 17 minutes and 13 seconds
......@@ -30,7 +30,9 @@ namespace Source {
Offset(unsigned line, unsigned index, boost::filesystem::path file_path_ = {}) : line(line), index(index), file_path(std::move(file_path_)) {}
operator bool() const { return !file_path.empty(); }
bool operator<(const Offset &rhs) const {
return file_path < rhs.file_path || (file_path == rhs.file_path && (line < rhs.line || (line == rhs.line && index < rhs.index)));
return file_path < rhs.file_path ||
(file_path == rhs.file_path && (line < rhs.line ||
(line == rhs.line && index < rhs.index)));
}
bool operator==(const Offset &rhs) const { return (file_path == rhs.file_path && line == rhs.line && index == rhs.index); }
......@@ -55,6 +57,17 @@ namespace Source {
std::string source;
std::string path;
std::pair<Offset, Offset> offsets;
bool operator<(const FixIt &rhs) const {
return type < rhs.type ||
(type == rhs.type && (source < rhs.source ||
(source == rhs.source && (path < rhs.path ||
(path == rhs.path && offsets < rhs.offsets)))));
}
bool operator==(const FixIt &rhs) const {
return type == rhs.type && source == rhs.source && path == rhs.path && offsets == rhs.offsets;
}
};
class View : public SpellCheckView, public DiffView {
......
......@@ -1038,8 +1038,8 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
for(auto &diagnostic : diagnostics) {
for(auto &quickfix_diagnostic : quickfix_diagnostics) {
if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) {
auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{});
pair.first->second.emplace_back(
auto pair = diagnostic.quickfixes.emplace(title, std::set<Source::FixIt>{});
pair.first->second.emplace(
edit.new_text,
filesystem::get_path_from_uri(file_it->first).string(),
std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character),
......@@ -1052,8 +1052,8 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
else { // Workaround for language server that does not report quickfix diagnostics
for(auto &diagnostic : diagnostics) {
if(edit.range.start.line == diagnostic.range.start.line) {
auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{});
pair.first->second.emplace_back(
auto pair = diagnostic.quickfixes.emplace(title, std::set<Source::FixIt>{});
pair.first->second.emplace(
edit.new_text,
filesystem::get_path_from_uri(file_it->first).string(),
std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character),
......
......@@ -71,7 +71,7 @@ namespace LanguageProtocol {
Range range;
int severity;
std::vector<RelatedInformation> related_informations;
std::map<std::string, std::vector<Source::FixIt>> quickfixes;
std::map<std::string, std::set<Source::FixIt>> quickfixes;
};
class TextEdit {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment