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:
@@ -43,6 +43,7 @@ namespace ClangCodeModel {
|
||||
namespace Internal {
|
||||
|
||||
using ClangBackEnd::CodeCompletions;
|
||||
using ClangBackEnd::CompletionCorrection;
|
||||
|
||||
class ClangCompletionAssistProcessor : public CppTools::CppCompletionAssistProcessor
|
||||
{
|
||||
@@ -54,7 +55,8 @@ public:
|
||||
|
||||
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
||||
|
||||
bool handleAvailableAsyncCompletions(const CodeCompletions &completions);
|
||||
bool handleAvailableAsyncCompletions(const CodeCompletions &completions,
|
||||
CompletionCorrection neededCorrection);
|
||||
|
||||
const TextEditor::TextEditorWidget *textEditorWidget() const;
|
||||
|
||||
@@ -64,7 +66,8 @@ private:
|
||||
int findStartOfName(int pos = -1) const;
|
||||
bool accepts() const;
|
||||
|
||||
TextEditor::IAssistProposal *createProposal() const;
|
||||
TextEditor::IAssistProposal *createProposal(
|
||||
CompletionCorrection neededCorrection = CompletionCorrection::NoCorrection) const;
|
||||
|
||||
bool completeInclude(const QTextCursor &cursor);
|
||||
bool completeInclude(int position);
|
||||
@@ -85,7 +88,8 @@ private:
|
||||
void sendFileContent(const QByteArray &customFileContent);
|
||||
bool sendCompletionRequest(int position, const QByteArray &customFileContent);
|
||||
|
||||
void handleAvailableCompletions(const CodeCompletions &completions);
|
||||
void handleAvailableCompletions(const CodeCompletions &completions,
|
||||
CompletionCorrection neededCorrection);
|
||||
bool handleAvailableFunctionHintCompletions(const CodeCompletions &completions);
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user