forked from qt-creator/qt-creator
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>
95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
/****************************************************************************
|
|
**
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
** Contact: http://www.qt.io/licensing
|
|
**
|
|
** This file is part of Qt Creator.
|
|
**
|
|
** Commercial License Usage
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
** accordance with the commercial license agreement provided with the
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
**
|
|
** GNU Lesser General Public License Usage
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
** following information to ensure the GNU Lesser General Public License
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
**
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
**
|
|
****************************************************************************/
|
|
|
|
#include "clangcodecompleteresults.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace ClangBackEnd {
|
|
|
|
using std::swap;
|
|
|
|
ClangCodeCompleteResults::ClangCodeCompleteResults(CXCodeCompleteResults *cxCodeCompleteResults)
|
|
: cxCodeCompleteResults(cxCodeCompleteResults)
|
|
{
|
|
}
|
|
|
|
ClangCodeCompleteResults::~ClangCodeCompleteResults()
|
|
{
|
|
clang_disposeCodeCompleteResults(cxCodeCompleteResults);
|
|
}
|
|
|
|
bool ClangCodeCompleteResults::isNull() const
|
|
{
|
|
return cxCodeCompleteResults == nullptr;
|
|
}
|
|
|
|
bool ClangCodeCompleteResults::isEmpty() const
|
|
{
|
|
return cxCodeCompleteResults->NumResults == 0;
|
|
}
|
|
|
|
bool ClangCodeCompleteResults::hasResults() const
|
|
{
|
|
return !isNull() && !isEmpty();
|
|
}
|
|
|
|
bool ClangCodeCompleteResults::hasNoResultsForDotCompletion() const
|
|
{
|
|
return !hasResults() && isDotCompletion();
|
|
}
|
|
|
|
bool ClangCodeCompleteResults::isDotCompletion() const
|
|
{
|
|
const unsigned long long contexts = clang_codeCompleteGetContexts(cxCodeCompleteResults);
|
|
|
|
return contexts & CXCompletionContext_DotMemberAccess;
|
|
}
|
|
|
|
CXCodeCompleteResults *ClangCodeCompleteResults::data() const
|
|
{
|
|
return cxCodeCompleteResults;
|
|
}
|
|
|
|
ClangCodeCompleteResults &ClangCodeCompleteResults::operator=(ClangCodeCompleteResults &&clangCodeCompleteResults)
|
|
{
|
|
swap(cxCodeCompleteResults, clangCodeCompleteResults.cxCodeCompleteResults);
|
|
|
|
return *this;
|
|
}
|
|
|
|
ClangCodeCompleteResults::ClangCodeCompleteResults(ClangCodeCompleteResults &&clangCodeCompleteResults)
|
|
{
|
|
swap(cxCodeCompleteResults, clangCodeCompleteResults.cxCodeCompleteResults);
|
|
}
|
|
|
|
} // namespace ClangBackEnd
|
|
|