Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/codecompletion/context.cpp
Show All 35 Lines | |||||
36 | #include <language/duchain/classdeclaration.h> | 36 | #include <language/duchain/classdeclaration.h> | ||
37 | #include <language/duchain/duchainutils.h> | 37 | #include <language/duchain/duchainutils.h> | ||
38 | #include <language/duchain/persistentsymboltable.h> | 38 | #include <language/duchain/persistentsymboltable.h> | ||
39 | #include <language/duchain/types/integraltype.h> | 39 | #include <language/duchain/types/integraltype.h> | ||
40 | #include <language/duchain/types/functiontype.h> | 40 | #include <language/duchain/types/functiontype.h> | ||
41 | #include <language/duchain/types/pointertype.h> | 41 | #include <language/duchain/types/pointertype.h> | ||
42 | #include <language/duchain/types/typealiastype.h> | 42 | #include <language/duchain/types/typealiastype.h> | ||
43 | #include <language/duchain/types/typeutils.h> | 43 | #include <language/duchain/types/typeutils.h> | ||
44 | #include <language/duchain/stringhelpers.h> | ||||
44 | #include <language/codecompletion/codecompletionmodel.h> | 45 | #include <language/codecompletion/codecompletionmodel.h> | ||
45 | #include <language/codecompletion/normaldeclarationcompletionitem.h> | 46 | #include <language/codecompletion/normaldeclarationcompletionitem.h> | ||
46 | #include <util/foregroundlock.h> | 47 | #include <util/foregroundlock.h> | ||
47 | #include <qtcompat_p.h> | 48 | #include <qtcompat_p.h> | ||
48 | 49 | | |||
49 | #include "../util/clangdebug.h" | 50 | #include "../util/clangdebug.h" | ||
50 | #include "../util/clangtypes.h" | 51 | #include "../util/clangtypes.h" | ||
51 | #include "../util/clangutils.h" | 52 | #include "../util/clangutils.h" | ||
52 | #include "../duchain/clangdiagnosticevaluator.h" | 53 | #include "../duchain/clangdiagnosticevaluator.h" | ||
53 | #include "../duchain/parsesession.h" | 54 | #include "../duchain/parsesession.h" | ||
54 | #include "../duchain/duchainutils.h" | 55 | #include "../duchain/duchainutils.h" | ||
55 | #include "../duchain/navigationwidget.h" | 56 | #include "../duchain/navigationwidget.h" | ||
56 | #include "../clangsettings/clangsettingsmanager.h" | 57 | #include "../clangsettings/clangsettingsmanager.h" | ||
57 | 58 | | |||
59 | #include <algorithm> | ||||
58 | #include <functional> | 60 | #include <functional> | ||
59 | #include <memory> | 61 | #include <memory> | ||
60 | 62 | | |||
61 | #include <KTextEditor/Document> | 63 | #include <KTextEditor/Document> | ||
62 | #include <KTextEditor/View> | 64 | #include <KTextEditor/View> | ||
63 | 65 | | |||
64 | using namespace KDevelop; | 66 | using namespace KDevelop; | ||
65 | 67 | | |||
Show All 34 Lines | 73 | enum CodeCompletionPriority { | |||
100 | /// Priority for a preprocessor macro. | 102 | /// Priority for a preprocessor macro. | ||
101 | CCP_Macro = 70, | 103 | CCP_Macro = 70, | ||
102 | /// Priority for a nested-name-specifier. | 104 | /// Priority for a nested-name-specifier. | ||
103 | CCP_NestedNameSpecifier = 75, | 105 | CCP_NestedNameSpecifier = 75, | ||
104 | /// Priority for a result that isn't likely to be what the user wants, but is included for completeness. | 106 | /// Priority for a result that isn't likely to be what the user wants, but is included for completeness. | ||
105 | CCP_Unlikely = 80 | 107 | CCP_Unlikely = 80 | ||
106 | }; | 108 | }; | ||
107 | 109 | | |||
108 | /** | 110 | /** | ||
mwolff: please move this to stringhelpers.h/cpp in kdevplatform/language/duchain, call it… | |||||
109 | * Common base class for Clang code completion items. | 111 | * Common base class for Clang code completion items. | ||
110 | */ | 112 | */ | ||
111 | template<class Base> | 113 | template<class Base> | ||
mwolff: this should return `midRef` | |||||
112 | class CompletionItem : public Base | 114 | class CompletionItem : public Base | ||
113 | { | 115 | { | ||
114 | public: | 116 | public: | ||
115 | CompletionItem(const QString& display, const QString& prefix) | 117 | CompletionItem(const QString& display, const QString& prefix) | ||
116 | : Base() | 118 | : Base() | ||
117 | , m_display(display) | 119 | , m_display(display) | ||
118 | , m_prefix(prefix) | 120 | , m_prefix(prefix) | ||
119 | , m_unimportant(false) | 121 | , m_unimportant(false) | ||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Line(s) | 334 | if (index.column() == CodeCompletionModel::Arguments) { | |||
333 | // our display string already contains the arguments | 335 | // our display string already contains the arguments | ||
334 | return {}; | 336 | return {}; | ||
335 | } | 337 | } | ||
336 | return DeclarationItem::data(index, role, model); | 338 | return DeclarationItem::data(index, role, model); | ||
337 | } | 339 | } | ||
338 | 340 | | |||
339 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | 341 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | ||
340 | { | 342 | { | ||
341 | view->document()->replaceText(word, m_replacement); | 343 | auto* const document = view->document(); | ||
344 | | ||||
345 | // 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… | |||||
346 | const QString leading = document->line(word.end().line()).left(word.end().column()); | ||||
347 | const QString leadingNoSpace = removeWhitespace(leading); | ||||
348 | if (!leadingNoSpace.isEmpty() && (removeWhitespace(m_display).startsWith(leadingNoSpace) | ||||
349 | || removeWhitespace(m_replacement).startsWith(leadingNoSpace))) { | ||||
350 | const int removeSize = leading.end() - std::find_if_not(leading.begin(), leading.end(), | ||||
351 | [](QChar c){ return c.isSpace(); }); | ||||
352 | const KTextEditor::Cursor newStart = {word.end().line(), word.end().column() - removeSize}; | ||||
353 | document->replaceText({newStart, word.end()}, m_replacement); | ||||
354 | } else { | ||||
355 | document->replaceText(word, m_replacement); | ||||
356 | } | ||||
mwolff: `const auto* document = `
| |||||
342 | } | 357 | } | ||
343 | }; | 358 | }; | ||
344 | 359 | | |||
345 | class ArgumentHintItem : public DeclarationItem | 360 | class ArgumentHintItem : public DeclarationItem | ||
346 | { | 361 | { | ||
347 | public: | 362 | public: | ||
348 | struct CurrentArgumentRange | 363 | struct CurrentArgumentRange | ||
349 | { | 364 | { | ||
▲ 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