forked from qt-creator/qt-creator
Clang: Correct member access operator if possible
1 struct Foo { int member; };
2 void f(Foo *foo)
3 {
4 foo.<REQUEST COMPLETION> // correct '.' to '->' and provide results
5 }
The preferred approach would be to check if "foo" in line 4 is of
pointer type, but there is no suitable cursor (only CompoundStmt) at
that position since the code is usually not yet parsed and thus invalid.
Thus, just run the completion as is. If there are not any results for a
dot completion, re-run the completion with "." exchanged by "->". This
approach is inherently slower than the preferred approach implemented in
the built-in code model.
The following rare cases are not handled:
1) Requesting completion after white space:
Works: foo.<COMPLETE HERE>
Fails: foo. <COMPLETE HERE>
2) Opening a file and requesting completion (ctrl+space) without prior
editing. No editing before triggering completion means that no
unsaved file is generated on the backend side, which is a
requirement for the correction.
Task-number: QTCREATORBUG-11581
Change-Id: I6bc8e8594778774ab342755fdb01a8a3e5c52ba0
Reviewed-by: Marco Bubke <marco.bubke@theqtcompany.com>
This commit is contained in:
@@ -78,5 +78,11 @@ enum class HighlightingType
|
||||
OutputArgument
|
||||
};
|
||||
|
||||
enum class CompletionCorrection
|
||||
{
|
||||
NoCorrection,
|
||||
DotToArrowCorrection
|
||||
};
|
||||
|
||||
}
|
||||
#endif // CLANGBACKENDIPC_GLOBAL_H
|
||||
|
||||
@@ -37,9 +37,12 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
CodeCompletedMessage::CodeCompletedMessage(const CodeCompletions &codeCompletions, quint64 ticketNumber)
|
||||
CodeCompletedMessage::CodeCompletedMessage(const CodeCompletions &codeCompletions,
|
||||
CompletionCorrection neededCorrection,
|
||||
quint64 ticketNumber)
|
||||
: codeCompletions_(codeCompletions),
|
||||
ticketNumber_(ticketNumber)
|
||||
ticketNumber_(ticketNumber),
|
||||
neededCorrection_(neededCorrection)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -48,14 +51,25 @@ const CodeCompletions &CodeCompletedMessage::codeCompletions() const
|
||||
return codeCompletions_;
|
||||
}
|
||||
|
||||
CompletionCorrection CodeCompletedMessage::neededCorrection() const
|
||||
{
|
||||
return neededCorrection_;
|
||||
}
|
||||
|
||||
quint64 CodeCompletedMessage::ticketNumber() const
|
||||
{
|
||||
return ticketNumber_;
|
||||
}
|
||||
|
||||
quint32 &CodeCompletedMessage::neededCorrectionAsInt()
|
||||
{
|
||||
return reinterpret_cast<quint32&>(neededCorrection_);
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const CodeCompletedMessage &message)
|
||||
{
|
||||
out << message.codeCompletions_;
|
||||
out << quint32(message.neededCorrection_);
|
||||
out << message.ticketNumber_;
|
||||
|
||||
return out;
|
||||
@@ -64,6 +78,7 @@ QDataStream &operator<<(QDataStream &out, const CodeCompletedMessage &message)
|
||||
QDataStream &operator>>(QDataStream &in, CodeCompletedMessage &message)
|
||||
{
|
||||
in >> message.codeCompletions_;
|
||||
in >> message.neededCorrectionAsInt();
|
||||
in >> message.ticketNumber_;
|
||||
|
||||
return in;
|
||||
@@ -72,7 +87,8 @@ QDataStream &operator>>(QDataStream &in, CodeCompletedMessage &message)
|
||||
bool operator==(const CodeCompletedMessage &first, const CodeCompletedMessage &second)
|
||||
{
|
||||
return first.ticketNumber_ == second.ticketNumber_
|
||||
&& first.codeCompletions_ == second.codeCompletions_;
|
||||
&& first.neededCorrection_ == second.neededCorrection_
|
||||
&& first.codeCompletions_ == second.codeCompletions_;
|
||||
}
|
||||
|
||||
bool operator<(const CodeCompletedMessage &first, const CodeCompletedMessage &second)
|
||||
@@ -80,11 +96,24 @@ bool operator<(const CodeCompletedMessage &first, const CodeCompletedMessage &se
|
||||
return first.ticketNumber_ < second.ticketNumber_;
|
||||
}
|
||||
|
||||
#define RETURN_TEXT_FOR_CASE(enumValue) case CompletionCorrection::enumValue: return #enumValue
|
||||
static const char *completionCorrectionToText(CompletionCorrection correction)
|
||||
{
|
||||
switch (correction) {
|
||||
RETURN_TEXT_FOR_CASE(NoCorrection);
|
||||
RETURN_TEXT_FOR_CASE(DotToArrowCorrection);
|
||||
default: return "UnhandledCompletionCorrection";
|
||||
}
|
||||
}
|
||||
#undef RETURN_TEXT_FOR_CASE
|
||||
|
||||
QDebug operator<<(QDebug debug, const CodeCompletedMessage &message)
|
||||
{
|
||||
debug.nospace() << "CodeCompletedMessage(";
|
||||
|
||||
debug.nospace() << message.codeCompletions_ << ", " << message.ticketNumber_;
|
||||
debug.nospace() << message.codeCompletions_ << ", "
|
||||
<< completionCorrectionToText(message.neededCorrection()) << ", "
|
||||
<< message.ticketNumber_;
|
||||
|
||||
debug.nospace() << ")";
|
||||
|
||||
|
||||
@@ -48,15 +48,22 @@ class CMBIPC_EXPORT CodeCompletedMessage
|
||||
friend void PrintTo(const CodeCompletedMessage &message, ::std::ostream* os);
|
||||
public:
|
||||
CodeCompletedMessage() = default;
|
||||
CodeCompletedMessage(const CodeCompletions &codeCompletions, quint64 ticketNumber);
|
||||
CodeCompletedMessage(const CodeCompletions &codeCompletions,
|
||||
CompletionCorrection neededCorrection,
|
||||
quint64 ticketNumber);
|
||||
|
||||
const CodeCompletions &codeCompletions() const;
|
||||
CompletionCorrection neededCorrection() const;
|
||||
|
||||
quint64 ticketNumber() const;
|
||||
|
||||
private:
|
||||
quint32 &neededCorrectionAsInt();
|
||||
|
||||
private:
|
||||
CodeCompletions codeCompletions_;
|
||||
quint64 ticketNumber_ = 0;
|
||||
CompletionCorrection neededCorrection_ = CompletionCorrection::NoCorrection;
|
||||
};
|
||||
|
||||
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const CodeCompletedMessage &message);
|
||||
|
||||
Reference in New Issue
Block a user