News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

Autocomplete problem

Started by dgrafix, February 15, 2009, 07:52:39 PM

Previous topic - Next topic

dgrafix

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??

Jenna

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.

dgrafix

#2
 :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 handlename-> |here i would expect a list of what (public) identifiers are declared in class |

I dont get autocomplete, but the code executes fine.

Jenna

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).

dgrafix

#4
-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.

Jenna

#5
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.

dgrafix

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

Jenna

#7
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.

dgrafix

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.

ollydbg

Quote from: 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.


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.

Barking_Mad

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

ollydbg

Quote from: 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).
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.

MortenMacFly

Quote from: Barking_Mad on February 26, 2009, 04:36:34 AM
is there no way that CC can be made to work with the working copy?
No. At least not implemented.

Quote from: Barking_Mad on February 26, 2009, 04:36:34 AM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]