Author Topic: Autocomplete problem  (Read 6283 times)

Offline dgrafix

  • Single posting newcomer
  • *
  • Posts: 9
Autocomplete problem
« on: February 15, 2009, 07:52:39 pm »
Hi,

I seem to have a problem with autocomplete not recognising variables.

For example (edited):

myclass * handlename= new myclass();

handlename->  - i would expect this to produce a list of methods and variables under type myclass, it doesnt.

What do i need to do to enable this??
« Last Edit: February 16, 2009, 05:46:07 pm by dgrafix »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Autocomplete problem
« Reply #1 on: February 15, 2009, 08:19:05 pm »
Did you really have a variable named this ?

If yes, you should read a good book about programming and about using (or not using) keywords as names for variables.

Offline dgrafix

  • Single posting newcomer
  • *
  • Posts: 9
Re: Autocomplete problem
« Reply #2 on: February 16, 2009, 05:43:33 pm »
 :lol:

lol no, i dont have a declaration called 'this' :D

I have edited above, still have the same issue, it does not seem to parse classes and subclasses for some reason.

eg i may have a variable or classname inside that called "a_variable" or "my_subclass"


i would expect
Code
handlename-> |here i would expect a list of what (public) identifiers are declared in class |

I dont get autocomplete, but the code executes fine.
« Last Edit: February 16, 2009, 05:48:55 pm by dgrafix »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Autocomplete problem
« Reply #3 on: February 16, 2009, 06:09:04 pm »
Works here (XP SP3 at work , C::B trunk) with a very simple testclass (ctor, dtor, one public function).

Did you save your class and the file where the header-file is included, so that it can be parsed ?

Is CodeCompletion enabled or is it accidently disabled (make sure "Settings -> Editor... -> Code-completion and symbols browser -> Code completion -> Disable code-completion" is unchecked).

Offline dgrafix

  • Single posting newcomer
  • *
  • Posts: 9
Re: Autocomplete problem
« Reply #4 on: February 16, 2009, 09:02:03 pm »
-I have the header file containing the class in the same dir as my program .cpp file.
-I have code completion definetely enabled.
-The directory path is listed in compiler search folders and in c++ parser options.
-The class has a namespace but i am using that namespace in the main code.

-It is autocompleting the namespace and classname. ie if i manually type out:

Namespace::BasicClassName::....  then it displays all.

Also, if i just use
BasicClassName::....  then it displays all.

but not when i make an instance of the class ie:
BasicClassName* instancename = new BasicClassName();

instancename ->  this is not autocompleting, even with ctrl space.


It must be something i am missing/overlooking in my setup as its the same for me on both linux and windows. I have the default package versions.
« Last Edit: February 16, 2009, 09:06:01 pm by dgrafix »

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Autocomplete problem
« Reply #5 on: February 17, 2009, 12:12:23 am »
I just tested again (at home on my linux machine), this time I also use a namespace for my class:

it works fine, if I declare the variable with xyz::classname* variable and have a using namespace xyz; only in the header.

It also works fine, if I have the using namespace directive in header- and cpp-file, but declare the variable without explicitely used namespace

It does not work, if I only have using namespace in the header file, and declare the variable "normally" (without explicitely used namespace).


Or in short: cc always works if I have a using namespace directive in the cpp-file or declare the variable with xyz::classname* variable.

It does not work, if I only have using namespace xyz; inside the header-file.
« Last Edit: February 17, 2009, 12:14:03 am by jens »

Offline dgrafix

  • Single posting newcomer
  • *
  • Posts: 9
Re: Autocomplete problem
« Reply #6 on: February 17, 2009, 01:45:52 pm »
AHAAA!

Thank you! I was "using namespaces" all over the place in my headers. I will convert everything (to do with my code) to use full names and give it a try later. I am convinced this IS the issue (as i have more or less explored everything else  :shock: ).

That would explain why AC is working in the header but not the cpp file.

 :D

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Autocomplete problem
« Reply #7 on: February 17, 2009, 01:51:05 pm »
For me it was enough to add using namespace xyz to the cpp-file, too.
It's less work then to use full names for every declaration (even if this would be more secure).

Please post if it works for you.
« Last Edit: February 17, 2009, 02:15:04 pm by jens »

Offline dgrafix

  • Single posting newcomer
  • *
  • Posts: 9
Re: Autocomplete problem
« Reply #8 on: February 21, 2009, 08:20:28 pm »
Hmm, nope, although it helped a little, i have some completion now at least..
but.
I get some completion sometimes and other times it works fine one minute and stops working the next. All the files are in the same folder as the cbp file and i have "./" in the search folders for compiler.

Online ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Autocomplete problem
« Reply #9 on: February 22, 2009, 02:14:05 am »
Hmm, nope, although it helped a little, i have some completion now at least..
but.
I get some completion sometimes and other times it works fine one minute and stops working the next. All the files are in the same folder as the cbp file and i have "./" in the search folders for compiler.


I think CC don't parser the code you entered before last save.

So, you could "save" your code, and let the parser  do it again on your newest code.
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 Barking_Mad

  • Multiple posting newcomer
  • *
  • Posts: 47
Re: Autocomplete problem
« Reply #10 on: February 26, 2009, 04:36:34 am »
Needing to save before CC updates is a bit annoying, is there no way that CC can be made to work with the working copy? Is there some specific reason CB cant do this? (i.e. due to scintilla).
WooF! WooF! - Ubuntu 8.10 & CB 5432 & GCC 4.3.2
To see the world in a grain of sand and heaven in a wild flower
To hold infinity in the palm of your hand and eternity in an hour - W.B

Online ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Autocomplete problem
« Reply #11 on: February 26, 2009, 04:45:33 am »
Needing to save before CC updates is a bit annoying, is there no way that CC can be made to work with the working copy? Is there some specific reason CB cant do this? (i.e. due to scintilla).
I think it can do it on a working copy. But now, development on CC is freezed. You can read it's source code and add something. By the way, nowadays, I'm reading it's source code and writing the wiki page

see here: http://wiki.codeblocks.org/index.php?title=Code_Completion_Design
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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Autocomplete problem
« Reply #12 on: February 26, 2009, 12:14:06 pm »
is there no way that CC can be made to work with the working copy?
No. At least not implemented.

Is there some specific reason CB cant do this? (i.e. due to scintilla).
Yes. imagine you are working an a huge file - processing CC at e.g. each fingertip (character you type in) would cost way too much performance. Doing CC after each 10 fingertips (or whatever) is not a good thing to do (imagine you are deleting a line in a file). Doing the same every n (m)secs is no good, too. Because users would still complain the same thing.

I believe triggering CC at Save is a very good thing to do. I mean: You have typed something you are "sure" it's correct - so why no save? And in the end: You still have the undo system as a backup...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