branches/kdevelop/3.4/languages/cpp

Jens Dagerbo jens.dagerbo at swipnet.se
Sun Jan 28 02:59:02 UTC 2007


SVN commit 627774 by dagerbo:

New stuff: A useful basic type info display system in approx 60 lines of code - why don't we have this already?

CCMAIL: kdevelop-devel at kdevelop.org

 M  +56 -7     cppcodecompletion.cpp  
 M  +2 -0      cppcodecompletion.h  
 M  +10 -0     cppsupportpart.cpp  


--- branches/kdevelop/3.4/languages/cpp/cppcodecompletion.cpp #627773:627774
@@ -899,7 +899,7 @@
 void CppCodeCompletion::slotStatusTextTimeout() {
   if ( m_statusTextList.isEmpty() || !m_pSupport )
     return ;
-  m_pSupport->mainWindow() ->statusBar() ->message( m_statusTextList.front().second, m_statusTextList.front().first );
+//   m_pSupport->mainWindow() ->statusBar() ->message( m_statusTextList.front().second, m_statusTextList.front().first );
   m_showStatusTextTimer->start( m_statusTextList.front().first , true );
   m_statusTextList.pop_front();
 }
@@ -1951,14 +1951,14 @@
     if ( !ast ) {
       kdDebug( 9007 ) << "background-parser is missing the translation-unit. The file needs to be reparsed." << endl;
 	    m_pSupport->parseFileAndDependencies( m_activeFileName, true );
-	    m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Background-parser is missing the necessary translation-unit. It will be computed, but this completion will fail." ).arg( m_activeFileName ), 2000 );
+// 	    m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Background-parser is missing the necessary translation-unit. It will be computed, but this completion will fail." ).arg( m_activeFileName ), 2000 );
 	    return;
     } else {
       computeRecoveryPointsLocked();
     }
 	  if ( this->d->recoveryPoints.isEmpty() ) {
 		  kdDebug( 9007 ) << "Failed to compute recovery-points for " << m_activeFileName << endl;
-		  m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Failed to compute recovery-points for %1" ).arg( m_activeFileName ), 1000 );
+// 		  m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Failed to compute recovery-points for %1" ).arg( m_activeFileName ), 1000 );
 	  } else {
 		  kdDebug( 9007 ) << "successfully computed recovery-points for " << m_activeFileName << endl;
 	  }
@@ -1972,7 +1972,7 @@
   FileDom file = m_pSupport->codeModel() ->fileByName( m_activeFileName );
 
   if ( !file ) {
-    m_pSupport->mainWindow() ->statusBar() ->message( i18n( "File %1 does not exist in the code-model" ).arg( m_activeFileName ), 1000 );
+//     m_pSupport->mainWindow() ->statusBar() ->message( i18n( "File %1 does not exist in the code-model" ).arg( m_activeFileName ), 1000 );
     kdDebug( 9007 ) << "Error: file " << m_activeFileName << " could not be located in the code-model, code-completion stopped\n";
     return SimpleType();
   }
@@ -2215,7 +2215,7 @@
   FileDom file = m_pSupport->codeModel() ->fileByName( m_activeFileName );
 
   if ( !file ) {
-    m_pSupport->mainWindow() ->statusBar() ->message( i18n( "File %1 does not exist in the code-model" ).arg( m_activeFileName ), 1000 );
+//     m_pSupport->mainWindow() ->statusBar() ->message( i18n( "File %1 does not exist in the code-model" ).arg( m_activeFileName ), 1000 );
     kdDebug( 9007 ) << "Error: file " << m_activeFileName << " could not be located in the code-model, code-completion stopped\n";
     return ;
   }
@@ -2864,7 +2864,7 @@
   if ( fileName != m_activeFileName || !m_pSupport || !m_activeEditor )
     return ;
 
-	m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Current file updated %1" ).arg( m_activeFileName ), 1000 );
+// 	m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Current file updated %1" ).arg( m_activeFileName ), 1000 );
 
   computeRecoveryPointsLocked();
 }
