Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/codecompletion/context.cpp
Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | |||||
50 | #include "../util/clangtypes.h" | 50 | #include "../util/clangtypes.h" | ||
51 | #include "../util/clangutils.h" | 51 | #include "../util/clangutils.h" | ||
52 | #include "../duchain/clangdiagnosticevaluator.h" | 52 | #include "../duchain/clangdiagnosticevaluator.h" | ||
53 | #include "../duchain/parsesession.h" | 53 | #include "../duchain/parsesession.h" | ||
54 | #include "../duchain/duchainutils.h" | 54 | #include "../duchain/duchainutils.h" | ||
55 | #include "../duchain/navigationwidget.h" | 55 | #include "../duchain/navigationwidget.h" | ||
56 | #include "../clangsettings/clangsettingsmanager.h" | 56 | #include "../clangsettings/clangsettingsmanager.h" | ||
57 | 57 | | |||
58 | #include <algorithm> | ||||
58 | #include <functional> | 59 | #include <functional> | ||
59 | #include <memory> | 60 | #include <memory> | ||
60 | 61 | | |||
61 | #include <KTextEditor/Document> | 62 | #include <KTextEditor/Document> | ||
62 | #include <KTextEditor/View> | 63 | #include <KTextEditor/View> | ||
63 | 64 | | |||
64 | using namespace KDevelop; | 65 | using namespace KDevelop; | ||
65 | 66 | | |||
Show All 34 Lines | 72 | enum CodeCompletionPriority { | |||
100 | /// Priority for a preprocessor macro. | 101 | /// Priority for a preprocessor macro. | ||
101 | CCP_Macro = 70, | 102 | CCP_Macro = 70, | ||
102 | /// Priority for a nested-name-specifier. | 103 | /// Priority for a nested-name-specifier. | ||
103 | CCP_NestedNameSpecifier = 75, | 104 | CCP_NestedNameSpecifier = 75, | ||
104 | /// Priority for a result that isn't likely to be what the user wants, but is included for completeness. | 105 | /// Priority for a result that isn't likely to be what the user wants, but is included for completeness. | ||
105 | CCP_Unlikely = 80 | 106 | CCP_Unlikely = 80 | ||
106 | }; | 107 | }; | ||
107 | 108 | | |||
109 | QStringRef trimLeft(const QStringRef string) { | ||||
mwolff: please move this to stringhelpers.h/cpp in kdevplatform/language/duchain, call it… | |||||
110 | const int position = std::find_if_not(string.begin(), string.end(), | ||||
111 | [](QChar c){ return c.isSpace(); }) - string.begin(); | ||||
112 | return string.mid(position); | ||||
mwolff: this should return `midRef` | |||||
113 | } | ||||
114 | | ||||
108 | /** | 115 | /** | ||
109 | * Common base class for Clang code completion items. | 116 | * Common base class for Clang code completion items. | ||
110 | */ | 117 | */ | ||
111 | template<class Base> | 118 | template<class Base> | ||
112 | class CompletionItem : public Base | 119 | class CompletionItem : public Base | ||
113 | { | 120 | { | ||
114 | public: | 121 | public: | ||
115 | CompletionItem(const QString& display, const QString& prefix) | 122 | CompletionItem(const QString& display, const QString& prefix) | ||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Line(s) | 339 | if (index.column() == CodeCompletionModel::Arguments) { | |||
333 | // our display string already contains the arguments | 340 | // our display string already contains the arguments | ||
334 | return {}; | 341 | return {}; | ||
335 | } | 342 | } | ||
336 | return DeclarationItem::data(index, role, model); | 343 | return DeclarationItem::data(index, role, model); | ||
337 | } | 344 | } | ||
338 | 345 | | |||
339 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | 346 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | ||
340 | { | 347 | { | ||
341 | view->document()->replaceText(word, m_replacement); | 348 | KTextEditor::Document* const document = view->document(); | ||
mwolff: `const auto* document = `
| |||||
349 | | ||||
350 | // try and replace leading typed text that match the proposed implementation | ||||
I agree that we should integrate this proposed feature for now, but want to mention that it can easily fail. Most notably, it will fail when
but as I said, your new behavior is already better than before, we can improve it later as needed mwolff: I agree that we should integrate this proposed feature for now, but want to mention that it can… | |||||
351 | const QStringRef leading = trimLeft(document->line(word.end().line()).leftRef(word.end().column())); | ||||
352 | if (!leading.isEmpty() && (m_display.startsWith(leading) || m_replacement.startsWith(leading))) { | ||||
353 | const KTextEditor::Cursor newStart = {word.end().line(), word.end().column() - leading.size()}; | ||||
354 | document->replaceText({newStart, word.end()}, m_replacement); | ||||
355 | } else { | ||||
356 | document->replaceText(word, m_replacement); | ||||
357 | } | ||||
342 | } | 358 | } | ||
343 | }; | 359 | }; | ||
344 | 360 | | |||
345 | class ArgumentHintItem : public DeclarationItem | 361 | class ArgumentHintItem : public DeclarationItem | ||
346 | { | 362 | { | ||
347 | public: | 363 | public: | ||
348 | struct CurrentArgumentRange | 364 | struct CurrentArgumentRange | ||
349 | { | 365 | { | ||
▲ Show 20 Lines • Show All 958 Lines • Show Last 20 Lines |
please move this to stringhelpers.h/cpp in kdevplatform/language/duchain, call it stripLeadingWhitespace or similar