| Summary: | code completion fails when there are c++ style comments containing . or -> | ||
|---|---|---|---|
| Product: | [Applications] kdevelop | Reporter: | Robert Jonsson <rj> |
| Component: | Code completion | Assignee: | kdevelop-bugs-null |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | holger-kde |
| Priority: | NOR | ||
| Version First Reported In: | 3.0.0b2 | ||
| Target Milestone: | --- | ||
| Platform: | Mandrake RPMs | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
|
Description
Robert Jonsson
2004-01-15 15:01:28 UTC
Oh, forgot to mention, the . or -> has to be placed last on the line. I've noticed the same thing in KDevelop-3.1.1:
void addFoo(const QString &bar)
{
if(foo)
{
someList_.append( bar ); /* code completion works here */
// A comment with dot.
/* doesn't work here!! */
}
/* works here again */
}
Really weird.
*** Bug 78255 has been marked as a duplicate of this bug. *** CVS commit by treat:
* C++ style comments present issues with finding the expr so I'm
matching for them and replacing them with empty C style comments
of the same length for purposes of finding the expr.
BUGS:72692
CCBUGS:72692
M +1 -1 codeinformationrepository.cpp 1.35
M +30 -3 cppcodecompletion.cpp 1.155
--- kdevelop/languages/cpp/codeinformationrepository.cpp #1.34:1.35
@@ -152,5 +152,5 @@ QValueList<KTextEditor::CompletionEntry>
QValueList<Tag> CodeInformationRepository::getBaseClassList( const QString& className )
{
- kdDebug( 9007 ) << "CodeInformationRepository::getBaseClasseList()" << endl;
+ kdDebug( 9007 ) << "CodeInformationRepository::getBaseClassList()" << endl;
if ( className.isEmpty() )
--- kdevelop/languages/cpp/cppcodecompletion.cpp #1.154:1.155
@@ -463,8 +463,35 @@ void CppCodeCompletion::slotTextChanged(
enum { T_ACCESS, T_PAREN, T_BRACKET, T_IDE, T_UNKNOWN };
-int CppCodeCompletion::expressionAt( const QString& text, int index )
+int CppCodeCompletion::expressionAt( const QString& contents, int index )
{
kdDebug( 9007 ) << k_funcinfo << endl;
+ /* C++ style comments present issues with finding the expr so I'm
+ matching for them and replacing them with empty C style comments
+ of the same length for purposes of finding the expr. */
+
+ QString text = contents;
+ QRegExp rx( "(//([^\n]*)(\n|$)|/\\*.*\\*/|\"([^\\\\]|\\\\.)*\")" );
+ rx.setMinimal( TRUE );
+
+ int pos = 0;
+ while ( (pos = rx.search( text, pos )) != -1 )
+ {
+ if ( rx.cap( 1 ).startsWith( "//" ) )
+ {
+ QString before = rx.cap( 1 );
+ QString after;
+ after.fill(' ', before.length() - 5 );
+ after.prepend( "/*" );
+ after.append( "*/" );
+ text.replace( pos, before.length() - 1, after );
+ pos += after.length();
+ }
+ else
+ {
+ pos += rx.matchedLength();
+ }
+ }
+
int last = T_UNKNOWN;
int start = index;
@@ -840,6 +867,6 @@ void CppCodeCompletion::completeText( )
QString textToReparse = getText( recoveryPoint->startLine, recoveryPoint->startColumn,
line, showArguments ? column - 1 : column );
- //kdDebug(9007) << "-------------> please reparse only text" << endl << textToReparse << endl
- // << "--------------------------------------------" << endl;
+// kdDebug(9007) << "-------------> please reparse only text" << endl << textToReparse << endl
+// << "--------------------------------------------" << endl;
Driver d;
CVS commit by treat:
* C++ style comments present issues with finding the expr so I'm
matching for them and replacing them with empty C style comments
of the same length for purposes of finding the expr.
BUGS:72692
CCBUGS:72692
M +1 -1 codeinformationrepository.cpp 1.35
M +30 -3 cppcodecompletion.cpp 1.155
--- kdevelop/languages/cpp/codeinformationrepository.cpp #1.34:1.35
@@ -152,5 +152,5 @@ QValueList<KTextEditor::CompletionEntry>
QValueList<Tag> CodeInformationRepository::getBaseClassList( const QString& className )
{
- kdDebug( 9007 ) << "CodeInformationRepository::getBaseClasseList()" << endl;
+ kdDebug( 9007 ) << "CodeInformationRepository::getBaseClassList()" << endl;
if ( className.isEmpty() )
--- kdevelop/languages/cpp/cppcodecompletion.cpp #1.154:1.155
@@ -463,8 +463,35 @@ void CppCodeCompletion::slotTextChanged(
enum { T_ACCESS, T_PAREN, T_BRACKET, T_IDE, T_UNKNOWN };
-int CppCodeCompletion::expressionAt( const QString& text, int index )
+int CppCodeCompletion::expressionAt( const QString& contents, int index )
{
kdDebug( 9007 ) << k_funcinfo << endl;
+ /* C++ style comments present issues with finding the expr so I'm
+ matching for them and replacing them with empty C style comments
+ of the same length for purposes of finding the expr. */
+
+ QString text = contents;
+ QRegExp rx( "(//([^\n]*)(\n|$)|/\\*.*\\*/|\"([^\\\\]|\\\\.)*\")" );
+ rx.setMinimal( TRUE );
+
+ int pos = 0;
+ while ( (pos = rx.search( text, pos )) != -1 )
+ {
+ if ( rx.cap( 1 ).startsWith( "//" ) )
+ {
+ QString before = rx.cap( 1 );
+ QString after;
+ after.fill(' ', before.length() - 5 );
+ after.prepend( "/*" );
+ after.append( "*/" );
+ text.replace( pos, before.length() - 1, after );
+ pos += after.length();
+ }
+ else
+ {
+ pos += rx.matchedLength();
+ }
+ }
+
int last = T_UNKNOWN;
int start = index;
@@ -840,6 +867,6 @@ void CppCodeCompletion::completeText( )
QString textToReparse = getText( recoveryPoint->startLine, recoveryPoint->startColumn,
line, showArguments ? column - 1 : column );
- //kdDebug(9007) << "-------------> please reparse only text" << endl << textToReparse << endl
- // << "--------------------------------------------" << endl;
+// kdDebug(9007) << "-------------> please reparse only text" << endl << textToReparse << endl
+// << "--------------------------------------------" << endl;
Driver d;
|