Bug 72692 - code completion fails when there are c++ style comments containing . or ->
Summary: code completion fails when there are c++ style comments containing . or ->
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Code completion (show other bugs)
Version: 3.0.0b2
Platform: Mandrake RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
: 78255 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-01-15 15:01 UTC by Robert Jonsson
Modified: 2005-03-09 23:29 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Jonsson 2004-01-15 15:01:28 UTC
Version:           3.0.0b2 (using KDE 3.1.3)
Installed from:    Mandrake Linux Cooker i586 - Cooker
Compiler:          gcc version 3.3.1 (Mandrake Linux 9.2 3.3.1-2mdk)
OS:          Linux (i686) release 2.4.22-10mdk

I'm having trouble from time to time with kdevelop refusing to complete code. Just now I think I found one issue, I suspect there are others.

It seems the completion parses comments, but only C++ style comments. If I add a . or a -> to the comment line then auto-completion won't work on the line below.

oh, the completion is for code in the project, not from persistant class store, in case there is a difference.
Comment 1 Robert Jonsson 2004-01-15 15:03:12 UTC
Oh, forgot to mention, the . or -> has to be placed last on the line.
Comment 2 Diederik van der Boor 2004-10-21 18:05:04 UTC
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.
Comment 3 Adam Treat 2005-03-09 06:00:17 UTC
*** Bug 78255 has been marked as a duplicate of this bug. ***
Comment 4 Adam Treat 2005-03-09 23:29:00 UTC
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;
Comment 5 Adam Treat 2005-03-09 23:29:00 UTC
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;