Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
040e2a30
Commit
040e2a30
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Ported global completion to use the new LookupContext.
parent
65780999
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/plugins/cpptools/cppcodecompletion.cpp
+69
-19
69 additions, 19 deletions
src/plugins/cpptools/cppcodecompletion.cpp
src/plugins/cpptools/cppcodecompletion.h
+1
-3
1 addition, 3 deletions
src/plugins/cpptools/cppcodecompletion.h
with
70 additions
and
22 deletions
src/plugins/cpptools/cppcodecompletion.cpp
+
69
−
19
View file @
040e2a30
...
...
@@ -767,11 +767,18 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
return
-
1
;
typeOfExpression
.
init
(
thisDocument
,
snapshot
);
Symbol
*
lastVisibleSymbol
=
thisDocument
->
lastVisibleSymbolAt
(
line
,
column
);
Scope
*
scope
=
thisDocument
->
scopeAt
(
line
,
column
);
Q_ASSERT
(
scope
!=
0
);
if
(
expression
.
isEmpty
())
{
if
(
m_completionOperator
==
T_EOF_SYMBOL
||
m_completionOperator
==
T_COLON_COLON
)
return
globalCompletion
(
lastVisibleSymbol
,
thisDocument
,
snapshot
);
if
(
m_completionOperator
==
T_EOF_SYMBOL
||
m_completionOperator
==
T_COLON_COLON
)
{
(
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
)
{
// 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
)
qDebug
()
<<
"scope:"
<<
scope
->
owner
()
->
fileName
()
<<
scope
->
owner
()
->
line
()
<<
scope
->
owner
()
->
column
();
...
...
@@ -871,26 +875,69 @@ int CppCodeCompletion::startCompletionInternal(TextEditor::BaseTextEditor *edit,
return
-
1
;
}
int
CppCodeCompletion
::
globalCompletion
(
Symbol
*
lastVisibleSymbol
,
Document
::
Ptr
thisDocument
,
const
Snapshot
&
snapshot
)
void
CppCodeCompletion
::
globalCompletion
(
Scope
*
currentScope
)
{
if
(
m_completionOperator
==
T_EOF_SYMBOL
)
{
addKeywords
();
addMacros
(
thisDocument
->
fileName
(),
snapshot
);
const
LookupContext
&
context
=
typeOfExpression
.
context
();
if
(
m_completionOperator
==
T_COLON_COLON
)
{
completeNamespace
(
context
.
globalNamespace
());
return
;
}
Document
::
Ptr
exprDoc
=
Document
::
create
(
QLatin1String
(
"<expression>"
));
const
DeprecatedLookupContext
context
(
lastVisibleSymbol
,
exprDoc
,
thisDocument
,
snapshot
);
const
QList
<
Scope
*>
scopes
=
context
.
expand
(
context
.
visibleScopes
());
addKeywords
();
addMacros
(
context
.
thisDocument
()
->
fileName
(),
context
.
snapshot
());
QList
<
ClassOrNamespace
*>
usingBindings
;
ClassOrNamespace
*
currentBinding
=
0
;
foreach
(
Scope
*
scope
,
scopes
)
{
for
(
unsigned
i
=
0
;
i
<
scope
->
symbolCount
();
++
i
)
{
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
;
}
}
for
(;
currentBinding
;
currentBinding
=
currentBinding
->
parent
())
{
const
QList
<
Symbol
*>
symbols
=
currentBinding
->
symbols
();
if
(
!
symbols
.
isEmpty
())
{
if
(
symbols
.
first
()
->
isNamespace
())
completeNamespace
(
currentBinding
);
else
completeClass
(
currentBinding
,
false
);
}
}
return
m_startPosition
;
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
,
...
...
@@ -1508,6 +1555,9 @@ bool CppCodeCompletion::completeQtMethod(const QList<LookupItem> &results,
void
CppCodeCompletion
::
completions
(
QList
<
TextEditor
::
CompletionItem
>
*
completions
)
{
const
int
length
=
m_editor
->
position
()
-
m_startPosition
;
if
(
length
<
0
)
return
;
const
QString
key
=
m_editor
->
textAt
(
m_startPosition
,
length
);
if
(
length
==
0
)
...
...
This diff is collapsed.
Click to expand it.
src/plugins/cpptools/cppcodecompletion.h
+
1
−
3
View file @
040e2a30
...
...
@@ -96,9 +96,7 @@ private:
bool
completeInclude
(
const
QTextCursor
&
cursor
);
void
completePreprocessor
();
int
globalCompletion
(
CPlusPlus
::
Symbol
*
lastVisibleSymbol
,
CPlusPlus
::
Document
::
Ptr
thisDocument
,
const
CPlusPlus
::
Snapshot
&
snapshot
);
void
globalCompletion
(
CPlusPlus
::
Scope
*
scope
);
bool
completeConstructorOrFunction
(
const
QList
<
CPlusPlus
::
LookupItem
>
&
results
,
int
endOfExpression
,
bool
toolTipOnly
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment