Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: daniloz on November 24, 2010, 02:38:37 pm

Title: Problem with tab in lines
Post by: daniloz on November 24, 2010, 02:38:37 pm
Hi all,

I found I problem with the CodeCompletion plugin. It was not finding some symbols in my code. At first, it seemed random, but I could trace down the problem to lines that had a strange combination of spaces and tabs, after doing some debugging.

Here is an example code (. means space and > is the final position of a tab, my settings are tab=4 spaces)
Code
void main(void)
{
   >int aabbaa;

   >aabbaa
}
(The code above has one tab before each declaration)

If you right click and say go to declaration, it works...

Now, replace the tab before aabbaa (equivalent to 4 spaces) with space+space+tab. The final code is:
Code
void main(void)
{
   >int aabbaa;

.. >aabbaa
}
With this code, if you right click on aabbaa and say go to declaration, is says "Not found".

This is because the tab is expanded in the nativeparser.cpp at line 2169
Code
actual_search.Replace(_T("\t"), tabwidth);
actual_search.Remove(col);

, so each tab is replaced with 4 spaces, but the next line truncates the line based on the column position from screen, so 2 characters are left out. The reason is that the tab on editor is equivalent to 2 spaces only, keeping an indentation of 4.

I found a way to solve this by using the GetTextRange() function from wxscintilla...
Code
actual_search = searchData->control->GetTextRange(searchData->control->PositionFromLine(line), pos);

A patch is attached against svn trunk r6857...
I'm using the patch in my systems and it seems to be working fine now.
Title: Re: Problem with tab in lines
Post by: killerbot on November 24, 2010, 03:06:28 pm
this sounds like a very nice catch. I will try this myself later this weekd.
To other devs : please give it a try too ....
Title: Re: Problem with tab in lines
Post by: jens on November 24, 2010, 03:31:18 pm
this sounds like a very nice catch. I will try this myself later this weekd.
To other devs : please give it a try too ....
I did so and it seems to work.
I attach the same patch after removing some stuff, that was only needed by the old version.
Title: Re: Problem with tab in lines
Post by: daniloz on November 24, 2010, 03:36:11 pm
this sounds like a very nice catch. I will try this myself later this weekd.
To other devs : please give it a try too ....
I did so and it seems to work.
I attach the same patch after removing some stuff, that was only needed by the old version.

Thanks jens.. I've forget about it...  :oops:
Title: Re: Problem with tab in lines
Post by: daniloz on November 29, 2010, 01:07:47 pm
Hi again!

Should I submit a bug report with the patch to the BerliOs server? Or is the patch I've already submitted here being considering?
Title: Re: Problem with tab in lines
Post by: jens on November 30, 2010, 01:45:50 pm
@killerbot and other devs:
Did you test the patch ?
If yes:
did you experience any problems ?
Are there any objections (especially from the cc gurus) against applying it to trunk ?
Title: Re: Problem with tab in lines
Post by: MortenMacFly on November 30, 2010, 02:04:12 pm
Did you test the patch ?
No, as I for myself am very short in time atm

Are there any objections (especially from the cc gurus) against applying it to trunk ?
From a quick look I don't see anything wrong. Seems logical.
Title: Re: Problem with tab in lines
Post by: ollydbg on January 28, 2011, 01:11:28 pm
this patch is applied in trunk or not???
Title: Re: Problem with tab in lines
Post by: Loaden on February 10, 2011, 03:19:00 am
this patch is applied in trunk or not???
Yes, I am sure.