codetools: code context: now works with empty param lists

git-svn-id: trunk@9621 -
This commit is contained in:
mattias 2006-07-17 09:51:59 +00:00
parent 4091f9a74f
commit f0b0ae7a39
2 changed files with 26 additions and 18 deletions

View File

@ -6747,7 +6747,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
BracketAtom: TAtomPosition;
begin
BracketAtom:=CurPos;
{$IFDEF VerboseCPS}DebugLn('CheckBrackets ',GetAtom,' ',dbgs(BracketAtom));{$ENDIF}
{$IFDEF VerboseCPS}DebugLn('CheckBrackets "',GetAtom,'" BracketAtom=',dbgs(BracketAtom));{$ENDIF}
repeat
ReadNextAtom;
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin
@ -6786,16 +6786,17 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
Result:=false;
CurProcNameAtom:=CurPos;
CurParameterIndex:=0;
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList START ',GetAtom,' ',dbgs(CurProcNameAtom));{$ENDIF}
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList START "',GetAtom,'" ',dbgs(CurProcNameAtom));{$ENDIF}
ReadNextAtom;
if CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen] then begin
BracketAtom:=CurPos;
ParameterStart:=CurPos.EndPos;
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList Bracket=',GetAtom);{$ENDIF}
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList Bracket="',GetAtom,'"');{$ENDIF}
repeat
ReadNextAtom;
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList Atom=',GetAtom);{$ENDIF}
if CurPos.EndPos>=CleanCursorPos then begin
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList Atom="',GetAtom,'"');{$ENDIF}
if (CurPos.EndPos>CleanCursorPos)
or ((CurPos.EndPos=CleanCursorPos) and (CurPos.Flag=cafWord)) then begin
// parameter found => search parameter expression bounds e.g. ', parameter ,'
// important: this function should work, even the code behind
// CleanCursorPos is buggy
@ -6807,7 +6808,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
MoveCursorToCleanPos(ParameterStart);
repeat
ReadNextAtom;
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList parameter atom ',GetAtom);{$ENDIF}
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList parameter atom "',GetAtom,'"');{$ENDIF}
if (CurPos.Flag in [cafRoundBracketOpen,cafEdgedBracketOpen]) then
ReadTilBracketClose(false)
else
@ -6845,7 +6846,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
=(CurPos.Flag=cafRoundBracketClose)
then begin
// parameter list ended in front of Variable => continue search
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList parm list ended in front of cursor');{$ENDIF}
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList parameter list ended in front of cursor');{$ENDIF}
exit;
end else begin
// invalid closing bracket found
@ -6857,7 +6858,7 @@ function TFindDeclarationTool.CheckParameterSyntax(CursorNode: TCodeTreeNode;
ParameterStart:=CurPos.EndPos;
inc(CurParameterIndex);
end;
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList After parsing atom: atom=',GetAtom);{$ENDIF}
{$IFDEF VerboseCPS}DebugLn('CheckIdentifierAndParameterList After parsing atom. atom="',GetAtom,'"');{$ENDIF}
until (CurPos.EndPos>CleanCursorPos);
end;
end;

View File

@ -1171,7 +1171,7 @@ procedure TIdentCompletionTool.FindCollectionContext(
if WordIsPropertySpecifier.DoItUpperCase(UpperSrc,
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos)
then
// don't resolve property specifiers
// do not resolve property specifiers
Result:=IdentStartPos;
end;
end;
@ -1213,6 +1213,7 @@ begin
//DebugLn('TIdentCompletionTool.CollectAllContexts CurrentContexts.ProcNameAtom.StartPos=',dbgs(CurrentContexts.ProcNameAtom.StartPos));
if (CurrentContexts.ProcName='') then exit;
FoundContext.Tool.MoveCursorToProcName(FoundContext.Node,true);
//DebugLn(['TIdentCompletionTool.CollectAllContexts ProcName=',GetIdentifier(@FoundContext.Tool.Src[FoundContext.Tool.CurPos.StartPos])]);
if not FoundContext.Tool.CompareSrcIdentifier(
FoundContext.Tool.CurPos.StartPos,
CurrentContexts.ProcName)
@ -1396,12 +1397,17 @@ var
Result:=false;
// check if in a begin..end block
if (CursorNode.Desc<>ctnBeginBlock)
and (not CursorNode.HasParentOfType(ctnBeginBlock)) then exit;
// check is cursor is in a parameter list behind an identifier
and (not CursorNode.HasParentOfType(ctnBeginBlock)) then begin
DebugLn(['TIdentCompletionTool.FindCodeContext.CheckContextIsParameter not in a begin block']);
exit;
end;
// check if cursor is in a parameter list
if not CheckParameterSyntax(CursorNode, CleanCursorPos,
VarNameAtom, ProcNameAtom, ParameterIndex)
then exit;
if VarNameAtom.StartPos<1 then exit;
then begin
DebugLn(['TIdentCompletionTool.FindCodeContext.CheckContextIsParameter not in a parameter list']);
exit;
end;
//DebugLn('CheckContextIsParameter Variable=',GetAtom(VarNameAtom),' Proc=',GetAtom(ProcNameAtom),' ParameterIndex=',dbgs(ParameterIndex));
// it is a parameter -> create context
@ -1423,6 +1429,7 @@ var
FindCollectionContext(Params,ProcNameAtom.StartPos,CursorNode,
GatherContext,ContextExprStartPos,StartInSubContext);
//DebugLn(['CheckContextIsParameter StartInSubContext=',StartInSubContext,' ',GatherContext.Node.DescAsString,' "',copy(GatherContext.Tool.Src,GatherContext.Node.StartPos-20,25),'"']);
// gather declarations of all parameter lists
Params.ContextNode:=GatherContext.Node;
@ -1430,8 +1437,6 @@ var
Params.Flags:=[fdfSearchInAncestors,fdfCollect,fdfFindVariable];
if not StartInSubContext then
Include(Params.Flags,fdfSearchInParentNodes);
if Params.ContextNode.Desc in [ctnClass,ctnClassInterface] then
Exclude(Params.Flags,fdfSearchInParentNodes);
CurrentIdentifierList.Context:=GatherContext;
//DebugLn('CheckContextIsParameter searching procedure ...');
GatherContext.Tool.FindIdentifierInContext(Params);
@ -1460,10 +1465,13 @@ begin
FindContextClassAndAncestors(CursorPos,ClassAndAncestors);
if CursorNode<>nil then begin
if CheckContextIsParameter(Result) then exit;
if not CheckContextIsParameter(Result) then begin
DebugLn(['TIdentCompletionTool.FindCodeContext cursor not at parameter']);
exit;
end;
end;
if CodeContexts=nil then begin
if CurrentContexts=nil then begin
// create default
AddCollectionContext(Self,CursorNode);
end;
@ -1483,7 +1491,6 @@ begin
DeactivateGlobalWriteLock;
FreeAndNil(CurrentIdentifierList);
end;
Result:=false;
end;