CodeTools: Don't throw an error with "(" inside a comment in front of unit. Issue #32235.

git-svn-id: trunk@56054 -
This commit is contained in:
juha 2017-10-14 16:12:50 +00:00
parent a66ce4f9b5
commit 8e89ff11f9

View File

@ -408,9 +408,9 @@ type
CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions); CleanPos: integer; BeautifyCodeOptions: TBeautifyCodeOptions);
procedure InitCollectIdentifiers(const CursorPos: TCodeXYPosition; procedure InitCollectIdentifiers(const CursorPos: TCodeXYPosition;
var IdentifierList: TIdentifierList); var IdentifierList: TIdentifierList);
procedure ParseSourceTillCollectionStart(const CursorPos: TCodeXYPosition; function ParseSourceTillCollectionStart(const CursorPos: TCodeXYPosition;
out CleanCursorPos: integer; out CursorNode: TCodeTreeNode; out CleanCursorPos: integer; out CursorNode: TCodeTreeNode;
out IdentStartPos, IdentEndPos: integer); out IdentStartPos, IdentEndPos: integer): boolean;
function FindIdentifierStartPos(const CursorPos: TCodeXYPosition function FindIdentifierStartPos(const CursorPos: TCodeXYPosition
): TCodeXYPosition; ): TCodeXYPosition;
procedure FindCollectionContext(Params: TFindDeclarationParams; procedure FindCollectionContext(Params: TFindDeclarationParams;
@ -2005,13 +2005,14 @@ begin
CurrentIdentifierList.StartContext:=StartContext; CurrentIdentifierList.StartContext:=StartContext;
end; end;
procedure TIdentCompletionTool.ParseSourceTillCollectionStart( function TIdentCompletionTool.ParseSourceTillCollectionStart(
const CursorPos: TCodeXYPosition; out CleanCursorPos: integer; const CursorPos: TCodeXYPosition; out CleanCursorPos: integer;
out CursorNode: TCodeTreeNode; out IdentStartPos, IdentEndPos: integer); out CursorNode: TCodeTreeNode; out IdentStartPos, IdentEndPos: integer): boolean;
var var
StartContext: TFindContext; StartContext: TFindContext;
ContextPos: Integer; ContextPos: Integer;
begin begin
Result:=false;
CleanCursorPos:=0; CleanCursorPos:=0;
CursorNode:=nil; CursorNode:=nil;
IdentStartPos:=0; IdentStartPos:=0;
@ -2023,7 +2024,12 @@ begin
{$ENDIF} {$ENDIF}
BuildTreeAndGetCleanPos(trTillCursor,lsrEnd,CursorPos,CleanCursorPos, BuildTreeAndGetCleanPos(trTillCursor,lsrEnd,CursorPos,CleanCursorPos,
[btSetIgnoreErrorPos]); [btSetIgnoreErrorPos]);
if FindDeepestNodeAtPos(CleanCursorPos,false)=nil then begin // Return if CleanCursorPos is before Tree.Root.StartNode.
// For example a comment at the beginning of a unit.
if Tree.Root.StartPos>CleanCursorPos then
Exit;
if FindDeepestNodeAtPos(CleanCursorPos,false)=nil then
begin
debugln(['TIdentCompletionTool.ParseSourceTillCollectionStart', debugln(['TIdentCompletionTool.ParseSourceTillCollectionStart',
' BuildTreeAndGetCleanPos worked, but no node found.', ' BuildTreeAndGetCleanPos worked, but no node found.',
' CursorPos=',dbgs(CursorPos),' CleanCursorPos=',CleanCursorPos, ' CursorPos=',dbgs(CursorPos),' CleanCursorPos=',CleanCursorPos,
@ -2077,6 +2083,7 @@ begin
//DebugLn(['TIdentCompletionTool.ParseSourceTillCollectionStart ',dbgstr(copy(Src,IdentStartPos,10)),' CursorPos.X=',CursorPos.X,' LineLen=',CursorPos.Code.GetLineLength(CursorPos.Y-1),' ',CursorPos.Code.GetLine(CursorPos.Y-1)]); //DebugLn(['TIdentCompletionTool.ParseSourceTillCollectionStart ',dbgstr(copy(Src,IdentStartPos,10)),' CursorPos.X=',CursorPos.X,' LineLen=',CursorPos.Code.GetLineLength(CursorPos.Y-1),' ',CursorPos.Code.GetLine(CursorPos.Y-1)]);
if CursorPos.X>CursorPos.Code.GetLineLength(CursorPos.Y-1)+1 then if CursorPos.X>CursorPos.Code.GetLineLength(CursorPos.Y-1)+1 then
IdentStartPos:=IdentEndPos; IdentStartPos:=IdentEndPos;
Result:=true;
end; end;
function TIdentCompletionTool.FindIdentifierStartPos( function TIdentCompletionTool.FindIdentifierStartPos(
@ -2742,8 +2749,9 @@ begin
IdentStartXY:=FindIdentifierStartPos(CursorPos); IdentStartXY:=FindIdentifierStartPos(CursorPos);
if CheckCursorInCompilerDirective(IdentStartXY) then exit(true); if CheckCursorInCompilerDirective(IdentStartXY) then exit(true);
ParseSourceTillCollectionStart(IdentStartXY,CleanCursorPos,CursorNode, if not ParseSourceTillCollectionStart(IdentStartXY,CleanCursorPos,CursorNode,
IdentStartPos,IdentEndPos); IdentStartPos,IdentEndPos) then
Exit;
Params:=TFindDeclarationParams.Create(Self,CursorNode); Params:=TFindDeclarationParams.Create(Self,CursorNode);
try try
if CleanCursorPos=0 then ; if CleanCursorPos=0 then ;
@ -3198,17 +3206,17 @@ var
IdentifierList: TIdentifierList; IdentifierList: TIdentifierList;
IdentStartPos, IdentEndPos: integer; IdentStartPos, IdentEndPos: integer;
begin begin
CodeContexts:=nil;
Result:=false; Result:=false;
CodeContexts:=nil;
IdentifierList:=nil; IdentifierList:=nil;
CurrentIdentifierContexts:=CodeContexts; CurrentIdentifierContexts:=CodeContexts;
ActivateGlobalWriteLock; ActivateGlobalWriteLock;
try try
InitCollectIdentifiers(CursorPos,IdentifierList); InitCollectIdentifiers(CursorPos,IdentifierList);
ParseSourceTillCollectionStart(CursorPos,CleanCursorPos,CursorNode, if not ParseSourceTillCollectionStart(CursorPos,CleanCursorPos,CursorNode,
IdentStartPos,IdentEndPos); IdentStartPos,IdentEndPos) then
Exit;
Params:=TFindDeclarationParams.Create(Self, CursorNode); Params:=TFindDeclarationParams.Create(Self, CursorNode);
try try
if IdentStartPos=0 then ; if IdentStartPos=0 then ;