Code::Blocks Forums

User forums => Help => Topic started by: dgrafix on February 15, 2009, 07:52:39 pm

Title: Autocomplete problem
Post by: dgrafix 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??
Title: Re: Autocomplete problem
Post by: Jenna 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.
Title: Re: Autocomplete problem
Post by: dgrafix 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.
Title: Re: Autocomplete problem
Post by: Jenna 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).
Title: Re: Autocomplete problem
Post by: dgrafix 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.
Title: Re: Autocomplete problem
Post by: Jenna 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.
Title: Re: Autocomplete problem
Post by: dgrafix 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
Title: Re: Autocomplete problem
Post by: Jenna 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.
Title: Re: Autocomplete problem
Post by: dgrafix 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.
Title: Re: Autocomplete problem
Post by: ollydbg 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.
Title: Re: Autocomplete problem
Post by: Barking_Mad 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).
Title: Re: Autocomplete problem
Post by: ollydbg 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
Title: Re: Autocomplete problem
Post by: MortenMacFly 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...