Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: zabzonk on February 20, 2013, 12:18:11 pm

Title: Code completion occurring inside comments
Post by: zabzonk on February 20, 2013, 12:18:11 pm
Using C::B 12.11, I am getting code completion popping up inside C++ comments. Am I alone in this (I did search before posting), and is there an easy way of stopping it? Screenshot here http://imgur.com/bL9VtGb .


Title: Re: Code completion occurring inside comments
Post by: oBFusCATed on February 20, 2013, 12:19:21 pm
I'd rather say this is a feature (at least for me) :)
Title: Re: Code completion occurring inside comments
Post by: zabzonk on February 20, 2013, 12:30:29 pm
Well, it's not for me! I find it intensely irritating having CC pop up when I'm writing non-program text. At the very least, it should be optional.
Title: Re: Code completion occurring inside comments
Post by: ollydbg on February 20, 2013, 02:49:57 pm
I think it is a cc bug, I can't reproduce this issue.
Title: Re: Code completion occurring inside comments
Post by: Alpha on February 20, 2013, 03:28:59 pm
The guard:
codecompletion.cpp: 2874
Code
    if (   control->IsString(style)
        || control->IsComment(style)
        || control->IsCharacter(style)
        || control->IsPreprocessor(style) )
    {
        return;
    }
should already prevent this.  Can you post a test case this behavior is occurring on?
Title: Re: Code completion occurring inside comments
Post by: zabzonk on February 20, 2013, 03:50:02 pm
Further investigation indicates that the behaviour is actually quite bizarre. If I create a new header file in a console project and start adding C++-style comments (but nothing else - no actual code), then the first word that can cause CC to fire will do so. So, if I enter;

Code
// this

then the code completion list pops up for "this", and for any other completable words as type them. If I enter a newline, then it seems the behaviour goes back to normal, and no CC takes place in the comment.  So it looks like the code for IsComment() may be a bit buggy.
Title: Re: Code completion occurring inside comments
Post by: ollydbg on February 20, 2013, 03:59:43 pm
...So it looks like the code for IsComment() may be a bit buggy.
I agree with you, you can report to scintilla :).
Title: Re: Code completion occurring inside comments
Post by: danselmi on February 20, 2013, 04:12:13 pm
IsComment(style) is part of cbStyledTextCtrl not scintilla!
Title: Re: Code completion occurring inside comments
Post by: Jenna on February 20, 2013, 06:19:39 pm
IsComment(style) is part of cbStyledTextCtrl not scintilla!
The problem is the control->GetStyleAt() function, that always returns 0 as style for the last position of a document.
And that's a Scintilla issue.
Title: Re: Code completion occurring inside comments
Post by: zabzonk on February 20, 2013, 06:43:29 pm
Is this a new Scintilla issue? Because I'm pretty positive it didn't happen prior to C::B 12.11.

Edit: Oh, yes it does (just tested it) - I wonder why I've never noticed it before?
Title: Re: Code completion occurring inside comments
Post by: Jenna on February 26, 2013, 10:51:50 am
IsComment(style) is part of cbStyledTextCtrl not scintilla!
The problem is the control->GetStyleAt() function, that always returns 0 as style for the last position of a document.
And that's a Scintilla issue.

Maybe not an issue, because the last postion is not styled at all, so retuzrning a zero.style might be considered the correct way to handle it.

I attach a patch with a quick (and more or less ugly) fix for this.
If the caret is on last position of a document (with length > 0) we use the style for the last character.

Title: Re: Code completion occurring inside comments
Post by: Jenna on March 01, 2013, 10:45:42 pm
IsComment(style) is part of cbStyledTextCtrl not scintilla!
The problem is the control->GetStyleAt() function, that always returns 0 as style for the last position of a document.
And that's a Scintilla issue.

Maybe not an issue, because the last postion is not styled at all, so retuzrning a zero.style might be considered the correct way to handle it.

I attach a patch with a quick (and more or less ugly) fix for this.
If the caret is on last position of a document (with length > 0) we use the style for the last character.


Any comments ?
Title: Re: Code completion occurring inside comments
Post by: MortenMacFly on March 02, 2013, 06:35:37 am
Any comments ?
No, seems to work here - at lest I see not negative side-effects.