Author Topic: Code completion occurring inside comments  (Read 5571 times)

zabzonk

  • Guest
Code completion occurring inside comments
« 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 .



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12122
    • Travis build status
Re: Code completion occurring inside comments
« Reply #1 on: February 20, 2013, 12:19:21 pm »
I'd rather say this is a feature (at least for me) :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

zabzonk

  • Guest
Re: Code completion occurring inside comments
« Reply #2 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.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion occurring inside comments
« Reply #3 on: February 20, 2013, 02:49:57 pm »
I think it is a cc bug, I can't reproduce this issue.
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.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Code completion occurring inside comments
« Reply #4 on: February 20, 2013, 03:28:59 pm »
The guard:
codecompletion.cpp: 2874
Code: [Select]
    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?

zabzonk

  • Guest
Re: Code completion occurring inside comments
« Reply #5 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: [Select]
// 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.
« Last Edit: February 20, 2013, 03:51:35 pm by Neil Butterworth »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5247
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Code completion occurring inside comments
« Reply #6 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 :).
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.

Offline danselmi

  • Developer
  • Almost regular
  • *****
  • Posts: 202
Re: Code completion occurring inside comments
« Reply #7 on: February 20, 2013, 04:12:13 pm »
IsComment(style) is part of cbStyledTextCtrl not scintilla!

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code completion occurring inside comments
« Reply #8 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.

zabzonk

  • Guest
Re: Code completion occurring inside comments
« Reply #9 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?
« Last Edit: February 20, 2013, 06:47:16 pm by Neil Butterworth »

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code completion occurring inside comments
« Reply #10 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.


Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code completion occurring inside comments
« Reply #11 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 ?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9508
Re: Code completion occurring inside comments
« Reply #12 on: March 02, 2013, 06:35:37 am »
Any comments ?
No, seems to work here - at lest I see not negative side-effects.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