mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-07 21:33:01 +01:00
codetools: fixed find enumerator in class helper
git-svn-id: trunk@50014 -
This commit is contained in:
parent
8dd0d53d28
commit
fb472b1555
@ -340,7 +340,7 @@ type
|
|||||||
OverrideMod, CallInherited, CallInheritedOnlyInElse: boolean;
|
OverrideMod, CallInherited, CallInheritedOnlyInElse: boolean;
|
||||||
SourceChanger: TSourceChangeCache;
|
SourceChanger: TSourceChangeCache;
|
||||||
out NewPos: TCodeXYPosition; out NewTopLine: integer;
|
out NewPos: TCodeXYPosition; out NewTopLine: integer;
|
||||||
LocalVarName: string = '' // default aSource
|
LocalVarName: string = '' // default is 'aSource'
|
||||||
): boolean;
|
): boolean;
|
||||||
|
|
||||||
// local variables
|
// local variables
|
||||||
@ -354,7 +354,7 @@ type
|
|||||||
function GuessTypeOfIdentifier(CursorPos: TCodeXYPosition;
|
function GuessTypeOfIdentifier(CursorPos: TCodeXYPosition;
|
||||||
out IsKeyword, IsSubIdentifier: boolean;
|
out IsKeyword, IsSubIdentifier: boolean;
|
||||||
out ExistingDefinition: TFindContext; // if it already exists
|
out ExistingDefinition: TFindContext; // if it already exists
|
||||||
out ListOfPFindContext: TFPList; // possible classes
|
out ListOfPFindContext: TFPList; // possible classes for adding as sub identifier
|
||||||
out NewExprType: TExpressionType; out NewType: string): boolean; // false = not at an identifier
|
out NewExprType: TExpressionType; out NewType: string): boolean; // false = not at an identifier
|
||||||
function DeclareVariableNearBy(InsertPos: TCodeXYPosition;
|
function DeclareVariableNearBy(InsertPos: TCodeXYPosition;
|
||||||
const VariableName, NewType, NewUnitName: string;
|
const VariableName, NewType, NewUnitName: string;
|
||||||
@ -6390,16 +6390,15 @@ function TCodeCompletionCodeTool.GuessTypeOfIdentifier(
|
|||||||
aclass.identifier:=<something>
|
aclass.identifier:=<something>
|
||||||
<something>:=aclass.identifier
|
<something>:=aclass.identifier
|
||||||
<something>:=<something>+aclass.identifier
|
<something>:=<something>+aclass.identifier
|
||||||
<proc>(,,aclass.identifier)
|
|
||||||
for identifier in <something>
|
for identifier in <something>
|
||||||
|
ToDo: <proc>(,,aclass.identifier)
|
||||||
|
|
||||||
checks where the identifier is already defined
|
checks where the identifier is already defined or is a keyword
|
||||||
checks if the identifier is a sub identifier (e.g. A.identifier)
|
checks if the identifier is a sub identifier (e.g. A.identifier)
|
||||||
creates the list of possible locations and notes
|
creates the list of possible insert locations
|
||||||
checks if it is the target of an assignment and guess the type
|
checks if it is the target of an assignment and guesses the type
|
||||||
checks if it is the source of an for in and guess the type
|
checks if it is the run variable of an for in and guesses the type
|
||||||
ToDo: checks if it is the target of an assignment and guess the type
|
ToDo: checks if it is a parameter and guesses the type
|
||||||
ToDo: checks if it is a parameter and guess the type
|
|
||||||
}
|
}
|
||||||
var
|
var
|
||||||
CleanCursorPos: integer;
|
CleanCursorPos: integer;
|
||||||
@ -6500,7 +6499,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// find assignment operator
|
// find assignment operator :=
|
||||||
MoveCursorToAtomPos(IdentifierAtom);
|
MoveCursorToAtomPos(IdentifierAtom);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
if AtomIs(':=') then begin
|
if AtomIs(':=') then begin
|
||||||
|
|||||||
@ -542,6 +542,7 @@ type
|
|||||||
Identifier: PChar;
|
Identifier: PChar;
|
||||||
StartTool: TFindDeclarationTool;
|
StartTool: TFindDeclarationTool;
|
||||||
StartNode: TCodeTreeNode;
|
StartNode: TCodeTreeNode;
|
||||||
|
Parent: TFindDeclarationParams;
|
||||||
ContextNode: TCodeTreeNode;
|
ContextNode: TCodeTreeNode;
|
||||||
OnIdentifierFound: TOnIdentifierFound;
|
OnIdentifierFound: TOnIdentifierFound;
|
||||||
IdentifierTool: TFindDeclarationTool;
|
IdentifierTool: TFindDeclarationTool;
|
||||||
@ -12010,14 +12011,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TFindDeclarationParams.Create(ParentParams: TFindDeclarationParams);
|
constructor TFindDeclarationParams.Create(ParentParams: TFindDeclarationParams);
|
||||||
var
|
|
||||||
HelperKind: TFDHelpersListKind;
|
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
Clear;
|
Clear;
|
||||||
if ParentParams<>nil then
|
Parent:=ParentParams;
|
||||||
for HelperKind in TFDHelpersListKind do
|
|
||||||
FHelpers[HelperKind] := ParentParams.FHelpers[HelperKind];
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TFindDeclarationParams.Create(Tool: TFindDeclarationTool;
|
constructor TFindDeclarationParams.Create(Tool: TFindDeclarationTool;
|
||||||
@ -12046,7 +12043,7 @@ begin
|
|||||||
FreeFoundProc(FFoundProcStackFirst,true);
|
FreeFoundProc(FFoundProcStackFirst,true);
|
||||||
for HelperKind in TFDHelpersListKind do
|
for HelperKind in TFDHelpersListKind do
|
||||||
if FFreeHelpers[HelperKind] then
|
if FFreeHelpers[HelperKind] then
|
||||||
FHelpers[HelperKind].Free;
|
FreeAndNil(FHelpers[HelperKind]);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -12216,6 +12213,8 @@ end;
|
|||||||
function TFindDeclarationParams.GetHelpers(HelperKind: TFDHelpersListKind;
|
function TFindDeclarationParams.GetHelpers(HelperKind: TFDHelpersListKind;
|
||||||
CreateIfNotExists: boolean): TFDHelpersList;
|
CreateIfNotExists: boolean): TFDHelpersList;
|
||||||
begin
|
begin
|
||||||
|
if Parent<>nil then
|
||||||
|
exit(Parent.GetHelpers(HelperKind,CreateIfNotExists));
|
||||||
if FNeedHelpers then
|
if FNeedHelpers then
|
||||||
StartTool.FindHelpersInContext(Self); // beware: this calls GetHelpers
|
StartTool.FindHelpersInContext(Self); // beware: this calls GetHelpers
|
||||||
Result:=FHelpers[HelperKind];
|
Result:=FHelpers[HelperKind];
|
||||||
|
|||||||
@ -199,9 +199,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end else if Marker='guesstype' then begin
|
end else if Marker='guesstype' then begin
|
||||||
ExpectedType:=copy(Src,PathPos,CommentP-1-PathPos);
|
ExpectedType:=copy(Src,PathPos,CommentP-1-PathPos);
|
||||||
{ $IFDEF VerboseFindDeclarationTests}
|
{$IFDEF VerboseFindDeclarationTests}
|
||||||
debugln(['TTestFindDeclaration.FindDeclarations "',Marker,'" at ',Tool.CleanPosToStr(NameStartPos-1),' ExpectedType=',ExpectedType]);
|
debugln(['TTestFindDeclaration.FindDeclarations "',Marker,'" at ',Tool.CleanPosToStr(NameStartPos-1),' ExpectedType=',ExpectedType]);
|
||||||
{ $ENDIF}
|
{$ENDIF}
|
||||||
Tool.CleanPosToCaret(IdentifierStartPos,CursorPos);
|
Tool.CleanPosToCaret(IdentifierStartPos,CursorPos);
|
||||||
|
|
||||||
// test GuessTypeOfIdentifier
|
// test GuessTypeOfIdentifier
|
||||||
@ -214,13 +214,6 @@ begin
|
|||||||
if ExpectedType<>'' then
|
if ExpectedType<>'' then
|
||||||
AssertEquals('GuessTypeOfIdentifier failed at '+Tool.CleanPosToStr(IdentifierStartPos,true)+': '+CodeToolBoss.ErrorMessage,false,true);
|
AssertEquals('GuessTypeOfIdentifier failed at '+Tool.CleanPosToStr(IdentifierStartPos,true)+': '+CodeToolBoss.ErrorMessage,false,true);
|
||||||
continue;
|
continue;
|
||||||
end else if ExistingDefinition.Node<>nil then begin
|
|
||||||
// already defined, no guessing needed
|
|
||||||
AssertEquals('GuessTypeOfIdentifier wrong at '
|
|
||||||
+Tool.CleanPosToStr(IdentifierStartPos,true),
|
|
||||||
'cannot find definition',
|
|
||||||
'found definition: '+ExistingDefinition.Tool.CleanPosToStr(
|
|
||||||
ExistingDefinition.Node.StartPos,true));
|
|
||||||
end else begin
|
end else begin
|
||||||
//debugln(['TTestFindDeclaration.FindDeclarations FoundPath=',FoundPath]);
|
//debugln(['TTestFindDeclaration.FindDeclarations FoundPath=',FoundPath]);
|
||||||
AssertEquals('GuessTypeOfIdentifier wrong at '+Tool.CleanPosToStr(IdentifierStartPos,true),LowerCase(ExpectedType),LowerCase(NewType));
|
AssertEquals('GuessTypeOfIdentifier wrong at '+Tool.CleanPosToStr(IdentifierStartPos,true),LowerCase(ExpectedType),LowerCase(NewType));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user