News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Issue about wxScintilla

Started by Loaden, September 30, 2010, 07:31:57 AM

Previous topic - Next topic

Loaden

Hi, all!
I encountered a problem about scintilla.
Quotevoid CodeRefactoring::Find(cbStyledTextCtrl* control, const wxString& file, const wxString& target)
{
   const int end = control->GetLength();
   int start = 0;
   int pos = 0;

   for (;;)
   {
       int lengthFound;
       pos = control->FindText(start, end, target, wxSCI_FIND_WHOLEWORD | wxSCI_FIND_MATCHCASE, &lengthFound);
       if (pos != wxSCI_INVALID_POSITION)
       {
           start = pos + lengthFound;

           // TODO (Loaden) not work?
           const int style = control->GetStyleAt(pos); // always been zero?
           if (control->IsString(style) || control->IsComment(style))
               continue;

           int line = control->LineFromPosition(pos);
           wxString text = control->GetLine(line).Trim(true).Trim(false);
           m_SearchDataMap[file].push_back(crSearchData(pos, line, text));
       }
       else
           break;
   }
}
Please see the bold style code, why the return value always been zero.
Any comment are welcome!

Example code:
int test()
{
   // test
   printf("test");
}

When call control->FindText, we will get three result, include the comment(test) and string (test).

Here are "find references" result:
Quotemain.cpp|1|int test()|
main.cpp|3|// test|
main.cpp|4|printf("test");|

Jenna

I did a quick test with trunk (modified my IncrementalSearch-plugin to spit out the style for every found string, and I get:
pos: 4; style: 11
pos: 20; style: 2
pos: 37; style: 6

three different styles.

MortenMacFly

Quote from: jens on September 30, 2010, 08:31:23 AM
pos: 4; style: 11
pos: 20; style: 2
pos: 37; style: 6

three different styles.
Same here with a dummy project (plugin), however, debugging into the code Loaden mentioned I also get zero always. So the root must be somewhere else, not in scintilla.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

ollydbg

Quote from: MortenMacFly on September 30, 2010, 10:14:52 AM
debugging into the code Loaden mentioned I also get zero always.
Confirmed. strange...
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Jenna

Quote from: ollydbg on September 30, 2010, 10:56:03 AM
Quote from: MortenMacFly on September 30, 2010, 10:14:52 AM
debugging into the code Loaden mentioned I also get zero always.
Confirmed. strange...
No, not strange.
The code do not use the cbEditor, but just the cbStyledTextctrl, but without a lexer and without highlighting any code, so GetStyleAt can not return anything but the default value, because the text is not styled.

The following patch should do the trick:
Index: coderefactoring.cpp
===================================================================
--- coderefactoring.cpp (Revision 6654)
+++ coderefactoring.cpp (Arbeitskopie)
@@ -156,6 +156,9 @@
                 continue; // failed
             control->SetText(detector.GetWxStr());
         }
+        cbEditor::ApplyStyles(control);
+        EditorColourSet EdColSet;
+        EdColSet.Apply(EdColSet.GetLanguageForFilename(files[i]), control);

         Find(control, files[i], targetText);
     }


Shall I commit it ?

ollydbg

thanks jen for the explanation.
Yes, I found that in coderefactoring.cpp line 131.
There are code snippet
    // now that list is filled, we'll search
    cbStyledTextCtrl* control = new cbStyledTextCtrl(editor->GetParent(), wxID_ANY, wxDefaultPosition, wxSize(0, 0));


QuoteShall I commit it ?
I full agree.



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Loaden

Quote from: jens on September 30, 2010, 12:01:58 PM
Quote from: ollydbg on September 30, 2010, 10:56:03 AM
Quote from: MortenMacFly on September 30, 2010, 10:14:52 AM
debugging into the code Loaden mentioned I also get zero always.
Confirmed. strange...
No, not strange.
The code do not use the cbEditor, but just the cbStyledTextctrl, but without a lexer and without highlighting any code, so GetStyleAt can not return anything but the default value, because the text is not styled.

The following patch should do the trick:
Index: coderefactoring.cpp
===================================================================
--- coderefactoring.cpp (Revision 6654)
+++ coderefactoring.cpp (Arbeitskopie)
@@ -156,6 +156,9 @@
                 continue; // failed
             control->SetText(detector.GetWxStr());
         }
+        cbEditor::ApplyStyles(control);
+        EditorColourSet EdColSet;
+        EdColSet.Apply(EdColSet.GetLanguageForFilename(files[i]), control);

         Find(control, files[i], targetText);
     }


Shall I commit it ?
Thank Jens! :D
I can't solved this issue so long time.
I am very happy to see what is the reason.
Thanks a lot!

But, I am worry about the search performance?
So, I want look into it.

Jenna

After a quick test with ThreadSearch-plugin and search for wxString, searching is about 25 times slower: ~400ms against ~9800ms .

I just used wxStropWatch and measured the for-loop in SearchInFiles about line 142.

ollydbg

I think:
the lexer/parser in scintilla is not as fast as CC's parser. So, I'd rather add a function in Parserthread class to do the search. Currently all the comments were skipped in CC's Tokenizer.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

MortenMacFly

Quote from: jens on September 30, 2010, 01:28:07 PM
After a quick test with ThreadSearch-plugin and search for wxString, searching is about 25 times slower: ~400ms against ~9800ms .
Quote from: ollydbg on September 30, 2010, 01:40:15 PM
Currently all the comments were skipped in CC's Tokenizer.
Which makes me wonder: Wat's the actual purpose of using the styles in scintilla to quey for comments? I mean: This can only be less performant...?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

ollydbg

Quote from: MortenMacFly on September 30, 2010, 02:05:11 PM
Which makes me wonder: Wat's the actual purpose of using the styles in scintilla to quey for comments? I mean: This can only be less performant...?!
The re-factoring model was designed by Loaden, so I think he can some idea. See:
int test()
{
    // test
    printf("test");
}


A simple plain text search will give 3 matches.
But in-fact, the one we interested was only the function name. So, both matched text result in comments and c-strings should be removed. Sometimes, the matched text in comments should also be involved.
Currently the only way is do a query to scintilla.

I'm thinking a better way by CC.

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Loaden

#11
Quote from: ollydbg on September 30, 2010, 02:13:30 PM
Quote from: MortenMacFly on September 30, 2010, 02:05:11 PM
Which makes me wonder: Wat's the actual purpose of using the styles in scintilla to quey for comments? I mean: This can only be less performant...?!
The re-factoring model was designed by Loaden, so I think he can some idea. See:
int test()
{
   // test
   printf("test");
}


A simple plain text search will give 3 matches.
But in-fact, the one we interested was only the function name. So, both matched text result in comments and c-strings should be removed. Sometimes, the matched text in comments should also be involved.
Currently the only way is do a query to scintilla.

I'm thinking a better way by CC.

Thank ollydbg explained.
I found a way to solved, will be less performant littler.

We can't solved this issue by CC.
It's only scintilla related.

EDIT:
Sorry! Found a bug, fixed now.

Loaden


Loaden

More improved.
This is the final version. :)