[prev in list] [next in list] [prev in thread] [next in thread] 

List:       quanta-devel
Subject:    Re: [quanta-devel] Class Variables - no attrAutoCompleteAfter patch
From:       Andrew Lowe <andrew.lowe () manildra ! com ! au>
Date:       2007-02-15 6:51:27
Message-ID: 45D402EF.1040703 () manildra ! com ! au
[Download RAW message or body]

Whoops... I found a mistake - I moved a statement inside an if that I 
should not have
sorry, attached is the fixed diff
Andrew Lowe wrote:

> Andrew Lowe wrote:
>
>> Andras,
>> Please find attached to svn diff to fix the first of the problems 
>> that I am looking at:
>> Removing the "completionDTD->attrAutoCompleteAfter" which for php is: 
>> "(" from the autocompletion entry for class variables.
>>
>> You have to update the description.rc to make variables a member of 
>> the class group - exactly as you sent in a previous email, then this 
>> code seems to work, and I do not believe it breaks anything?
>>
>> Here is what I have done:
>> in sagroupparser.cpp SAGroupParser::parseForScriptGroup
>>    I check if s (the tag text) contains a "(" and if it does, I set 
>> the qTag->type to "function", otherwise I set it to "variable".
>> in document.cpp Document::getTagCompletions
>>    I add a QMap named type,
>>    I check if the completionDTD->family is Script, (if not ignore - 
>> it is XML) then if our tag->type is "variable" insert into the type 
>> QMap "variable", if it is function, insert "script" (so it works in 
>> Document::slotFilterCompletion.) I also add to the comments QMap the 
>> type ("variable" or "function") to show the user the type when they 
>> are using the autocomplete drop-down.
>>    Finally, I set the completion.type to be the type for that tag.
>>    I also made a TODO comment to sort the completions by type.
>>
>> I hope everything is right - and I have not used any QTag or 
>> CompletionEntry variables I should not have - if so let me know.  
>> Also let me know if anything is not right :-)
>
>
> I think I now have the class auto-completion working!
> This current patch (against SVN) contains the above plus:
>    ignoring class function arguments;
>    and sorts the list by type, then name
>
> Here is an outline:
> 1 ignore class function arguments
> in sagroupparser.cpp SAGroupParser::parseForScriptGroup
>    If the tag is a class member, and variable we process it, otherwise 
> we do not need to filter
>    We determine the whole line the variable is on.
>    We check if it is after '(' and before ')'.
>    If this is true, reset its className to nothing ""
>
> 2 sorting class tag completions by type
> in document.cpp Document::getTagCompletions
>    Test if we are using a Script family in our completionDTD, 
> otherwise we can ignore this sorting and just leave it alphabetically 
> sorted by name.
>    We want to sort first: unknowns ("other"), "variable" and then 
> functions ("script"),  and then alphabetically by name
>    instead of just appending every completion to the completions 
> QValueList, we determine if it is of type "variable", "script" or 
> anything else("other").
>    we have a couple of iterators to put "other" and "variable" types 
> at the beginning and middle of the completions QValueList, and keep 
> our place.
>    functions just go at the end.
>
> Let me know how it is...
>


-- 
Andrew Lowe
    System Administrator & Programmer
        Information Technology
            Manildra Group

Email:   andrew.lowe@manildra.com.au
Phone:   02 4423 8270
Mobile:  04 1323 8270
Fax:     02 4421 7760 


["class-completions.patch" (text/plain)]

Index: parsers/sagroupparser.cpp
===================================================================
--- parsers/sagroupparser.cpp	(revision 633713)
+++ parsers/sagroupparser.cpp	(working copy)
@@ -216,6 +216,52 @@
               }
             }
           }
