From 7b17aaf0b30e19d755c75b416e7d6a688618ddef Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 25 Jun 2013 09:33:37 +0000 Subject: [PATCH] codetools: identifier completion: ignore parser errors when gathering keywords, bug #20919 git-svn-id: trunk@41886 - --- components/codetools/identcompletiontool.pas | 286 ++++++++++--------- 1 file changed, 146 insertions(+), 140 deletions(-) diff --git a/components/codetools/identcompletiontool.pas b/components/codetools/identcompletiontool.pas index 91aa6618ea..60b6f5463c 100644 --- a/components/codetools/identcompletiontool.pas +++ b/components/codetools/identcompletiontool.pas @@ -1637,161 +1637,167 @@ var p: Integer; NodeBehind: TCodeTreeNode; begin - Node:=Context.Node; - //debugln(['TIdentCompletionTool.GatherContextKeywords ',Node.DescAsString]); + try + Node:=Context.Node; + //debugln(['TIdentCompletionTool.GatherContextKeywords ',Node.DescAsString]); - ReadPriorAtomSafe(CleanPos); - //debugln(['TIdentCompletionTool.GatherContextKeywords prioratom=',CleanPosToStr(CurPos.StartPos),'=',GetAtom(CurPos)]); - NodeInFront:=nil; - if CurPos.StartPos>0 then - NodeInFront:=FindDeepestNodeAtPos(CurPos.StartPos,false); + ReadPriorAtomSafe(CleanPos); + //debugln(['TIdentCompletionTool.GatherContextKeywords prioratom=',CleanPosToStr(CurPos.StartPos),'=',GetAtom(CurPos)]); + NodeInFront:=nil; + if CurPos.StartPos>0 then + NodeInFront:=FindDeepestNodeAtPos(CurPos.StartPos,false); - NodeBehind:=nil; - MoveCursorToCleanPos(CleanPos); - ReadNextAtom; - //debugln(['TIdentCompletionTool.GatherContextKeywords nextatom=',CleanPosToStr(CurPos.StartPos),'=',GetAtom(CurPos)]); - if CurPos.StartPos>CleanPos then - NodeBehind:=FindDeepestNodeAtPos(CurPos.StartPos,false); + NodeBehind:=nil; + MoveCursorToCleanPos(CleanPos); + ReadNextAtom; + //debugln(['TIdentCompletionTool.GatherContextKeywords nextatom=',CleanPosToStr(CurPos.StartPos),'=',GetAtom(CurPos)]); + if CurPos.StartPos>CleanPos then + NodeBehind:=FindDeepestNodeAtPos(CurPos.StartPos,false); - //debugln(['TIdentCompletionTool.GatherContextKeywords Node=',Node.DescAsString,' NodeInFront=',NodeInFront.DescAsString,' NodeBehind=',NodeBehind.DescAsString]); + //debugln(['TIdentCompletionTool.GatherContextKeywords Node=',Node.DescAsString,' NodeInFront=',NodeInFront.DescAsString,' NodeBehind=',NodeBehind.DescAsString]); - case Node.Desc of - ctnClass,ctnObject,ctnRecordType,ctnObjCCategory,ctnObjCClass, - ctnClassPrivate,ctnClassProtected,ctnClassPublic,ctnClassPublished: - begin - Add('public'); - Add('private'); - Add('protected'); - Add('published'); - Add('procedure'); - Add('function'); - Add('property'); - if (Node.Desc=ctnClass) or (Node.Parent.Desc=ctnClass) then begin - Add('constructor'); - Add('destructor'); - end; - if (Node.Desc=ctnRecordType) or (Node.Parent.Desc=ctnRecordType) then begin - Add('case'); - end; - if (Node.LastChild<>nil) and (CleanPos>Node.LastChild.StartPos) - and (Node.LastChild.EndPos>Node.LastChild.StartPos) - and (Node.LastChild.EndPosnil) and (CleanPos>Node.LastChild.StartPos) + and (Node.LastChild.EndPos>Node.LastChild.StartPos) + and (Node.LastChild.EndPosnil then begin + if NodeInFront.Desc=ctnProcedure then + AddMethodSpecifiers; end; end; - if NodeInFront<>nil then begin - if NodeInFront.Desc=ctnProcedure then - AddMethodSpecifiers; - end; - end; - ctnClassInterface,ctnDispinterface,ctnObjCProtocol,ctnCPPClass: - begin - Add('procedure'); - Add('function'); - end; - - ctnInterface,ctnImplementation: - begin - if (Node.FirstChild=nil) - or ((Node.FirstChild.Desc<>ctnUsesSection) - and (Node.FirstChild.StartPos>=CleanPos)) - then - Add('uses'); - Add('type'); - Add('var'); - Add('const'); - Add('procedure'); - Add('function'); - Add('resourcestring'); - if Node.Desc=ctnInterface then begin - Add('property'); + ctnClassInterface,ctnDispinterface,ctnObjCProtocol,ctnCPPClass: + begin + Add('procedure'); + Add('function'); end; + + ctnInterface,ctnImplementation: + begin + if (Node.FirstChild=nil) + or ((Node.FirstChild.Desc<>ctnUsesSection) + and (Node.FirstChild.StartPos>=CleanPos)) + then + Add('uses'); + Add('type'); + Add('var'); + Add('const'); + Add('procedure'); + Add('function'); + Add('resourcestring'); + if Node.Desc=ctnInterface then begin + Add('property'); + end; + if (NodeBehind=nil) + or (NodeBehind.Desc in [ctnInitialization,ctnFinalization,ctnEndPoint,ctnBeginBlock]) + then begin + if Node.Desc=ctnInterface then + Add('implementation'); + Add('initialization'); + Add('finalization'); + end; + end; + + ctnInitialization: if (NodeBehind=nil) or (NodeBehind.Desc in [ctnInitialization,ctnFinalization,ctnEndPoint,ctnBeginBlock]) then begin - if Node.Desc=ctnInterface then - Add('implementation'); - Add('initialization'); - Add('finalization'); - end; - end; - - ctnInitialization: - if (NodeBehind=nil) - or (NodeBehind.Desc in [ctnInitialization,ctnFinalization,ctnEndPoint,ctnBeginBlock]) - then begin - Add('finalization'); - Add('begin'); - end; - - ctnProcedure: - begin - Add('begin'); - Add('type'); - Add('var'); - Add('const'); - Add('procedure'); - Add('function'); - end; - - ctnProcedureHead: - begin - MoveCursorBehindProcName(Node); - p:=CurPos.StartPos; - while (p>=1) and (Src[p] in [' ',#9]) do dec(p); - if CleanPos>=p then - AddMethodSpecifiers; - end; - - ctnVarDefinition: - if Node.Parent.Desc in [ctnClass,ctnObject,ctnRecordType,ctnObjCCategory,ctnObjCClass] - +AllClassBaseSections - then begin - Add('public'); - Add('private'); - Add('protected'); - Add('published'); - Add('procedure'); - Add('function'); - Add('property'); - if [cmsObjectiveC1,cmsObjectiveC2]*Scanner.CompilerModeSwitches<>[] then - begin - Add('required'); - Add('optional'); - end; - if (Node.Desc=ctnClass) or (Node.Parent.Desc=ctnClass) then begin - Add('constructor'); - Add('destructor'); - end; - if (Node.Desc=ctnRecordType) or (Node.Parent.Desc=ctnRecordType) then begin - Add('case'); - end; - end; - - ctnTypeSection,ctnVarSection,ctnConstSection,ctnLabelSection,ctnResStrSection, - ctnLibrary,ctnProgram: - begin - Add('type'); - Add('const'); - Add('var'); - Add('resourcestring'); - Add('procedure'); - Add('function'); - Add('property'); - if Node.Desc=ctnLibrary then begin - Add('initialization'); Add('finalization'); Add('begin'); end; + + ctnProcedure: + begin + Add('begin'); + Add('type'); + Add('var'); + Add('const'); + Add('procedure'); + Add('function'); + end; + + ctnProcedureHead: + begin + MoveCursorBehindProcName(Node); + p:=CurPos.StartPos; + while (p>=1) and (Src[p] in [' ',#9]) do dec(p); + if CleanPos>=p then + AddMethodSpecifiers; + end; + + ctnVarDefinition: + if Node.Parent.Desc in [ctnClass,ctnObject,ctnRecordType,ctnObjCCategory,ctnObjCClass] + +AllClassBaseSections + then begin + Add('public'); + Add('private'); + Add('protected'); + Add('published'); + Add('procedure'); + Add('function'); + Add('property'); + if [cmsObjectiveC1,cmsObjectiveC2]*Scanner.CompilerModeSwitches<>[] then + begin + Add('required'); + Add('optional'); + end; + if (Node.Desc=ctnClass) or (Node.Parent.Desc=ctnClass) then begin + Add('constructor'); + Add('destructor'); + end; + if (Node.Desc=ctnRecordType) or (Node.Parent.Desc=ctnRecordType) then begin + Add('case'); + end; + end; + + ctnTypeSection,ctnVarSection,ctnConstSection,ctnLabelSection,ctnResStrSection, + ctnLibrary,ctnProgram: + begin + Add('type'); + Add('const'); + Add('var'); + Add('resourcestring'); + Add('procedure'); + Add('function'); + Add('property'); + if Node.Desc=ctnLibrary then begin + Add('initialization'); + Add('finalization'); + Add('begin'); + end; + end; + + ctnProperty: + CheckProperty(Node); + end; - - ctnProperty: - CheckProperty(Node); - + except + // ignore parser errors + on E: ECodeToolError do ; + on E: ELinkScannerError do ; end; end;