Author Topic: Code Completion works only partially per file  (Read 9988 times)

jamieo

  • Guest
Code Completion works only partially per file
« on: February 19, 2007, 12:08:05 am »
Hi, I've been looking into this for a while and have searched through many posts but have not found any that reference this particular problem.

Problem Description
The problem is that while the Win32 Platform SDK include files ARE parsed, they are only parsed part the way through.  For instance, in the attached composite screenshot you can see that while 'FormatMessage' from 'WinBase.h' is completed ok, 'CreatePipe' (which is the next function in that include) is not.  Further, any other functions I tried that appear later in the file are not found while functions that appear earlier are.  The same is true of 'WinUser.h' as shown - these were the only files I tried in such detail, more than likely the problem exists for all files.  The behavior of 'Find Declaration of..' is also similar. 

Tests carried out
To rule out a problem of file size I chopped out a big lump of the file before the problem occurs - this made no difference.  As a further test I cut everything after the last working function in each file and checked the sizes, one was 77kb, the other 91kb.   I also tried removing precompiler statements between the working and non working areas without any improvement, as well as removing all files from the include folder except the two files mentioned and 'Windows.h' - results were exactly the same.  I restarted CodeBlocks between each attempt.

CodeBlocks Version and Settings
This problem exists in all builds I've tried (over the past month) - I am currently using the latest nightly (CB_20070217_rev3614_win32) which describes itself as: svn build rev 0 (2007-02-10 13:44:04) gcc 3.4.5 Windows/unicode.

I have tried all combinations of the parser settings with no improvement and am currently using the default settings with the ommision of 'Parse Preprocessor Directives' in case this was the cause (which it does not appear to be).  The folders are set in the compiler's search paths and are obviously found as many functions do work.  I also tried setting them in the project's parser search paths settings.

I've only been doing Win32 development so have not noticed the problem with other includes.  If anybody hasn't got this problem when using Win32 Includes perhaps we can zip them up and swap 'em over to rule them out as the cause...

Please let me know if there's anything more I can do to help with this problem, I can provide my whole install, settings, include files or projects zipped up if required.  CodeBlocks could completely replace the VS2005 IDE for C++ if it were not for this problem and the lack of a win32 resource editor. :)

Jamie

[attachment deleted by admin]

jamieo

  • Guest
Re: Code Completion works only partially per file
« Reply #1 on: February 22, 2007, 05:07:37 am »
Not that anybody seems interested but I tried some different platform sdk releases based on the assumption that I must be the only person with this problem!  :shock:

Basically all the platform sdk downloads still listed on microsoft.com exhibit the same problem.  However, installations of VC6 and VC7.1 that come with (much older) platform sdk headers included do not have any problems.  With all my tests I had the platform sdk headers in a separate folder to the compiler includes. ie, .\vc71\include + .\psdk\include.

Code
PASS - (04/1998) VC6.0 SP6 Includes with PSDK
PASS - (09/2002) VC7.1 SP1 Includes with PSDK

FAIL - (05/2005) PlatformSDK Windows 2003 SP2
FAIL - (03/2006) PlatformSDK Windows 2003 R2
FAIL - (11/2006) PlatformSDK Windows Vista

I guess there must be some weird difference between the header layout wrt preprocessor directives or something... I can zip these up if anybody is interested...

wxLearner

  • Guest
Re: Code Completion works only partially per file
« Reply #2 on: February 22, 2007, 11:08:48 am »
CodeBlocks could completely replace the VS2005 IDE for C++ if it were not for this problem and the lack of a win32 resource editor. :)
Hello,
I think it's better to create cross platform GUI applications (Code::Blocks has the wxSmith plugin for GUI editing), but if you really want to make a Win32 only application, please take a look at the ResEd Resource editor.

ascxaxsvcbsxbbqvcxqsbcvxs

  • Guest
