mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-25 03:10:31 +01:00
Cody: declare variable: show existing definition
git-svn-id: trunk@30877 -
This commit is contained in:
parent
9809397536
commit
d7a02cfb06
@ -223,7 +223,7 @@ type
|
|||||||
out Caret:TCodeXYPosition; out NewTopLine: integer): boolean; // true=ok, false=invalid CleanPos
|
out Caret:TCodeXYPosition; out NewTopLine: integer): boolean; // true=ok, false=invalid CleanPos
|
||||||
function CleanPosToStr(CleanPos: integer; WithFilename: boolean = false): string;
|
function CleanPosToStr(CleanPos: integer; WithFilename: boolean = false): string;
|
||||||
function CleanPosToRelativeStr(CleanPos: integer;
|
function CleanPosToRelativeStr(CleanPos: integer;
|
||||||
const BasePos: TCodeXYPosition): string;
|
const BaseFilename: string): string;
|
||||||
procedure GetCleanPosInfo(CodePosInFront, CleanPos: integer;
|
procedure GetCleanPosInfo(CodePosInFront, CleanPos: integer;
|
||||||
ResolveComments: boolean; out SameArea: TAtomPosition);
|
ResolveComments: boolean; out SameArea: TAtomPosition);
|
||||||
procedure GetLineInfo(ACleanPos: integer;
|
procedure GetLineInfo(ACleanPos: integer;
|
||||||
@ -2548,18 +2548,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomCodeTool.CleanPosToRelativeStr(CleanPos: integer;
|
function TCustomCodeTool.CleanPosToRelativeStr(CleanPos: integer;
|
||||||
const BasePos: TCodeXYPosition): string;
|
const BaseFilename: string): string;
|
||||||
var
|
var
|
||||||
CodePos: TCodeXYPosition;
|
CodePos: TCodeXYPosition;
|
||||||
begin
|
begin
|
||||||
if not CleanPosToCaret(CleanPos,CodePos) then
|
if not CleanPosToCaret(CleanPos,CodePos) then
|
||||||
Result:='(?)'
|
Result:='(?)'
|
||||||
else begin
|
else begin
|
||||||
if (BasePos.Code=nil) or (not FilenameIsAbsolute(BasePos.Code.Filename)) then
|
if (BaseFilename='') or (not FilenameIsAbsolute(BaseFilename)) then
|
||||||
Result:=CodePos.Code.Filename
|
Result:=CodePos.Code.Filename
|
||||||
else if (CodePos.Code<>BasePos.Code) then
|
else if CompareFilenames(CodePos.Code.Filename,BaseFilename)<>0 then
|
||||||
Result:=CreateRelativePath(CodePos.Code.Filename,
|
Result:=CreateRelativePath(CodePos.Code.Filename,
|
||||||
ExtractFilePath(BasePos.Code.Filename))
|
ExtractFilePath(BaseFilename))
|
||||||
else
|
else
|
||||||
Result:='';
|
Result:='';
|
||||||
Result:=Result+'('+IntToStr(CodePos.Y)+','+IntToStr(CodePos.X)+')';
|
Result:=Result+'('+IntToStr(CodePos.Y)+','+IntToStr(CodePos.X)+')';
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
||||||
Left = 275
|
Left = 291
|
||||||
Height = 298
|
Height = 298
|
||||||
Top = 250
|
Top = 243
|
||||||
Width = 408
|
Width = 408
|
||||||
Caption = 'CodyDeclareVarDialog'
|
Caption = 'CodyDeclareVarDialog'
|
||||||
ClientHeight = 298
|
ClientHeight = 298
|
||||||
@ -12,8 +12,8 @@ object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
|||||||
LCLVersion = '0.9.31'
|
LCLVersion = '0.9.31'
|
||||||
object ButtonPanel1: TButtonPanel
|
object ButtonPanel1: TButtonPanel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 40
|
Height = 42
|
||||||
Top = 252
|
Top = 250
|
||||||
Width = 396
|
Width = 396
|
||||||
OKButton.Name = 'OKButton'
|
OKButton.Name = 'OKButton'
|
||||||
OKButton.Caption = '&OK'
|
OKButton.Caption = '&OK'
|
||||||
@ -28,12 +28,12 @@ object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
|||||||
end
|
end
|
||||||
object Panel1: TPanel
|
object Panel1: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 246
|
Height = 244
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 408
|
Width = 408
|
||||||
Align = alClient
|
Align = alClient
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 246
|
ClientHeight = 244
|
||||||
ClientWidth = 408
|
ClientWidth = 408
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
object TypeLabel: TLabel
|
object TypeLabel: TLabel
|
||||||
@ -42,8 +42,8 @@ object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
|||||||
AnchorSideTop.Side = asrCenter
|
AnchorSideTop.Side = asrCenter
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 18
|
Height = 18
|
||||||
Top = 223
|
Top = 221
|
||||||
Width = 66
|
Width = 71
|
||||||
BorderSpacing.Left = 6
|
BorderSpacing.Left = 6
|
||||||
BorderSpacing.Right = 6
|
BorderSpacing.Right = 6
|
||||||
Caption = 'TypeLabel'
|
Caption = 'TypeLabel'
|
||||||
@ -57,10 +57,10 @@ object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
|||||||
AnchorSideRight.Side = asrBottom
|
AnchorSideRight.Side = asrBottom
|
||||||
AnchorSideBottom.Control = Panel1
|
AnchorSideBottom.Control = Panel1
|
||||||
AnchorSideBottom.Side = asrBottom
|
AnchorSideBottom.Side = asrBottom
|
||||||
Left = 78
|
Left = 83
|
||||||
Height = 27
|
Height = 27
|
||||||
Top = 219
|
Top = 217
|
||||||
Width = 324
|
Width = 319
|
||||||
Anchors = [akLeft, akRight, akBottom]
|
Anchors = [akLeft, akRight, akBottom]
|
||||||
BorderSpacing.Top = 6
|
BorderSpacing.Top = 6
|
||||||
BorderSpacing.Right = 6
|
BorderSpacing.Right = 6
|
||||||
@ -70,8 +70,8 @@ object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
|||||||
object WhereRadioGroup: TRadioGroup
|
object WhereRadioGroup: TRadioGroup
|
||||||
AnchorSideBottom.Control = TypeEdit
|
AnchorSideBottom.Control = TypeEdit
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 207
|
Height = 181
|
||||||
Top = 6
|
Top = 30
|
||||||
Width = 396
|
Width = 396
|
||||||
Align = alTop
|
Align = alTop
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
@ -88,5 +88,15 @@ object CodyDeclareVarDialog: TCodyDeclareVarDialog
|
|||||||
ChildSizing.ControlsPerLine = 1
|
ChildSizing.ControlsPerLine = 1
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
|
object RedefineLabel: TLabel
|
||||||
|
Left = 6
|
||||||
|
Height = 18
|
||||||
|
Top = 6
|
||||||
|
Width = 396
|
||||||
|
Align = alTop
|
||||||
|
BorderSpacing.Around = 6
|
||||||
|
Caption = 'RedefineLabel'
|
||||||
|
ParentColor = False
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -33,7 +33,6 @@
|
|||||||
- guess for in
|
- guess for in
|
||||||
- guess parameter
|
- guess parameter
|
||||||
- guess <i>:=expression
|
- guess <i>:=expression
|
||||||
- Fix bug: adding a public variable is added after a method
|
|
||||||
- Extend uses section when adding to a class
|
- Extend uses section when adding to a class
|
||||||
- Fix bug: adding types with comments
|
- Fix bug: adding types with comments
|
||||||
}
|
}
|
||||||
@ -73,6 +72,7 @@ type
|
|||||||
TypeEdit: TEdit;
|
TypeEdit: TEdit;
|
||||||
TypeLabel: TLabel;
|
TypeLabel: TLabel;
|
||||||
WhereRadioGroup: TRadioGroup;
|
WhereRadioGroup: TRadioGroup;
|
||||||
|
RedefineLabel: TLabel;
|
||||||
procedure HelpButtonClick(Sender: TObject);
|
procedure HelpButtonClick(Sender: TObject);
|
||||||
procedure OKButtonClick(Sender: TObject);
|
procedure OKButtonClick(Sender: TObject);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
@ -93,6 +93,7 @@ procedure ShowDeclareVariableDialog(Sender: TObject);
|
|||||||
|
|
||||||
function CheckCreateVarFromIdentifierInSrcEdit(out CodePos: TCodeXYPosition;
|
function CheckCreateVarFromIdentifierInSrcEdit(out CodePos: TCodeXYPosition;
|
||||||
out Tool: TCodeTool; out NewIdentifier, NewType, NewUnitName: string;
|
out Tool: TCodeTool; out NewIdentifier, NewType, NewUnitName: string;
|
||||||
|
out ExistingDefinition: TFindContext;
|
||||||
out PossibleContexts: TFPList): boolean;
|
out PossibleContexts: TFPList): boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -112,6 +113,7 @@ end;
|
|||||||
function CheckCreateVarFromIdentifierInSrcEdit(
|
function CheckCreateVarFromIdentifierInSrcEdit(
|
||||||
out CodePos: TCodeXYPosition; out Tool: TCodeTool;
|
out CodePos: TCodeXYPosition; out Tool: TCodeTool;
|
||||||
out NewIdentifier, NewType, NewUnitName: string;
|
out NewIdentifier, NewType, NewUnitName: string;
|
||||||
|
out ExistingDefinition: TFindContext;
|
||||||
out PossibleContexts: TFPList // list of PFindContext
|
out PossibleContexts: TFPList // list of PFindContext
|
||||||
): boolean;
|
): boolean;
|
||||||
|
|
||||||
@ -127,7 +129,6 @@ var
|
|||||||
CursorNode: TCodeTreeNode;
|
CursorNode: TCodeTreeNode;
|
||||||
Handled: boolean;
|
Handled: boolean;
|
||||||
IsKeyword: boolean;
|
IsKeyword: boolean;
|
||||||
ExistingDefinition: TFindContext;
|
|
||||||
NewExprType: TExpressionType;
|
NewExprType: TExpressionType;
|
||||||
IsSubIdentifier: boolean;
|
IsSubIdentifier: boolean;
|
||||||
begin
|
begin
|
||||||
@ -137,6 +138,7 @@ begin
|
|||||||
NewUnitName:='';
|
NewUnitName:='';
|
||||||
CodePos:=CleanCodeXYPosition;
|
CodePos:=CleanCodeXYPosition;
|
||||||
Tool:=nil;
|
Tool:=nil;
|
||||||
|
ExistingDefinition:=CleanFindContext;
|
||||||
PossibleContexts:=nil;
|
PossibleContexts:=nil;
|
||||||
|
|
||||||
if (ParseTilCursor(Tool,CleanPos,CursorNode,Handled,true,@CodePos)<>cupeSuccess)
|
if (ParseTilCursor(Tool,CleanPos,CursorNode,Handled,true,@CodePos)<>cupeSuccess)
|
||||||
@ -269,15 +271,24 @@ var
|
|||||||
OldChange: boolean;
|
OldChange: boolean;
|
||||||
OldSrcEdit: TSourceEditorInterface;
|
OldSrcEdit: TSourceEditorInterface;
|
||||||
NewType: String;
|
NewType: String;
|
||||||
|
ExistingDefinition: TFindContext;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
PossibleContexts:=nil;
|
PossibleContexts:=nil;
|
||||||
Targets.Clear;
|
Targets.Clear;
|
||||||
try
|
try
|
||||||
if not CheckCreateVarFromIdentifierInSrcEdit(CodePos,Tool,Identifier,
|
if not CheckCreateVarFromIdentifierInSrcEdit(CodePos,Tool,Identifier,
|
||||||
RecommendedType,UnitOfType,PossibleContexts)
|
RecommendedType,UnitOfType,ExistingDefinition,PossibleContexts)
|
||||||
then exit;
|
then exit;
|
||||||
|
|
||||||
|
if ExistingDefinition.Node<>nil then begin
|
||||||
|
RedefineLabel.Visible:=true;
|
||||||
|
RedefineLabel.Caption:='Already defined at '+ExistingDefinition.Tool.CleanPosToRelativeStr(
|
||||||
|
ExistingDefinition.Node.StartPos,CodePos.Code.Filename);
|
||||||
|
end else begin
|
||||||
|
RedefineLabel.Visible:=false;
|
||||||
|
end;
|
||||||
|
|
||||||
if PossibleContexts<>nil then begin
|
if PossibleContexts<>nil then begin
|
||||||
for i:=0 to PossibleContexts.Count-1 do begin
|
for i:=0 to PossibleContexts.Count-1 do begin
|
||||||
Context:=PFindContext(PossibleContexts[i])^;
|
Context:=PFindContext(PossibleContexts[i])^;
|
||||||
|
|||||||
@ -2023,6 +2023,7 @@ var
|
|||||||
var
|
var
|
||||||
p: LongInt;
|
p: LongInt;
|
||||||
Msg: String;
|
Msg: String;
|
||||||
|
f: String;
|
||||||
begin
|
begin
|
||||||
ReadTilBracketCloseOrUnexpected:=false;
|
ReadTilBracketCloseOrUnexpected:=false;
|
||||||
if not ExceptionOnNotFound then exit;
|
if not ExceptionOnNotFound then exit;
|
||||||
@ -2036,9 +2037,13 @@ var
|
|||||||
siEdgedBracketOpen: Msg:='bracket ] not found';
|
siEdgedBracketOpen: Msg:='bracket ] not found';
|
||||||
siRecord: Msg:='record end not found';
|
siRecord: Msg:='record end not found';
|
||||||
end;
|
end;
|
||||||
if CurPos.StartPos<=SrcLen then
|
if CurPos.StartPos<=SrcLen then begin
|
||||||
Msg:=Msg+', found unexpected '+GetAtom
|
if ErrorNicePosition.Code<>nil then
|
||||||
+' at '+CleanPosToRelativeStr(CurPos.StartPos,ErrorNicePosition);
|
f:=ErrorNicePosition.Code.Filename
|
||||||
|
else
|
||||||
|
f:='';
|
||||||
|
Msg:=Msg+', found unexpected '+GetAtom+' at '+CleanPosToRelativeStr(CurPos.StartPos,f);
|
||||||
|
end;
|
||||||
SaveRaiseException(Msg,not CleanPosToCaret(p,ErrorNicePosition));
|
SaveRaiseException(Msg,not CleanPosToCaret(p,ErrorNicePosition));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user