Some times codecompletion stops working, see the video on the link and the attached project.
Looks like the issue only happens when the struct
struct _READ_DATA { uint32_t addr; uint32_t size; } read_data, *pread_data;
is declared inside the function, if I move the declaration outside the function the issue doesn't happen.
It also seems to only affect autocompletion inside the function there the previous struct was declared,
if I move to other function autocompletion is working.
Reparsing the project makes autocompletion work again but read_data
and pread_data
are never shown in the list.
https://drive.google.com/open?id=1hNgStc4F1fWPXsv8k0hvWhmanfPaiuyM
I'm running C::B svn build rev 11558, SDK version 1.37.0, scintilla version 3.7.5, wx3.0.4 on Debian testing 64bits.
Thanks for the report.
I will take some time to debug it.
BTW: The screen shot application is quite good. Can you tell me which one do you use, thanks.
I debugged a while, for simplicity, I use such testing code:
When I hit the dot key after the " read_data", I see the call stack:
You see, the "struct IN" is simplified to the buffer, thus all the contents of the struct IN is lost.
I think the function call m_Parser->ParseBuffer() will parse the simplified buffer.
So, the solution here is: we don't need such simplification of the buffer, right?
The simplification is just try to remove the nested { xxx xxx xxx }.
Seems like the issue is somewhere else, I've modified the code to not remove the struct definition
It doesn't remove (or prevent not adding) the definition from
buffer
but it is still not suggestingread_data
orpread_data
.OK, I apply your changes, and do some further test. I enabled the "Debug SmartSense" (set the s_DebugSmartSense variable to true), and have the following result in the C::B's Debug log.
It looks like the IN is not parsed correctly.
I think I find the reason. It is located in the in plugins\codecompletion\parser\parserthread.cpp, around the line 1584, in the function body Token* ParserThread::DoAddToken()
You look at the line:
When parsing the function body, it looks like "m_Options.parentIdxOfBuffer != -1" is true. So, the function Token is set as the finalParent of the new created Token.
Thus:
when we add the "addr" as a new Token, the parent should be the "struct IN", not the function "main".
But with the above code, the function "main" is set as the parent, which is not correct.
We can simply remove this condition check, but I'm not sure this cause any other issue.
With the above changes, It still get failed.
It looks like this is wrong?
Surely IN is not a scope containing the current carret (code completion) position.
If the two line
were removed, there are extra errors.
This is cause by the member variable "m_LastParent". When we start parsing the function body of the main(), we should set the m_LastParent as the Token "main". While we enter into the enum IN's body, the m_LastParent should be Token "IN".
Some sample code of handling this is like below:
Last edit: ollydbg 2019-02-20
Now, with this patch:
I have such log:
But I'm not sure why the result is 0.
I think search "read_data" under "386" (The main Token) should return at least one match.
But it looks like "read_data" is not parsed correctly.
With the above changes, this sample code works OK
But:
They should have Parent as "main", but now they are empty parent(the global token), which is wrong.
Last edit: ollydbg 2019-02-20
Hi ollydbg, I haven't tried your changes yet but I found this comment on src/plugins/codecompletion/parser/parserthread.cpp:624
And that happens at the end of parsing the IN struct definition but the function doesn't return, is that behavior correct?
As the method DoParse doesn't return upon finding the struct closing '}' it continues to parse the
read_data
and*pread_data
declarations but it fails at line 1231 because m_Str is emptyI just removed the if condition I mentioned before (I don't know if the condition or the comment is wrong), applied your changes and now it works better, this is the log
But as you can see it doesn't parse the
read_data2
declaration.EDIT: I also applied your changes.
Last edit: Fabián Inostroza 2019-02-24
Idealy, the body of the main should parse like below, I have add the comments there
From your log message:
Yes, I think the variable
read_data2
is lost, so there are some parsing issue.I think this code is wrong here as you already found:
Especially the if condition here:
Even in parsing the function body, we may have recursive call of DoParse, so we should return here.
I think the if condition used here are for simplicity, because a user may write some { } in side the function body, for simplicity, we don't handle those {} in the function body. This will make our parser failed to handle the struct defined inside the function body as your test code.
Now, for this code, there is a check:
But in your test code, the "OUT" is not defined in the main, but in global scope, so it get failed.
I simple solution is we can remove such check. I don't have much time to debug it.
The interesting is "struct OUT * p;" such patter works.