Re: Code Completion works only partially per file
« Reply #3 on: February 22, 2007, 02:46:23 pm »
Problem Description
The problem is that while the Win32 Platform SDK include files ARE parsed, they are only parsed part the way through.  For instance, in the attached composite screenshot you can see that while 'FormatMessage' from 'WinBase.h' is completed ok, 'CreatePipe' (which is the next function in that include) is not.  Further, any other functions I tried that appear later in the file are not found while functions that appear earlier are.  The same is true of 'WinUser.h' as shown - these were the only files I tried in such detail, more than likely the problem exists for all files.  The behavior of 'Find Declaration of..' is also similar. 
Are the number of functions that autocomplete in each include files the same?
For example exactly 100 functions autocomplete in WinBase.h and 100 exactly also in WinUser.h ?
« Last Edit: February 22, 2007, 03:41:06 pm by ascxaxsvcbsxbbqvcxqsbcvxs »

ascxaxsvcbsxbbqvcxqsbcvxs

  • Guest
Re: Code Completion works only partially per file
« Reply #4 on: February 22, 2007, 03:42:58 pm »
CodeBlocks could completely replace the VS2005 IDE for C++ if it were not for this problem and the lack of a win32 resource editor. :)
Hello,
I think it's better to create cross platform GUI applications (Code::Blocks has the wxSmith plugin for GUI editing), but if you really want to make a Win32 only application, please take a look at the ResEd Resource editor.

If the autocomplete is limited for win32 files, it surely is limited also for other cross platform files.

jamieo

  • Guest
Re: Code Completion works only partially per file
« Reply #5 on: February 23, 2007, 02:07:16 am »
Unfortunately it's not just function names but any symbol is affected.  For example, the BSM_* constants that appear a little after GetMessage in WinUser.h are not parsed. (these were the first and only I tried just now).  It would be a huge task to count each and every one but it would be nice if somebody could add some stats to the code completion parser to see how many symbols were parsed per file, even if it were just a quick hack to help with this investigation.

Based on your question I checked where the symbols stopped being parsed in the latest Vista PSDK.  It's in the exact place for both files ie, FormatMessage and GetMessage are the last symbols that will work.  I then compared these files to the original versions I reference above from PSDK2003 and there are (as expected) many new symbols defined, including new functions so I doubt symbol or function count has an influence.  I also checked some of the new symbols defined either side of the 'divide' and behavior was as with psdk2003.

I'm surprised none of the developers or more experienced codeblocks hackers are interested in this thread - this IS the Dev-el-op-ment Forum?!  Maybe you have to have 10000 posts before your posts are valid...

Jamie




Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Code Completion works only partially per file
« Reply #6 on: February 23, 2007, 04:09:12 am »
I'm surprised none of the developers or more experienced codeblocks hackers are interested in this thread ...
Code::Blocks' code completion is a work in progress. It's generally accepted that the current implementation, while usable, would be better off redeveloped from the ground up. Of the official devs, I'd expect only mandrav and possibly thomas to be truly qualified to troubleshoot and bugfix the current version (the majority of which was written single-handedly by mandrav). Any fixes to the current version, therefore, are subject to mandrav's willingness to nail more boards onto a house that's already scheduled for demolition.

(I don't pretend to speak for the C::B dev team in any way -- this has just been my experience.)
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Code Completion works only partially per file
« Reply #7 on: February 23, 2007, 09:28:23 am »
Quote from: jamleo
Based on your question I checked where the symbols stopped being parsed in the latest Vista PSDK.  It's in the exact place for both files ie, FormatMessage and GetMessage are the last symbols that will work.  I then compared these files to the original versions I reference above from PSDK2003 and there are (as expected) many new symbols defined, including new functions so I doubt symbol or function count has an influence.  I also checked some of the new symbols defined either side of the 'divide' and behavior was as with psdk2003.

Did you check inside the files for "strange" constructs or defines, around there the parser stops, that could possibly confuse our parser?
If you can't see anything, zip one such file and attach it here or post a link to it so I can have a look.

Quote from: jamleo
I'm surprised none of the developers or more experienced codeblocks hackers are interested in this thread - this IS the Dev-el-op-ment Forum?!  Maybe you have to have 10000 posts before your posts are valid...

But then again you may ignore this post as I don't have 10000 posts already so it may very well be considered invalid...
Be patient!
This bug will be fixed soon...

jamieo

  • Guest
Re: Code Completion works only partially per file
« Reply #8 on: February 23, 2007, 07:12:44 pm »
Did you check inside the files for "strange" constructs or defines, around there the parser stops, that could possibly confuse our parser?
If you can't see anything, zip one such file and attach it here or post a link to it so I can have a look.

Thanks for looking into this, I've spent a while investigating and documenting this so a resolution may be found.  Opening the attached project from testproj.zip with your psdk search path changed to the minimal set of headers included *should* result in the described behavoir.  The other attachment has the working headers from VS2003 if required.

I've found the part of the include that causes the problem by commenting out various directives and retesting, I didn't think of doing this before as I thought disabling the 'Follow Preprocessor Directives' option should ignore any #ifdef etc. directives but it doesn't seem to have any effect on this issue - does the option only effect reading of additional files included in a header?  Additionally, the directives look valid and folding within SciTe seems to confirm that.

The error occurs with incorrect parsing of the '#ifdef UNICODE' block within the '#if defined(_M_CEE)' blocks commented below.  What's surprising is that I wouldn't expect the problem block to even be parsed based on the defines in effect.  With the 'Follow Preprocessor Directives' option disabled the error still happens.  Also, 'Find declaration of..' FormatMessage lists the symbol defined within this directive, should this be the case.  It seems Codeblocks parses within inactive directives.

WinBase.h
Code
#if defined(_M_CEE)
#undef FormatMessage
__inline
DWORD
FormatMessage(
    DWORD dwFlags,
    LPCVOID lpSource,
    DWORD dwMessageId,
    DWORD dwLanguageId,
    LPTSTR lpBuffer,
    DWORD nSize,
    va_list *Arguments
    )
{

///  COMMENTING THE FOLLOWING DIRECTIVE
///  MAKES THE PROBLEM GO AWAY!
/*
#ifdef UNICODE
    return FormatMessageW(
#else
    return FormatMessageA(
#endif
*/

        dwFlags,
        lpSource,
        dwMessageId,
        dwLanguageId,
        lpBuffer,
        nSize,
        Arguments
);
}
#endif /* _M_CEE */

WinUser.h
Code
#if defined(_M_CEE)
#undef GetMessage
__inline
BOOL
GetMessage(
    LPMSG lpMsg,
    HWND hWnd,
    UINT wMsgFilterMin,
    UINT wMsgFilterMax
    )
{
///  COMMENTING THE FOLLOWING DIRECTIVE
///  MAKES THE PROBLEM GO AWAY!
/*
#ifdef UNICODE
    return GetMessageW(
#else
    return GetMessageA(
#endif
*/
        lpMsg,
        hWnd,
        wMsgFilterMin,
        wMsgFilterMax
        );
}
#endif /* _M_CEE */

Commenting out the blocks above doesn't completely fix code completion, for instance 'MessageBox' is not found so there are other instances of this problem within the same include.  However, some similar directives I look into don't seem to cause the same problem.  The following block for 'SetEnvironmentVariable' within 'WinBase.h' seems ok so there seems to be some other influence at work here:

WinBase.h
Code
#if defined(_M_CEE)
#undef SetEnvironmentVariable
__inline
BOOL
SetEnvironmentVariable(
    LPCTSTR lpName,
    LPCTSTR lpValue
    )
{
///  THE FOLLOWING DIRECTIVE DOESN'T
///  SEEM TO CAUSE A PROBLEM...
#ifdef UNICODE
    return SetEnvironmentVariableW(
#else
    return SetEnvironmentVariableA(
#endif
        lpName,
lpValue
);
}
#endif /* _M_CEE */

But then again you may ignore this post as I don't have 10000 posts already so it may very well be considered invalid...
Ha!  Then I am lucky your post count is not so high yet!  Of course your post is valid - to me anyway - you still have more posts than I do!!! ;)

I'm joking btw, although it does annoy me how many boards have a snobery regarding post count.  Especially as I prefer to search for my own answers rather than increasing my post count by blindly asking for help all the time!  End Rant!   :P

Jamie

[attachment deleted by admin]
« Last Edit: February 23, 2007, 07:15:54 pm by jamieo »

jamieo

  • Guest
Re: Code Completion works only partially per file
« Reply #9 on: February 23, 2007, 07:26:27 pm »
Another problem I've encountered with code completion is that some functions complete but do not offer the parameter tooltip.

I've noticed this seems to occur only with functions that are defined as other functions, ie: 'MessageBox' is really 'MessageBoxA' or 'MessageBoxW' depending on the 'UNICODE' define.  The tooltip doesn't work for this function but does for 'MessageBoxA' and 'MessageBoxW'.  This severly cripples code completion (for win32 at least, not sure about other platforms) - is this behavoir expected or should the tooltips be shown??

PS. Although I'm probably unable to fix these problems myself I have noticed a few other minor bugs - I'm unsure if these have already been reported as the forum referenced to in the 'Reporting Problems' sticky seems to be inaccessible to non-developers.

Jamie
« Last Edit: February 23, 2007, 07:57:12 pm by jamieo »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Code Completion works only partially per file
« Reply #10 on: February 23, 2007, 11:04:28 pm »
Thanks for investigating some more.

So, here's the deal: the parser does parse preprocessor directives (if enabled in options) but only to collect them as tokens. The only extra handling for preprocessor directives is distinguishing #if/#else blocks. In that case it always parses inside the #if/#ifdef and skips the #else/#elsif. The only thing missing yet is support for the special "#if 0" directive so that it skips it and parse the #else/#elsif branch instead. This is planned and will come at some point.

There are no plans atm to add "smarter" behaviour wrt preprocessor blocks and that's because it's just a parser. It's not a compiler (or a post-processor if you like).
Be patient!
This bug will be fixed soon...

jamieo

  • Guest
Re: Code Completion works only partially per file
« Reply #11 on: February 24, 2007, 12:34:33 am »
Hmm... Did you have time yet to look into the headers I attached?  I don't think it's a new feature I'm requesting - the code is already there, it just ain't workin!  ;)

When you say it always parses inside the #if/#ifdef and skips the #else/#elsif do you mean when the #if condition is true?  Otherwise the inverse should be perfomed?  Anyway, your post confirms that turning off the option should stop it caring about the preprocessor directives all together... so why does the problem occur with this option turned off? 

While on the subject of preprocessor directives, did you see my previous post?  With the preprocessor option on, functions defined by ie, '#define MessageBox  MessageBoxW' are parsed but the #define isn't followed to set up the tooltips for the function parameters.  Is this what you mean when you say only tokens are collected?  Surely once you have the token it would be straightforward (for the original dev anyway) to lookup the function it references and copy the parameters (tooltip string) to the new token?

The annoying thing is that apart from these niggles the parser works very well - it just seems everybody has given up on it!   Unfortunately it's these little bugs that prevent it from being useful for it's purpose - which afaic is to have all the available symbols in the list and not having to have the MSDN docs (or similar) to hand.

I've checked out the CodeBlocks source from svn but am not getting too far in compiling wxwidgets with mingw (although vc2003 is no problem).  It's unfortunate that these little bugs ruin the usefulness of what is a great IDE - I would much prefer using CodeBlocks over VS2005 but without these basic features working properly I find myself using VS2005 for coding while most of my time in CodeBlocks is spent investigating the cause of various problems.   :(

Are these bugs being looked into?  Your last post sounds as though you do not intend to and while it's your right to prioritise your time could you confirm either way case so I can prioritise my time too.

Jamie
« Last Edit: February 24, 2007, 12:47:25 am by jamieo »