Browse Source

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

xdg
eidheim 5 years ago
parent
commit
f853ae9d08
  1. 15
      src/source.hpp
  2. 8
      src/source_language_protocol.cpp
  3. 2
      src/source_language_protocol.hpp

15
src/source.hpp

@ -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_)) {} 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(); } operator bool() const { return !file_path.empty(); }
bool operator<(const Offset &rhs) const { 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); } 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 source;
std::string path; std::string path;
std::pair<Offset, Offset> offsets; 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 { class View : public SpellCheckView, public DiffView {

8
src/source_language_protocol.cpp

@ -1038,8 +1038,8 @@ void Source::LanguageProtocolView::update_diagnostics_async(std::vector<Language
for(auto &diagnostic : diagnostics) { for(auto &diagnostic : diagnostics) {
for(auto &quickfix_diagnostic : quickfix_diagnostics) { for(auto &quickfix_diagnostic : quickfix_diagnostics) {
if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) { if(diagnostic.message == quickfix_diagnostic.message && diagnostic.range == quickfix_diagnostic.range) {
auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{}); auto pair = diagnostic.quickfixes.emplace(title, std::set<Source::FixIt>{});
pair.first->second.emplace_back( pair.first->second.emplace(
edit.new_text, edit.new_text,
filesystem::get_path_from_uri(file_it->first).string(), filesystem::get_path_from_uri(file_it->first).string(),
std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character), 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 else { // Workaround for language server that does not report quickfix diagnostics
for(auto &diagnostic : diagnostics) { for(auto &diagnostic : diagnostics) {
if(edit.range.start.line == diagnostic.range.start.line) { if(edit.range.start.line == diagnostic.range.start.line) {
auto pair = diagnostic.quickfixes.emplace(title, std::vector<Source::FixIt>{}); auto pair = diagnostic.quickfixes.emplace(title, std::set<Source::FixIt>{});
pair.first->second.emplace_back( pair.first->second.emplace(
edit.new_text, edit.new_text,
filesystem::get_path_from_uri(file_it->first).string(), filesystem::get_path_from_uri(file_it->first).string(),
std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character), std::make_pair<Offset, Offset>(Offset(edit.range.start.line, edit.range.start.character),

2
src/source_language_protocol.hpp

@ -71,7 +71,7 @@ namespace LanguageProtocol {
Range range; Range range;
int severity; int severity;
std::vector<RelatedInformation> related_informations; 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 { class TextEdit {

Loading…
Cancel
Save