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