+          /* Author Andrew Lowe - andrew.lowe@manildra.com.au
+           * Test for variable or function Type by checking for an opening bracket \
"(" used by functions +           * store the type in the QTag type variable.
+           */
+          if (s.find('(') == -1)
+            qTag->type="variable";
+          else
+            qTag->type="function";
+          
+          /* Author Andrew Lowe - andrew.lowe@manildra.com.au
+           * Test if the tag has been determined to be a class variable
+           * If it is we want to make sure it is not a class function argument.
+           * If it is a class function argument, it should not belong to the class, \
so we need to remove its className +           */
+          if(qTag->type == "variable" && qTag->className.length() != 0)
+          {
+            // First we want to determine the whole line the tag is on
+            QString tagWholeLineStr = tagStr;
+            // Remove lines before target line
+            while(tagWholeLineStr.length() > 0) // this stops infinit looping in \
case something goes wrong! +            {
+              if(tagWholeLineStr.find('\n') != -1 && \
tagWholeLineStr.mid(tagWholeLineStr.find('\n')+1,tagWholeLineStr.length()).find(s) != \
-1) +                tagWholeLineStr = \
tagWholeLineStr.mid(tagWholeLineStr.find('\n')+1,tagWholeLineStr.length()); +         \
else +                break;
+            }
+            // Remove lines after target line
+            while(tagWholeLineStr.length() > 0)
+            {
+              if(tagWholeLineStr.findRev('\n') != -1 && \
tagWholeLineStr.mid(0,tagWholeLineStr.findRev('\n')).find(s) != -1) +                \
tagWholeLineStr = tagWholeLineStr.mid(0,tagWholeLineStr.findRev('\n')); +             \
else +                break;
+            }
+            // Now we are left with the current line, lets check if the variable is \
inside parentheses +            if(tagWholeLineStr.find('(') != -1 && \
tagWholeLineStr.find(')') != -1 ) +            {
+              if(tagWholeLineStr.find('(') < tagWholeLineStr.find(s) && \
tagWholeLineStr.find(')') > tagWholeLineStr.find(s) ) +              {
+                // The variable is defined inside parentheses so we reset its class.
+                qTag->className = "";
+              }
+            }
+          }
+
+          // Write the current tag to the list ( Existing Code commented for \
clarity)  m_write->userTagList.insert(s.lower(), qTag);
         }
 
Index: src/document.cpp
===================================================================
--- src/document.cpp	(revision 633713)
+++ src/document.cpp	(working copy)
@@ -1285,6 +1285,10 @@
   completion.userdata = word + "|";
   QStringList tagNameList;
   QMap<QString, QString> comments;
+  /* Andrew Lowe - andrew.lowe@manildra.com.au
+   * A QMap to hold the completion type (function/string/class/etc)
+   */
+  QMap<QString, QString> type;
   QString tagName;
   QDictIterator<QTag> it(*(completionDTD->tagsList));
   int i = 0;
@@ -1318,11 +1322,37 @@
       tagName = tag->name() + QString("%1").arg(i, 10);
       tagNameList += tagName;
       comments.insert(tagName, tag->comment);
+      /* Author - Andrew Lowe - andrew.lowe@manildra.com.au
+       * If the completion family is script, then we want to update the tag type
+       * it appears we use "script" for adding the \
completionDTD->attrAutoCompleteAfter when we run the slotFilterCompletion +       * \
so we will continue to use that for functions (they need the attribute added), but \
variables get a new type - and we do not +       * have to auto-complete them
+       */
+      if(completionDTD->family==Script)
+      {
+        if(tag->type=="variable")
+          type.insert(tagName, tag->type);
+        else if(tag->type=="function")
+          type.insert(tagName, "script");
+      }
+      /*
+       * While we are at it - we might add the type to the comment variable, so it \
displays on the screen, giving the user some feedback +       */
+      comments.insert(tagName, tag->type);
       i++;
     }
   }
 
   tagNameList.sort();
+  /* Author Andrew Lowe
+   * tagNameList is sorted above to sort the completions by name alphabetically
+   * Now we want to sort the completions by their types.
+   * We only want to do this if we are completing Script DTDs
+   * We are going to use a couple of iterators to sort the list by Type
+   * Type Sorting is as follows: 0:Other, 1:Variables, 2: Functions (script)
+   */
+  QValueList<KTextEditor::CompletionEntry>::Iterator otherIt=completions->begin();
+  QValueList<KTextEditor::CompletionEntry>::Iterator \
variableIt=completions->begin();  for (uint i = 0; i < tagNameList.count(); i++)
   {
     if (completionDTD->family == Xml)
@@ -1331,10 +1361,43 @@
       completion.text = tagNameList[i];
     completion.text = completion.text.left(completion.text.length() - \
10).stripWhiteSpace();  completion.comment = comments[tagNameList[i]];
-    completions->append( completion );
+    /* Author Andrew Lowe - andrew.lowe@manildra.com.au
+     * Here we actually append the completion type
+     */
+    completion.type = type[tagNameList[i]];
+    if(completionDTD->family==Script)
+    {
+      // And here is out sorting...
+      if(completion.type.contains("variable"))
+      {
+        // Insert after the last variable
+        variableIt++;
+        variableIt = completions->insert(variableIt, completion);
+      }
+      else
+      {
+        if(completion.type.contains("script"))
+        {
+          //Scripts can go at the end of the list
+          completions->append(completion);
+        }
+        else
+        {
+          // Other types go first, after the last other type
+          otherIt++;
+          otherIt = completions->insert(otherIt, completion);
+          // If we have no variables in the list, we need to point variableIt to \
otherIt, so they will go after the 'others' +          \
if((*variableIt).text.length()==0) +            variableIt=otherIt;
+        }
+      }
+    }
+    else
+      completions->append( completion );
   }
 
 //  completionInProgress = true;
+
   return completions;
 }



_______________________________________________
quanta-devel mailing list
quanta-devel@kde.org
https://mail.kde.org/mailman/listinfo/quanta-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic