Bug 151207 - Content assist fails due to lack of completion node
Summary: Content assist fails due to lack of completion node
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 4.0 M5   Edit
Assignee: Bryan Wilkinson CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-07-20 07:37 EDT by Norbert Plött CLA
Modified: 2009-01-09 15:09 EST (History)
4 users (show)

See Also:


Attachments
proposed patch (2.10 KB, patch)
2007-01-25 14:02 EST, Bryan Wilkinson CLA
bjorn.freeman-benson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Norbert Plött CLA 2006-07-20 07:37:14 EDT
In a number of situations content assist fails because the GNUCPPSourceParser does not return a completion node. All situations are reproducable through junit tests in package org.eclipse.cdt.ui.tests.text.contentassist2. The list below gives the specific classes which fail, and a short description of the situation. The exact C source code which leads up to the problem can of course be retrieved from the given classes.

This bug may have to be split into several entries if various causes are found for the failure. From my current perspective it's the GNUCPPSourceParser as a blackbox which does not deliver a completion node. So here is the list:

Completion in an argument list:
void foo( ???
- CompletionTest_ArgumentType_NoPrefix
- CompletionTest_ArgumentType_NoPrefix2

Completion where a class definition would be appropriate:
class X : ???
- CompletionTest_ClassReference_NoPrefix

exception to be caught:
  catch ( ???
- CompletionTest_ExceptionReference_NoPrefix

Class field type specifier:
class A {
   ???
}
- CompletionTest_FieldType_NoPrefix
- CompletionTest_FieldType_NoPrefix2

where a macro reference would be appropriate: 
#ifdef ???
- CompletionTest_MacroRef_NoPrefix
- CompletionTest_MacroRef_Prefix

where a namespace reference would be appropriate:
using namespace ???
- CompletionTest_NamespaceRef_NoPrefix

where operator new needs a type specification:
  aClass myClass = new ???
- CompletionTest_NewTypeReference_NoPrefix

Starting a statement in a method context:
void anotherClass::anotherMethod()
{
    ???
}
- CompletionTest_SingleName_Method_NoPrefix

left hand side of an assignment in a function context
void foo(int x){
	int y = ???
}
- CompletionTest_SingleName_NoPrefix

Starting a statement in a global context:
- CompletionTest_VariableType_NoPrefix
Comment 1 Bryan Wilkinson CLA 2007-01-25 14:02:48 EST
Created attachment 57541 [details]
proposed patch

The source of the problem is actually the scanner for the GNUCPPSourceParser.  Once the scanner reaches the last character to be processed for the completion it creates a COMPLETION token if it is in the process of scanning an identifier.  If the parser looks past the COMPLETION token, it will only find EOC (End Of Completion) tokens.

The problem occurs if an identifier is not being scanned when the last character is reached.  Then, an EOC token is returned.  The GNUCPPCompletionParser, however, still requires a COMPLETION token to properly create a completion node.  So simply returning a COMPLETION token instead should do the job.

A couple of small changes were also made in GNUCPPSourceParser to handle COMPLETION tokens during the parsing of base specifiers.

The patch fixes completion node creation (but not necessarily completion proposal generation) for the following cases:
- CompletionTest_ArgumentType_NoPrefix
- CompletionTest_ArgumentType_NoPrefix2
- CompletionTest_ClassReference_NoPrefix
- CompletionTest_ExceptionReference_NoPrefix
- CompletionTest_FieldType_NoPrefix
- CompletionTest_FieldType_NoPrefix2
- CompletionTest_NamespaceRef_NoPrefix
- CompletionTest_NewTypeReference_NoPrefix
- CompletionTest_SingleName_Method_NoPrefix
- CompletionTest_SingleName_NoPrefix
- CompletionTest_VariableType_NoPrefix

The following cases still do not produce completion nodes:
- CompletionTest_MacroRef_NoPrefix
- CompletionTest_MacroRef_Prefix

However, this is because the GNUCPPSourceParser is not responsible for preprocessor directives.  In fact, there is no completion processing at all for preprocessor directives, which is another problem altogether.
Comment 2 Anton Leherbauer CLA 2007-01-26 10:36:52 EST
Great! A tiny patch but a big step forward for code completion.
Comment 3 Anton Leherbauer CLA 2007-01-26 10:48:22 EST
I have applied the patch and updated the tests.
Together with the patch for bug 169480 most of those tests actually succeed.
Comment 4 Norbert Plött CLA 2007-01-29 02:34:05 EST
(In reply to comment #3)
> I have applied the patch and updated the tests.
> Together with the patch for bug 169480 most of those tests actually succeed.

This is _impressive_, and I am quite happy that my labor in preparing this report was not in vain ...

Anton, will this be in 3.1.2?
Comment 5 Anton Leherbauer CLA 2007-01-29 03:59:59 EST
Although the patch is quite "harmless", I'd rather not given that 3.1.2 release date is not far ahead.