Patch #3391 2012-12-06 01:27

alpha0010

CC: preprocessor completion improvements
Download
3391-CC_preprocesso.patch (14.6 KB)
Category
Plugin::FeatureAdd
Status
Accepted
Close date
2012-12-13 14:36
Assigned to
mortenmacfly
Index: src/plugins/codecompletion/codecompletion.h
===================================================================
--- src/plugins/codecompletion/codecompletion.h    (revision 8646)
+++ src/plugins/codecompletion/codecompletion.h    (working copy)
@@ -279,6 +279,7 @@
     int                     m_ActiveCalltipsNest;
 
     bool                    m_IsAutoPopup;
+    bool                    m_CompletePPOnly;
     // The variables below were related to CC's toolbar
     /** the CC's toolbar */
     wxToolBar*              m_ToolBar;
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp    (revision 8646)
+++ src/plugins/codecompletion/codecompletion.cpp    (working copy)
@@ -380,6 +380,36 @@
 "                ",
 "                "};
 
+// bitmap for #include file listings
+/* XPM */
+static const char* header_file_xpm[] = {
+"16 16 9 1",
+"   c None",
+"+  c #D23E39",
+"$  c #CF0C0A",
+"@  c #CB524B",
+"&  c #E2D8D8",
+"#  c #C7C7C4",
+"_  c #E4B9B5",
+"-  c #F7F9F7",
+"=  c #EBE9E7",
+"  #########     ",
+"  #=-----####   ",
+"  #--------=##  ",
+"  #--------=-#  ",
+"  #--=@_-----#  ",
+"  #--=+_-----#  ",
+"  #--=++@_---#  ",
+"  #--&$@@$=--#  ",
+"  #--&$__$&=-#  ",
+"  #--&$__$&=-#  ",
+"  #--&$__$&=-#  ",
+"  #-==#=&#==-#  ",
+"  #-========-#  ",
+"  #----=====-#  ",
+"  ############  ",
+"                "};
+
 // menu IDS
 // just because we don't know other plugins' used identifiers,
 // we use wxNewId() to generate a guaranteed unique ID ;), instead of enum
@@ -469,6 +499,7 @@
     m_LastEditor(0),
     m_ActiveCalltipsNest(0),
     m_IsAutoPopup(false),
+    m_CompletePPOnly(false),
     m_ToolBar(0),
     m_Function(0),
     m_Scope(0),
@@ -837,6 +868,9 @@
 
 int CodeCompletion::CodeComplete()
 {
+    const bool preprocessorOnly = m_CompletePPOnly;
+    m_CompletePPOnly = false;
+
     if (!IsAttached() || !m_InitDone)
         return -1;
 
@@ -888,6 +922,9 @@
                 if (unique_strings.find(token->m_Name) != unique_strings.end())
                     continue;
 
+                if (preprocessorOnly && token->m_TokenKind != tkPreprocessor)
+                    continue;
+
                 unique_strings.insert(token->m_Name);
                 int iidx = m_NativeParser.GetTokenKindImage(token);
                 if (already_registered.Index(iidx) == wxNOT_FOUND)
@@ -919,7 +956,7 @@
 
             CC_LOCKER_TRACK_TT_MTX_UNLOCK(s_TokenTreeMutex)
 
-            if (m_NativeParser.LastAISearchWasGlobal())
+            if (m_NativeParser.LastAISearchWasGlobal() && !preprocessorOnly)
             {
                 // empty or partial search phrase: add theme keywords in search list
                 if (s_DebugSmartSense)
@@ -1095,9 +1132,19 @@
         return;
 
     cbStyledTextCtrl* control = ed->GetControl();
-    const int curPos = control->GetCurrentPos();
-    const int start = control->WordStartPosition(curPos, true);
-    const int end = control->WordEndPosition(curPos, true);
+    if (control->GetLexer() != wxSCI_LEX_CPP)
+    {
+        const FileType fTp = FileTypeOf(ed->GetShortName());
+        if (   fTp != ftSource
+            && fTp != ftHeader
+            && fTp != ftResource )
+        {
+            return; // not C/C++
+        }
+    }
+    const int curPos    = control->GetCurrentPos();
+    const int start     = control->WordStartPosition(curPos, true);
+    const wxString text = control->GetTextRange(start, curPos);
 
     wxArrayString tokens;
     tokens.Add(_T("include"));
@@ -1115,9 +1162,21 @@
     tokens.Add(_T("error"));
     tokens.Add(_T("line"));
     tokens.Sort();
-    ed->GetControl()->ClearRegisteredImages();
-    ed->GetControl()->AutoCompSetIgnoreCase(false);
-    ed->GetControl()->AutoCompShow(end - start, GetStringFromArray(tokens, _T(" ")));
+    control->ClearRegisteredImages();
+    for (int i = 0; i < (int)tokens.GetCount(); ++i)
+    {
+        if (!text.IsEmpty() && tokens[i][0] != text[0])
+        {
+            tokens.RemoveAt(i); // remove tokens that start with a different letter
+            --i;
+        }
+        else
+            tokens[i] += wxString::Format(wxT("?%d"), PARSER_IMG_PREPROCESSOR);
+    }
+    control->RegisterImage(PARSER_IMG_PREPROCESSOR,
+                           m_NativeParser.GetImageList()->GetBitmap(PARSER_IMG_PREPROCESSOR));
+    control->AutoCompSetIgnoreCase(false);
+    control->AutoCompShow(curPos - start, GetStringFromArray(tokens, _T(" ")));
 }
 
 // Do the code completion when we enter:
@@ -1155,9 +1214,9 @@
         return;
 
     int keyPos = line.Find(_T('"'));
-    if (keyPos == wxNOT_FOUND)
+    if (keyPos == wxNOT_FOUND || keyPos >= pos - lineStartPos)
         keyPos = line.Find(_T('<'));
-    if (keyPos == wxNOT_FOUND || keyPos > pos - lineStartPos)
+    if (keyPos == wxNOT_FOUND || keyPos >= pos - lineStartPos)
         return;
     ++keyPos;
 
@@ -1167,6 +1226,10 @@
     if
download for full patch...
alpha0010 2012-12-06 01:28