@@ -2873,7 +2873,7 @@
   if ( fileName != m_activeFileName || !m_pSupport || !m_activeEditor )
     return ;
 
-	m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Current file parsed %1 (cache emptied)" ).arg( m_activeFileName ), 1000 );
+// 	m_pSupport->mainWindow() ->statusBar() ->message( i18n( "Current file parsed %1 (cache emptied)" ).arg( m_activeFileName ), 1000 );
 
   emptyCache(); ///The cache has to be emptied, because the code-model changed. @todo Better: Only refresh the code-model(tell all code-model-types to refresh themselves on demand)
 
@@ -4233,7 +4233,56 @@
 	}
 }
 
+QString CppCodeCompletion::createTypeInfoString( int line, int column ) 
+{
+	QString typeInfoString;
+	
+	SimpleTypeConfiguration conf( m_activeFileName );
+	EvaluationResult type = evaluateExpressionAt( line, column, conf );
+	
+	if ( type.expr.expr().stripWhiteSpace().isEmpty() )
+		return typeInfoString;
+	
+	typeInfoString += type.expr.expr() + QString(" : " );
+	
+	if ( type->resolved() ) 
+	{ 
+		QString scope = type->resolved()->scope().join("::");
+		int pos = scope.findRev("::");
+		if ( scope.isEmpty() || pos == -1 )
+		{
+			scope = "::";
+		}
+		else
+		{
+			scope.truncate( pos + 2 );
+		}
+		
+		typeInfoString += scope + type->fullNameChain()  + QString( i18n(" (resolved) ") );
+	}
+	else
+	{
+		if ( type ) 
+		{
+			if( !BuiltinTypes::isBuiltin( type.resultType ) ) 
+			{
+				typeInfoString += type->fullNameChain() + QString( i18n(" (unresolved) ") );
+			} 
+			else 
+			{
+				typeInfoString += type->fullNameChain() + ", " + BuiltinTypes::comment( type.resultType ) + QString( i18n(" (builtin type) ") );
+			}
+		}
+		else
+		{
+			typeInfoString += QString( i18n(" (unresolved) ") );
+		}
+	}
+	return typeInfoString;
+}
 
+
+
 #include "cppcodecompletion.moc"
 //kate: indent-mode csands; tab-width 2; space-indent off;
 
--- branches/kdevelop/3.4/languages/cpp/cppcodecompletion.h #627773:627774
@@ -124,6 +124,8 @@
 		return m_completionMode;
 	}
 
+	QString createTypeInfoString( int line, int column );
+	
     QString replaceCppComments( const QString& contents );
     int expressionAt( const QString& text, int index );
 	QStringList splitExpression( const QString& text );
--- branches/kdevelop/3.4/languages/cpp/cppsupportpart.cpp #627773:627774
@@ -40,6 +40,7 @@
 #include "kdevsourceformatter.h"
 #include "kdevcreatefile.h"
 #include "qtbuildconfig.h"
+#include "kdeveditorutil.h"
 #include <ktexteditor/viewcursorinterface.h>
 #include <kpopupmenu.h>
 // wizards
@@ -2582,6 +2583,15 @@
 
 void CppSupportPart::slotCursorPositionChanged()
 {
+	if ( codeCompletion() )
+	{
+		unsigned int line;
+		unsigned int column;
+		KDevEditorUtil::currentPositionReal( &line, &column, dynamic_cast<KTextEditor::Document*>( partController()->activePart() ) );
+		QString typeInfoString = codeCompletion()->createTypeInfoString( line, column );
+		mainWindow()->statusBar()->message( typeInfoString );
+	}
+	
 	//    m_functionHintTimer->changeInterval( 1000 );
 	if ( splitHeaderSourceConfig()->splitEnabled()
 	     && splitHeaderSourceConfig()->autoSync() )




More information about the KDevelop-devel mailing list