forked from qt-creator/qt-creator
Ported global completion to use the new LookupContext.
This commit is contained in:
@@ -767,11 +767,18 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
typeOfExpression.init(thisDocument, snapshot);
|
typeOfExpression.init(thisDocument, snapshot);
|
||||||
Symbol *lastVisibleSymbol = thisDocument->lastVisibleSymbolAt(line, column);
|
|
||||||
|
Scope *scope = thisDocument->scopeAt(line, column);
|
||||||
|
Q_ASSERT(scope != 0);
|
||||||
|
|
||||||
if (expression.isEmpty()) {
|
if (expression.isEmpty()) {
|
||||||
if (m_completionOperator == T_EOF_SYMBOL || m_completionOperator == T_COLON_COLON)
|
if (m_completionOperator == T_EOF_SYMBOL || m_completionOperator == T_COLON_COLON) {
|
||||||
return globalCompletion(lastVisibleSymbol, thisDocument, snapshot);
|
(void) typeOfExpression(expression, scope);
|
||||||
|
globalCompletion(scope);
|
||||||
|
if (m_completions.isEmpty())
|
||||||
|
return -1;
|
||||||
|
return m_startPosition;
|
||||||
|
}
|
||||||
|
|
||||||
else if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) {
|
else if (m_completionOperator == T_SIGNAL || m_completionOperator == T_SLOT) {
|
||||||
// Apply signal/slot completion on 'this'
|
// Apply signal/slot completion on 'this'
|
||||||
@@ -779,9 +786,6 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope *scope = thisDocument->scopeAt(line, column);
|
|
||||||
Q_ASSERT(scope != 0);
|
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "scope:" << scope->owner()->fileName() << scope->owner()->line() << scope->owner()->column();
|
qDebug() << "scope:" << scope->owner()->fileName() << scope->owner()->line() << scope->owner()->column();
|
||||||
|
|
||||||
@@ -871,26 +875,69 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CppCodeCompletion::globalCompletion(Symbol *lastVisibleSymbol,
|
void CppCodeCompletion::globalCompletion(Scope *currentScope)
|
||||||
Document::Ptr thisDocument,
|
|
||||||
const Snapshot &snapshot)
|
|
||||||
{
|
{
|
||||||
if (m_completionOperator == T_EOF_SYMBOL) {
|
const LookupContext &context = typeOfExpression.context();
|
||||||
addKeywords();
|
|
||||||
addMacros(thisDocument->fileName(), snapshot);
|
if (m_completionOperator == T_COLON_COLON) {
|
||||||
|
completeNamespace(context.globalNamespace());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Ptr exprDoc = Document::create(QLatin1String("<expression>"));
|
addKeywords();
|
||||||
const DeprecatedLookupContext context(lastVisibleSymbol, exprDoc, thisDocument, snapshot);
|
addMacros(context.thisDocument()->fileName(), context.snapshot());
|
||||||
const QList<Scope *> scopes = context.expand(context.visibleScopes());
|
|
||||||
|
|
||||||
foreach (Scope *scope, scopes) {
|
QList<ClassOrNamespace *> usingBindings;
|
||||||
for (unsigned i = 0; i < scope->symbolCount(); ++i) {
|
ClassOrNamespace *currentBinding = 0;
|
||||||
addCompletionItem(scope->symbolAt(i));
|
|
||||||
|
for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) {
|
||||||
|
if (scope->isBlockScope()) {
|
||||||
|
if (ClassOrNamespace *binding = context.lookupType(scope->owner())) {
|
||||||
|
for (unsigned i = 0; i < scope->symbolCount(); ++i) {
|
||||||
|
Symbol *member = scope->symbolAt(i);
|
||||||
|
if (! member->name())
|
||||||
|
continue;
|
||||||
|
else if (UsingNamespaceDirective *u = member->asUsingNamespaceDirective()) {
|
||||||
|
if (ClassOrNamespace *b = binding->lookupType(u->name()))
|
||||||
|
usingBindings.append(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (scope->isFunctionScope() || scope->isClassScope() || scope->isNamespaceScope()) {
|
||||||
|
currentBinding = context.lookupType(scope->owner());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_startPosition;
|
for (; currentBinding; currentBinding = currentBinding->parent()) {
|
||||||
|
const QList<Symbol *> symbols = currentBinding->symbols();
|
||||||
|
|
||||||
|
if (! symbols.isEmpty()) {
|
||||||
|
if (symbols.first()->isNamespace())
|
||||||
|
completeNamespace(currentBinding);
|
||||||
|
else
|
||||||
|
completeClass(currentBinding, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ClassOrNamespace *b, usingBindings)
|
||||||
|
completeNamespace(b);
|
||||||
|
|
||||||
|
for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) {
|
||||||
|
if (scope->isBlockScope()) {
|
||||||
|
for (unsigned i = 0; i < scope->symbolCount(); ++i) {
|
||||||
|
addCompletionItem(scope->symbolAt(i));
|
||||||
|
}
|
||||||
|
} else if (scope->isFunctionScope()) {
|
||||||
|
Scope *arguments = scope->owner()->asFunction()->arguments();
|
||||||
|
for (unsigned i = 0; i < arguments->symbolCount(); ++i) {
|
||||||
|
addCompletionItem(arguments->symbolAt(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results,
|
bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results,
|
||||||
@@ -1508,6 +1555,9 @@ bool CppCodeCompletion::completeQtMethod(const QList<LookupItem> &results,
|
|||||||
void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completions)
|
void CppCodeCompletion::completions(QList<TextEditor::CompletionItem> *completions)
|
||||||
{
|
{
|
||||||
const int length = m_editor->position() - m_startPosition;
|
const int length = m_editor->position() - m_startPosition;
|
||||||
|
if (length < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
const QString key = m_editor->textAt(m_startPosition, length);
|
const QString key = m_editor->textAt(m_startPosition, length);
|
||||||
|
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
|
|||||||
@@ -96,9 +96,7 @@ private:
|
|||||||
bool completeInclude(const QTextCursor &cursor);
|
bool completeInclude(const QTextCursor &cursor);
|
||||||
void completePreprocessor();
|
void completePreprocessor();
|
||||||
|
|
||||||
int globalCompletion(CPlusPlus::Symbol *lastVisibleSymbol,
|
void globalCompletion(CPlusPlus::Scope *scope);
|
||||||
CPlusPlus::Document::Ptr thisDocument,
|
|
||||||
const CPlusPlus::Snapshot &snapshot);
|
|
||||||
|
|
||||||
bool completeConstructorOrFunction(const QList<CPlusPlus::LookupItem> &results,
|
bool completeConstructorOrFunction(const QList<CPlusPlus::LookupItem> &results,
|
||||||
int endOfExpression, bool toolTipOnly);
|
int endOfExpression, bool toolTipOnly);
|
||||||
|
|||||||
Reference in New Issue
Block a user