mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-29 05:43:44 +02:00
codetools: FindDeclarationAndOverload return function result type when cursor on colon
git-svn-id: trunk@20263 -
This commit is contained in:
parent
f23aae7dab
commit
802d6ef059
@ -198,20 +198,16 @@ begin
|
||||
|
||||
CacheWasUsed:=false;
|
||||
|
||||
if IsIdentChar[Code.Source[CodePos.P]] then begin
|
||||
//DebugLn(['TDeclarationInheritanceCache.FindDeclarations searching ',Code.Filename,'(X=',X,',Y=',Y,')']);
|
||||
//DebugLn(['TDeclarationInheritanceCache.FindDeclarations searching ',Code.Filename,'(X=',X,',Y=',Y,')']);
|
||||
|
||||
// ask the codetools
|
||||
if OnFindDeclarations(Code,X,Y,ListOfPCodeXYPosition,[])
|
||||
and (ListOfPCodeXYPosition<>nil)
|
||||
and (ListOfPCodeXYPosition.Count>0) then begin
|
||||
Result:=true;
|
||||
end else begin
|
||||
FreeAndNil(ListOfPCodeXYPosition);
|
||||
Result:=false;
|
||||
end;
|
||||
// ask the codetools
|
||||
if OnFindDeclarations(Code,X,Y,ListOfPCodeXYPosition,[])
|
||||
and (ListOfPCodeXYPosition<>nil)
|
||||
and (ListOfPCodeXYPosition.Count>0) then begin
|
||||
Result:=true;
|
||||
end else begin
|
||||
exit;
|
||||
FreeAndNil(ListOfPCodeXYPosition);
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
// save to cache
|
||||
|
@ -3592,6 +3592,25 @@ var
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
function StartPositionAtFunctionResult: boolean;
|
||||
var
|
||||
Node: TCodeTreeNode;
|
||||
begin
|
||||
Result:=false;
|
||||
if (NewNode.Desc=ctnProcedureHead)
|
||||
and PositionInFuncResultName(NewNode,CleanPos) then begin
|
||||
Node:=NewNode.FirstChild;
|
||||
if Node=nil then exit;
|
||||
if Node.Desc=ctnParameterList then Node:=Node.NextBrother;
|
||||
if Node=nil then exit;
|
||||
if Node.Desc in [ctnVarDefinition,ctnIdentifier] then begin
|
||||
// return the function result type or the operator variable name
|
||||
NewNode:=Node;
|
||||
Result:=true;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
Result:=true;
|
||||
ListOfPCodeXYPosition:=nil;
|
||||
@ -3613,6 +3632,11 @@ begin
|
||||
AddPos;
|
||||
if fdlfIfStartIsDefinitionStop in Flags then exit;
|
||||
end;
|
||||
if StartPositionAtFunctionResult then begin
|
||||
AddPos;
|
||||
// the function result has no overloads => stop search
|
||||
exit;
|
||||
end;
|
||||
|
||||
CurCursorPos:=CursorPos;
|
||||
CurTool:=Self;
|
||||
|
@ -104,6 +104,8 @@ type
|
||||
SkipClassName: boolean);
|
||||
function PositionInProcName(ProcNode: TCodeTreeNode;
|
||||
SkipClassName: boolean; CleanPos: integer): boolean;
|
||||
function PositionInFuncResultName(ProcNode: TCodeTreeNode;
|
||||
CleanPos: integer): boolean;
|
||||
function ProcNodeHasParamList(ProcNode: TCodeTreeNode): boolean;
|
||||
function NodeIsInAMethod(Node: TCodeTreeNode): boolean;
|
||||
function NodeIsMethodBody(ProcNode: TCodeTreeNode): boolean;
|
||||
@ -834,6 +836,45 @@ begin
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.PositionInFuncResultName(ProcNode: TCodeTreeNode;
|
||||
CleanPos: integer): boolean;
|
||||
// true if position between ) and :
|
||||
begin
|
||||
Result:=false;
|
||||
if ProcNode.Desc=ctnProcedure then begin
|
||||
ProcNode:=ProcNode.FirstChild;
|
||||
if ProcNode=nil then exit;
|
||||
end;
|
||||
// read behind parameter list
|
||||
if ProcNode.Desc<>ctnProcedureHead then exit;
|
||||
if (ProcNode.FirstChild<>nil) and (ProcNode.FirstChild.Desc=ctnParameterList)
|
||||
then begin
|
||||
if (CleanPos<ProcNode.FirstChild.EndPos) then
|
||||
exit;
|
||||
MoveCursorToCleanPos(ProcNode.FirstChild.EndPos);
|
||||
end else begin
|
||||
MoveCursorToNodeStart(ProcNode.FirstChild);
|
||||
ReadNextAtom;
|
||||
if AtomIsIdentifier(false) then begin
|
||||
// read name
|
||||
ReadNextAtom;
|
||||
if (CurPos.Flag=cafPoint) then begin
|
||||
// read method name
|
||||
ReadNextAtom;
|
||||
ReadNextAtom;
|
||||
end;
|
||||
end;
|
||||
if CurPos.Flag=cafRoundBracketOpen then
|
||||
if not ReadTilBracketClose(false) then exit;
|
||||
end;
|
||||
if CurPos.StartPos>CleanPos then exit;
|
||||
// read optional result variable (e.g. operator can have them)
|
||||
ReadNextAtom;
|
||||
if AtomIsIdentifier(false) then ReadNextAtom;
|
||||
if CurPos.Flag<>cafColon then exit;
|
||||
Result:=CleanPos<=CurPos.StartPos;
|
||||
end;
|
||||
|
||||
function TPascalReaderTool.MoveCursorToPropType(PropNode: TCodeTreeNode
|
||||
): boolean;
|
||||
begin
|
||||
|
18
ide/main.pp
18
ide/main.pp
@ -13341,22 +13341,6 @@ var
|
||||
begin
|
||||
if (SrcEdit=nil) then exit;
|
||||
|
||||
// check if there is an identifier
|
||||
case ToolStatus of
|
||||
itNone: begin
|
||||
Identifier := SrcEdit.GetWordFromCaret(CaretPos);
|
||||
if (Identifier='') or (not IsValidIdent(Identifier)) then exit;
|
||||
end;
|
||||
itDebugger: begin
|
||||
// Identifier := SrcEdit.GetWordFromCaretEx(CaretPos,
|
||||
// ['A'..'Z', 'a'..'z', '0'..'9', '(', '[', '.', ''''],
|
||||
// ['A'..'Z', 'a'..'z', '0'..'9', ')', ']', '^', '''']);
|
||||
Identifier := SrcEdit.GetWordFromCaret(CaretPos);
|
||||
if Identifier = '' then Exit;
|
||||
end;
|
||||
else
|
||||
Exit;
|
||||
end;
|
||||
SourceNotebook.SetActiveSE(SrcEdit);
|
||||
|
||||
if not BeginCodeTool(ActiveSrcEdit, ActiveUnitInfo,
|
||||
@ -13375,6 +13359,8 @@ begin
|
||||
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TMainIDE.OnSrcNotebookShowHintForSource B');{$ENDIF}
|
||||
end;
|
||||
itDebugger: begin
|
||||
Identifier := SrcEdit.GetWordFromCaret(CaretPos);
|
||||
if Identifier = '' then Exit;
|
||||
if SrcEdit.SelectionAvailable
|
||||
and SrcEdit.CaretInSelection(CaretPos)
|
||||
then Expression := SrcEdit.GetText(True)
|
||||
|
Loading…
Reference in New Issue
Block a user