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

View File

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