mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 05:49:15 +02:00
codetools: extended ctnWithStatement EndPos to next atom when possible, bug #7970
git-svn-id: trunk@15207 -
This commit is contained in:
parent
bc6912e30f
commit
a45d589f57
@ -6543,7 +6543,7 @@ begin
|
||||
// parse unit
|
||||
NewCodeTool.BuildTreeAndGetCleanPos(trAll,CodeXYPos,CleanCursorPos,[]);
|
||||
// find node at position
|
||||
ProcNode:=NewCodeTool.FindDeepestExpandedNodeAtPos(CleanCursorPos,true);
|
||||
ProcNode:=NewCodeTool.BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
if (ProcNode.Desc<>ctnProcedure)
|
||||
or (ProcNode.Parent=nil) then begin
|
||||
NewCodeTool.MoveCursorToNodeStart(ProcNode);
|
||||
|
@ -1140,7 +1140,7 @@ begin
|
||||
DebugLn('TFindDeclarationTool.FindDeclarationOfIdentifier B CleanCursorPos=',dbgs(CleanCursorPos));
|
||||
{$ENDIF}
|
||||
// find CodeTreeNode at cursor
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,true);
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
// search
|
||||
Params:=TFindDeclarationParams.Create;
|
||||
Params.ContextNode:=CursorNode;
|
||||
@ -1319,8 +1319,7 @@ begin
|
||||
{$ENDIF}
|
||||
// find CodeTreeNode at cursor
|
||||
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,
|
||||
true);
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
if (fsfFindMainDeclaration in SearchSmartFlags)
|
||||
and CleanPosIsDeclarationIdentifier(CleanCursorPos,CursorNode)
|
||||
then begin
|
||||
@ -3389,7 +3388,7 @@ begin
|
||||
|
||||
NodeList:=TFPList.Create;
|
||||
NewTool:=Self;
|
||||
NewNode:=FindDeepestExpandedNodeAtPos(CleanPos,true);
|
||||
NewNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanPos,true);
|
||||
NewPos:=CursorPos;
|
||||
if StartPositionAtDefinition then
|
||||
AddPos;
|
||||
@ -3579,7 +3578,7 @@ var
|
||||
if CleanPosToCaret(StartPos,ReferencePos) then
|
||||
debugln(' x=',dbgs(ReferencePos.X),' y=',dbgs(ReferencePos.Y),' ',ReferencePos.Code.Filename);
|
||||
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,StartPos,true);
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(StartPos,true);
|
||||
debugln(' CursorNode=',CursorNode.DescAsString,' Forward=',dbgs(CursorNode.SubDesc and ctnsForwardDeclaration));
|
||||
|
||||
if (DeclarationTool=Self)
|
||||
@ -3772,7 +3771,7 @@ var
|
||||
DeclarationTool.BuildTreeAndGetCleanPos(trAll,CursorPos,CleanDeclCursorPos,
|
||||
[]);
|
||||
DeclarationNode:=DeclarationTool.BuildSubTreeAndFindDeepestNodeAtPos(
|
||||
DeclarationTool.Tree.Root,CleanDeclCursorPos,true);
|
||||
CleanDeclCursorPos,true);
|
||||
Identifier:=DeclarationTool.ExtractIdentifier(CleanDeclCursorPos);
|
||||
if Identifier='' then begin
|
||||
debugln('FindDeclarationNode Identifier="',Identifier,'"');
|
||||
|
@ -1241,7 +1241,7 @@ begin
|
||||
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
||||
|
||||
// find node at position
|
||||
CursorNode:=FindDeepestExpandedNodeAtPos(CleanCursorPos,true);
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
if CurrentIdentifierList<>nil then begin
|
||||
StartContext:=CurrentIdentifierList.StartContext;
|
||||
StartContext.Node:=CursorNode;
|
||||
@ -1716,7 +1716,7 @@ begin
|
||||
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
||||
|
||||
// find node at position
|
||||
CursorNode:=FindDeepestExpandedNodeAtPos(CleanCursorPos,true);
|
||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
|
||||
// if cursor is on type node, find class node
|
||||
if CursorNode.Desc=ctnTypeDefinition then
|
||||
@ -2033,7 +2033,7 @@ var
|
||||
begin
|
||||
if not (iliNodeHashValid in Flags) then exit(true);
|
||||
//DebugLn(['TIdentifierListItem.RestoreNode ',Identifier]);
|
||||
NewNode:=Tool.FindDeepestExpandedNodeAtPos(FNodeStartPos,false);
|
||||
NewNode:=Tool.BuildSubTreeAndFindDeepestNodeAtPos(FNodeStartPos,false);
|
||||
Result:=false;
|
||||
if (NewNode=nil) or (NewNode.StartPos<>FNodeStartPos)
|
||||
or (NewNode.Desc<>FNodeDesc) then begin
|
||||
|
@ -223,6 +223,8 @@ type
|
||||
procedure BuildSubTree(CleanCursorPos: integer); virtual;
|
||||
procedure BuildSubTree(ANode: TCodeTreeNode); virtual;
|
||||
function NodeNeedsBuildSubTree(ANode: TCodeTreeNode): boolean; virtual;
|
||||
function BuildSubTreeAndFindDeepestNodeAtPos(
|
||||
P: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||
function BuildSubTreeAndFindDeepestNodeAtPos(StartNode: TCodeTreeNode;
|
||||
P: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||
|
||||
@ -2418,7 +2420,16 @@ function TPascalParserTool.ReadWithStatement(ExceptionOnError,
|
||||
if CreateNodes then begin
|
||||
EndPos:=CurPos.EndPos;
|
||||
if CurNode.Desc=ctnWithStatement then begin
|
||||
if not (CurPos.Flag in [cafSemicolon,cafEnd]) then begin
|
||||
// the with statement is valid until the next atom
|
||||
// this is important for context when cursor is behind last atom of the
|
||||
// with statement, but in front of the next atom
|
||||
ReadNextAtom;
|
||||
EndPos:=CurPos.StartPos;
|
||||
UndoReadNextAtom;
|
||||
end;
|
||||
CurNode.EndPos:=EndPos;
|
||||
//DebugLn(['CloseNodes "',copy(Src,CurNode.StartPos,CurNode.EndPos-CurNode.STartPos),'"']);
|
||||
EndChildNode; // ctnWithStatement
|
||||
end;
|
||||
WithVarNode:=CurNode;
|
||||
@ -4182,16 +4193,22 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos(P: integer;
|
||||
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||
begin
|
||||
Result:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,P,ExceptionOnNotFound);
|
||||
end;
|
||||
|
||||
function TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos(
|
||||
StartNode: TCodeTreeNode; P: integer; ExceptionOnNotFound: boolean
|
||||
): TCodeTreeNode;
|
||||
begin
|
||||
Result:=FindDeepestNodeAtPos(StartNode,P,ExceptionOnNotFound);
|
||||
debugln('TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos A ',Result.DescAsString,' ',dbgs(NodeNeedsBuildSubTree(Result)));
|
||||
//debugln('TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos A ',Result.DescAsString,' ',dbgs(NodeNeedsBuildSubTree(Result)));
|
||||
while NodeNeedsBuildSubTree(Result) do begin
|
||||
BuildSubTree(Result);
|
||||
Result:=FindDeepestNodeAtPos(Result,P,ExceptionOnNotFound);
|
||||
debugln('TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos B ',Result.DescAsString,' ',dbgs(NodeNeedsBuildSubTree(Result)));
|
||||
//debugln('TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos B ',Result.DescAsString,' ',dbgs(NodeNeedsBuildSubTree(Result)));
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -49,9 +49,6 @@ type
|
||||
protected
|
||||
CachedSourceName: string;
|
||||
public
|
||||
function FindDeepestExpandedNodeAtPos(CleanCursorPos: integer;
|
||||
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||
|
||||
// comments
|
||||
function CleanPosIsInComment(CleanPos, CleanCodePosInFront: integer;
|
||||
var CommentStart, CommentEnd: integer): boolean;
|
||||
@ -1138,23 +1135,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.FindDeepestExpandedNodeAtPos(
|
||||
CleanCursorPos: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||
begin
|
||||
Result:=FindDeepestNodeAtPos(CleanCursorPos,ExceptionOnNotFound);
|
||||
if Result=nil then exit;
|
||||
if Result.Desc in [ctnClass,ctnClassInterface] then begin
|
||||
BuildSubTreeForClass(Result);
|
||||
Result:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
if Result=nil then exit;
|
||||
end;
|
||||
if Result.Desc=ctnBeginBlock then begin
|
||||
BuildSubTreeForBeginBlock(Result);
|
||||
Result:=FindDeepestNodeAtPos(CleanCursorPos,true);
|
||||
if Result=nil then exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.FindVarNode(StartNode: TCodeTreeNode;
|
||||
const UpperVarName: string): TCodeTreeNode;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user