mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 19:59:14 +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
|
// parse unit
|
||||||
NewCodeTool.BuildTreeAndGetCleanPos(trAll,CodeXYPos,CleanCursorPos,[]);
|
NewCodeTool.BuildTreeAndGetCleanPos(trAll,CodeXYPos,CleanCursorPos,[]);
|
||||||
// find node at position
|
// find node at position
|
||||||
ProcNode:=NewCodeTool.FindDeepestExpandedNodeAtPos(CleanCursorPos,true);
|
ProcNode:=NewCodeTool.BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
if (ProcNode.Desc<>ctnProcedure)
|
if (ProcNode.Desc<>ctnProcedure)
|
||||||
or (ProcNode.Parent=nil) then begin
|
or (ProcNode.Parent=nil) then begin
|
||||||
NewCodeTool.MoveCursorToNodeStart(ProcNode);
|
NewCodeTool.MoveCursorToNodeStart(ProcNode);
|
||||||
|
@ -1140,7 +1140,7 @@ begin
|
|||||||
DebugLn('TFindDeclarationTool.FindDeclarationOfIdentifier B CleanCursorPos=',dbgs(CleanCursorPos));
|
DebugLn('TFindDeclarationTool.FindDeclarationOfIdentifier B CleanCursorPos=',dbgs(CleanCursorPos));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// find CodeTreeNode at cursor
|
// find CodeTreeNode at cursor
|
||||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,true);
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
// search
|
// search
|
||||||
Params:=TFindDeclarationParams.Create;
|
Params:=TFindDeclarationParams.Create;
|
||||||
Params.ContextNode:=CursorNode;
|
Params.ContextNode:=CursorNode;
|
||||||
@ -1319,8 +1319,7 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
// find CodeTreeNode at cursor
|
// find CodeTreeNode at cursor
|
||||||
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
if (Tree.Root<>nil) and (Tree.Root.StartPos<=CleanCursorPos) then begin
|
||||||
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,CleanCursorPos,
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
true);
|
|
||||||
if (fsfFindMainDeclaration in SearchSmartFlags)
|
if (fsfFindMainDeclaration in SearchSmartFlags)
|
||||||
and CleanPosIsDeclarationIdentifier(CleanCursorPos,CursorNode)
|
and CleanPosIsDeclarationIdentifier(CleanCursorPos,CursorNode)
|
||||||
then begin
|
then begin
|
||||||
@ -3389,7 +3388,7 @@ begin
|
|||||||
|
|
||||||
NodeList:=TFPList.Create;
|
NodeList:=TFPList.Create;
|
||||||
NewTool:=Self;
|
NewTool:=Self;
|
||||||
NewNode:=FindDeepestExpandedNodeAtPos(CleanPos,true);
|
NewNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanPos,true);
|
||||||
NewPos:=CursorPos;
|
NewPos:=CursorPos;
|
||||||
if StartPositionAtDefinition then
|
if StartPositionAtDefinition then
|
||||||
AddPos;
|
AddPos;
|
||||||
@ -3579,7 +3578,7 @@ var
|
|||||||
if CleanPosToCaret(StartPos,ReferencePos) then
|
if CleanPosToCaret(StartPos,ReferencePos) then
|
||||||
debugln(' x=',dbgs(ReferencePos.X),' y=',dbgs(ReferencePos.Y),' ',ReferencePos.Code.Filename);
|
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));
|
debugln(' CursorNode=',CursorNode.DescAsString,' Forward=',dbgs(CursorNode.SubDesc and ctnsForwardDeclaration));
|
||||||
|
|
||||||
if (DeclarationTool=Self)
|
if (DeclarationTool=Self)
|
||||||
@ -3772,7 +3771,7 @@ var
|
|||||||
DeclarationTool.BuildTreeAndGetCleanPos(trAll,CursorPos,CleanDeclCursorPos,
|
DeclarationTool.BuildTreeAndGetCleanPos(trAll,CursorPos,CleanDeclCursorPos,
|
||||||
[]);
|
[]);
|
||||||
DeclarationNode:=DeclarationTool.BuildSubTreeAndFindDeepestNodeAtPos(
|
DeclarationNode:=DeclarationTool.BuildSubTreeAndFindDeepestNodeAtPos(
|
||||||
DeclarationTool.Tree.Root,CleanDeclCursorPos,true);
|
CleanDeclCursorPos,true);
|
||||||
Identifier:=DeclarationTool.ExtractIdentifier(CleanDeclCursorPos);
|
Identifier:=DeclarationTool.ExtractIdentifier(CleanDeclCursorPos);
|
||||||
if Identifier='' then begin
|
if Identifier='' then begin
|
||||||
debugln('FindDeclarationNode Identifier="',Identifier,'"');
|
debugln('FindDeclarationNode Identifier="',Identifier,'"');
|
||||||
|
@ -1241,7 +1241,7 @@ begin
|
|||||||
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
||||||
|
|
||||||
// find node at position
|
// find node at position
|
||||||
CursorNode:=FindDeepestExpandedNodeAtPos(CleanCursorPos,true);
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
if CurrentIdentifierList<>nil then begin
|
if CurrentIdentifierList<>nil then begin
|
||||||
StartContext:=CurrentIdentifierList.StartContext;
|
StartContext:=CurrentIdentifierList.StartContext;
|
||||||
StartContext.Node:=CursorNode;
|
StartContext.Node:=CursorNode;
|
||||||
@ -1716,7 +1716,7 @@ begin
|
|||||||
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
[{$IFNDEF DisableIgnoreErrorAfter}btSetIgnoreErrorPos{$ENDIF}]);
|
||||||
|
|
||||||
// find node at position
|
// find node at position
|
||||||
CursorNode:=FindDeepestExpandedNodeAtPos(CleanCursorPos,true);
|
CursorNode:=BuildSubTreeAndFindDeepestNodeAtPos(CleanCursorPos,true);
|
||||||
|
|
||||||
// if cursor is on type node, find class node
|
// if cursor is on type node, find class node
|
||||||
if CursorNode.Desc=ctnTypeDefinition then
|
if CursorNode.Desc=ctnTypeDefinition then
|
||||||
@ -2033,7 +2033,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if not (iliNodeHashValid in Flags) then exit(true);
|
if not (iliNodeHashValid in Flags) then exit(true);
|
||||||
//DebugLn(['TIdentifierListItem.RestoreNode ',Identifier]);
|
//DebugLn(['TIdentifierListItem.RestoreNode ',Identifier]);
|
||||||
NewNode:=Tool.FindDeepestExpandedNodeAtPos(FNodeStartPos,false);
|
NewNode:=Tool.BuildSubTreeAndFindDeepestNodeAtPos(FNodeStartPos,false);
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if (NewNode=nil) or (NewNode.StartPos<>FNodeStartPos)
|
if (NewNode=nil) or (NewNode.StartPos<>FNodeStartPos)
|
||||||
or (NewNode.Desc<>FNodeDesc) then begin
|
or (NewNode.Desc<>FNodeDesc) then begin
|
||||||
|
@ -223,6 +223,8 @@ type
|
|||||||
procedure BuildSubTree(CleanCursorPos: integer); virtual;
|
procedure BuildSubTree(CleanCursorPos: integer); virtual;
|
||||||
procedure BuildSubTree(ANode: TCodeTreeNode); virtual;
|
procedure BuildSubTree(ANode: TCodeTreeNode); virtual;
|
||||||
function NodeNeedsBuildSubTree(ANode: TCodeTreeNode): boolean; virtual;
|
function NodeNeedsBuildSubTree(ANode: TCodeTreeNode): boolean; virtual;
|
||||||
|
function BuildSubTreeAndFindDeepestNodeAtPos(
|
||||||
|
P: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||||
function BuildSubTreeAndFindDeepestNodeAtPos(StartNode: TCodeTreeNode;
|
function BuildSubTreeAndFindDeepestNodeAtPos(StartNode: TCodeTreeNode;
|
||||||
P: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
|
P: integer; ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||||
|
|
||||||
@ -2418,7 +2420,16 @@ function TPascalParserTool.ReadWithStatement(ExceptionOnError,
|
|||||||
if CreateNodes then begin
|
if CreateNodes then begin
|
||||||
EndPos:=CurPos.EndPos;
|
EndPos:=CurPos.EndPos;
|
||||||
if CurNode.Desc=ctnWithStatement then begin
|
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;
|
CurNode.EndPos:=EndPos;
|
||||||
|
//DebugLn(['CloseNodes "',copy(Src,CurNode.StartPos,CurNode.EndPos-CurNode.STartPos),'"']);
|
||||||
EndChildNode; // ctnWithStatement
|
EndChildNode; // ctnWithStatement
|
||||||
end;
|
end;
|
||||||
WithVarNode:=CurNode;
|
WithVarNode:=CurNode;
|
||||||
@ -4182,16 +4193,22 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos(P: integer;
|
||||||
|
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||||
|
begin
|
||||||
|
Result:=BuildSubTreeAndFindDeepestNodeAtPos(Tree.Root,P,ExceptionOnNotFound);
|
||||||
|
end;
|
||||||
|
|
||||||
function TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos(
|
function TPascalParserTool.BuildSubTreeAndFindDeepestNodeAtPos(
|
||||||
StartNode: TCodeTreeNode; P: integer; ExceptionOnNotFound: boolean
|
StartNode: TCodeTreeNode; P: integer; ExceptionOnNotFound: boolean
|
||||||
): TCodeTreeNode;
|
): TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
Result:=FindDeepestNodeAtPos(StartNode,P,ExceptionOnNotFound);
|
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
|
while NodeNeedsBuildSubTree(Result) do begin
|
||||||
BuildSubTree(Result);
|
BuildSubTree(Result);
|
||||||
Result:=FindDeepestNodeAtPos(Result,P,ExceptionOnNotFound);
|
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;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -49,9 +49,6 @@ type
|
|||||||
protected
|
protected
|
||||||
CachedSourceName: string;
|
CachedSourceName: string;
|
||||||
public
|
public
|
||||||
function FindDeepestExpandedNodeAtPos(CleanCursorPos: integer;
|
|
||||||
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
|
||||||
|
|
||||||
// comments
|
// comments
|
||||||
function CleanPosIsInComment(CleanPos, CleanCodePosInFront: integer;
|
function CleanPosIsInComment(CleanPos, CleanCodePosInFront: integer;
|
||||||
var CommentStart, CommentEnd: integer): boolean;
|
var CommentStart, CommentEnd: integer): boolean;
|
||||||
@ -1138,23 +1135,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
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;
|
function TPascalReaderTool.FindVarNode(StartNode: TCodeTreeNode;
|
||||||
const UpperVarName: string): TCodeTreeNode;
|
const UpperVarName: string): TCodeTreeNode;
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user