1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
|
{
*****************************************************************************
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Mattias Gaertner
Abstract:
Interface to the IDE messages (below the source editor).
}
unit IDEMsgIntf;
{$mode objfpc}{$H+}
interface
{$IFDEF EnableNewExtTools}
uses
Classes, SysUtils, contnrs, Forms, Menus,
TextTools, IDECommands, IDEExternToolIntf;
type
TMsgQuickFixes = class;
{ TMsgQuickFix }
TMsgQuickFix = class
public
procedure CreateMenuItems(Fixes: TMsgQuickFixes); virtual;
procedure JumpTo({%H-}Msg: TMessageLine; var {%H-}Handled: boolean); virtual; // called when user (double) clicks on message
procedure QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine); virtual; // Msg=nil means fix all Fixes.Lines
end;
TMsgQuickFixClass = class of TMsgQuickFix;
{ TMsgQuickFixes }
TMsgQuickFixes = class(TComponent)
private
function GetLines(Index: integer): TMessageLine; inline;
function GetQuickFixes(Index: integer): TMsgQuickFix; inline;
protected
fMsg: TFPList; // list of TMessageLine
fItems: TObjectList; // list of TMsgQuickFix
public
constructor Create(aOwner: TComponent); override;
destructor Destroy; override;
procedure RegisterQuickFix(Fix: TMsgQuickFix);
procedure UnregisterQuickFix(Fix: TMsgQuickFix);
function Count: integer; inline;
property Items[Index: integer]: TMsgQuickFix read GetQuickFixes; default;
function LineCount: integer; inline;
property Lines[Index: integer]: TMessageLine read GetLines;
function AddMenuItem(Fix: TMsgQuickFix; Msg: TMessageLine; aCaption: string;
aTag: PtrInt = 0): TMenuItem; virtual; abstract;
end;
var
MsgQuickFixes: TMsgQuickFixes = nil; // set by IDE
procedure RegisterIDEMsgQuickFix(Fix: TMsgQuickFix);
type
TIDEMessagesWindowInterface = class(TForm)
protected
function GetViews(Index: integer): TExtToolView; virtual; abstract;
public
procedure Clear; virtual; abstract; // clears all finished views
function ViewCount: integer; virtual; abstract;
property Views[Index: integer]: TExtToolView read GetViews;
function GetView(aCaption: string; CreateIfNotExist: boolean): TExtToolView; virtual; abstract;
function FindUnfinishedView: TExtToolView; virtual; abstract;
procedure DeleteView(View: TExtToolView); virtual; abstract; // free view
function IndexOfView(View: TExtToolView): integer; virtual; abstract;
procedure SelectMsgLine(Msg: TMessageLine); virtual; abstract;
function SelectFirstUrgentMessage(aMinUrgency: TMessageLineUrgency;
WithSrcPos: boolean): boolean; virtual; abstract;
function SelectNextUrgentMessage(aMinUrgency: TMessageLineUrgency;
WithSrcPos, Downwards: boolean): boolean; virtual; abstract;
function AddCustomMessage(TheUrgency: TMessageLineUrgency; Msg: string;
aSrcFilename: string = ''; LineNumber: integer = 0; Column: integer = 0;
const ViewCaption: string = ''): TMessageLine; virtual; abstract;
function GetSelectedLine: TMessageLine; virtual; abstract;
end;
var
IDEMessagesWindow: TIDEMessagesWindowInterface = nil;// initialized by the IDE
implementation
procedure RegisterIDEMsgQuickFix(Fix: TMsgQuickFix);
begin
MsgQuickFixes.RegisterQuickFix(Fix);
end;
{ TMsgQuickFix }
procedure TMsgQuickFix.QuickFix(Fixes: TMsgQuickFixes; Msg: TMessageLine);
var
i: Integer;
begin
// this is purely an example
if Msg<>nil then begin
if Msg.MsgID=-11111 then begin
// fix the cause for the message
// ...
// mark message as handled
Msg.MarkFixed;
end;
end else begin
// example for fixing multiple messages at once
for i:=0 to Fixes.LineCount-1 do begin
Msg:=Fixes.Lines[i];
if Msg.MsgID=-11111 then begin
// fix the cause for the message
// ...
// mark message as handled
Msg.MarkFixed;
end;
end;
end;
end;
procedure TMsgQuickFix.CreateMenuItems(Fixes: TMsgQuickFixes);
var
i: Integer;
Msg: TMessageLine;
begin
// this is an example how to check the selected messages
for i:=0 to Fixes.LineCount-1 do begin
Msg:=Fixes.Lines[i];
// here are some examples how to test if a message fits
if (Msg.Urgency<mluWarning)
and (Msg.MsgID=-11111)
and (Msg.Line>0)
and (Msg.Column>0)
and (Msg.SubTool=SubToolFPC)
and (Msg.GetFullFilename<>'')
and (Pos('LazarusExample',Msg.Msg)>0)
then
// this message can be quick fixed => add a menu item
Fixes.AddMenuItem(Self,Msg,'Change this or that to fix this item');
end;
end;
procedure TMsgQuickFix.JumpTo(Msg: TMessageLine; var Handled: boolean);
begin
end;
{ TMsgQuickFixes }
// inline
function TMsgQuickFixes.GetLines(Index: integer): TMessageLine;
begin
Result:=TMessageLine(fMsg[index]);
end;
// inline
function TMsgQuickFixes.GetQuickFixes(Index: integer): TMsgQuickFix;
begin
Result:=TMsgQuickFix(fItems[Index]);
end;
// inline
function TMsgQuickFixes.Count: integer;
begin
Result:=fItems.Count;
end;
// inline
function TMsgQuickFixes.LineCount: integer;
begin
Result:=fMsg.Count;
end;
constructor TMsgQuickFixes.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
fItems:=TObjectList.create(true);
fMsg:=TFPList.Create;
end;
destructor TMsgQuickFixes.Destroy;
begin
FreeAndNil(fMsg);
FreeAndNil(fItems);
inherited Destroy;
if MsgQuickFixes=Self then
MsgQuickFixes:=nil;
end;
procedure TMsgQuickFixes.RegisterQuickFix(Fix: TMsgQuickFix);
begin
if fItems.IndexOf(Fix)>=0 then
raise Exception.Create('quick fix already registered');
fItems.Add(Fix);
end;
procedure TMsgQuickFixes.UnregisterQuickFix(Fix: TMsgQuickFix);
begin
fItems.Remove(Fix);
end;
{$ELSE EnableNewExtTools}
uses
Classes, SysUtils, Forms, LCLProc,
TextTools, IDECommands, IDEExternToolIntf;
type
{ TIDEMessageLine
The IDE (TOutputFilter) parses each message line.
If it sees FPC output, it fills the Parts property and set various
Name=Value pairs.
Name | Value
--------|-----------------------------------------------------------------
Stage Indicates what part of the build process the message
belongs to. Common values are 'FPC', 'Linker' or 'make'
Type For FPC: 'Hint', 'Note', 'Warning', 'Error', 'Fatal', 'Panic',
'Compiling', 'Assembling'
For make: 'entering directory', 'leaving directory'
For Linker:
Line An integer for the linenumber as given by FPC in brackets.
Column An integer for the column as given by FPC in brackets.
Message The message text without other parsed items.
Example:
Message written by FPC:
unit1.pas(21,3) Warning: unit buttons not used
Creates the following lines in Parts:
Stage=FPC
Type=Warning
Filename=/path/unit1.pas
Line=21
Column=3
Message=unit buttons not used
You can access them via:
if ALine.Parts.Values['Stage']='FPC' then ...
}
TIDEMessageLine = class
private
FDirectory: string;
FMsg: string;
FOriginalIndex: integer;
FParts: TStrings;
FPosition: integer;
FVisible: boolean;
FVisiblePosition: integer;
procedure SetDirectory(const AValue: string);
procedure SetMsg(const AValue: string);
public
constructor Create;
destructor Destroy; override;
procedure GetSourcePosition(out Filename: string;
out LineNumber, Column: integer);
procedure SetSourcePosition(const Filename: string;
const LineNumber, Column: integer);
property Msg: string read FMsg write SetMsg;
property Directory: string read FDirectory write SetDirectory;
property Position: integer read FPosition write FPosition; // position in all available messages
property VisiblePosition: integer read FVisiblePosition write FVisiblePosition;// filtered position
property OriginalIndex: integer read FOriginalIndex write FOriginalIndex;// unsorted, unfiltered position
property Parts: TStrings read FParts write FParts;
property Visible: boolean read FVisible write FVisible;
end;
TOnFilterLine = procedure(MsgLine: TIDEMessageLine; var Show: boolean) of object;
{ TIDEMessageLineList }
TIDEMessageLineList = class
private
FItems: TFPList;
function GetCount: integer;
function GetItems(Index: integer): TIDEMessageLine;
function GetParts(Index: integer): TStrings;
procedure SetParts(Index: integer; const AValue: TStrings);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function Add(const Msg: string): integer;
function Add(Item: TIDEMessageLine): integer;
procedure Delete(Index: Integer);
public
property Count: integer read GetCount;
property Items[Index: integer]: TIDEMessageLine read GetItems; default;
property Parts[Index: integer]: TStrings read GetParts write SetParts;
end;
TIDEMsgScannerType = class;
{ TIDEMsgScanner }
TIDEMsgScanner = class(TPersistent)
private
FLines: TIDEMessageLineList;
FScannerType: TIDEMsgScannerType;
FWorkingDirectory: string;
protected
procedure SetWorkingDirectory(const AValue: string);
public
constructor Create(TheScannerType: TIDEMsgScannerType;
TheLines: TIDEMessageLineList);
function ParseLine(MsgLine: TIDEMessageLine; var Show: boolean): boolean; virtual; abstract;// true if line was handled
procedure EndScan; virtual;
property Lines: TIDEMessageLineList read FLines;
property ScannerType: TIDEMsgScannerType read FScannerType;
property WorkingDirectory: string read FWorkingDirectory write SetWorkingDirectory;
end;
{ TIDEMsgScannerType }
TIDEMsgScannerType = class(TComponent)
public
function ShortDescription: string; virtual; abstract;
function Description: string; virtual; abstract;
function StartScan(Lines: TIDEMessageLineList): TIDEMsgScanner; virtual; abstract;
end;
{ TIDEMsgScanners }
TIDEMsgScanners = class(TPersistent)
private
fScanners: TFPList;// current instances
fTypes: TFPList;// registered scanner types
function GetCount: integer;
function GetItems(Index: integer): TIDEMsgScannerType;
function GetScannerCount: integer;
function GetScanners(Index: integer): TIDEMsgScanner;
public
constructor Create;
destructor Destroy; override;
procedure RegisterType(aType: TIDEMsgScannerType);
procedure UnregisterType(aType: TIDEMsgScannerType);
function CreateUniqueName(const aName: string): string;
function IndexOfName(const aTypeName: string): integer;
function TypeOfName(const aTypeName: string): TIDEMsgScannerType;
function IndexOfShortDesc(const ShortDescription: string): integer;
function TypeOfShortDesc(const ShortDescription: string): TIDEMsgScannerType;
property Count: integer read GetCount;
property Items[Index: integer]: TIDEMsgScannerType read GetItems; default;
property ScannerCount: integer read GetScannerCount;
property Scanners[Index: integer]: TIDEMsgScanner read GetScanners;
end;
{ TIDEMsgQuickFixItem }
TIMQuickFixStep = (
imqfoMenuItem, // Popup menu opens. Add now the menu item.
imqfoImproveMessage,// Message can now be rewritten/beautified.
imqfoJump // Override what happens, when user clicks on message.
);
TIMQuickFixSteps = set of TIMQuickFixStep;
TIMQFExecuteMethod = procedure(Sender: TObject; Step: TIMQuickFixStep;
Msg: TIDEMessageLine) of object;
TIMQFExecuteProc = procedure(Sender: TObject; Step: TIMQuickFixStep;
Msg: TIDEMessageLine);
TIDEMsgQuickFixItem = class(TPersistent)
private
FCaption: string;
FName: string;
FOnExecuteMethod: TIMQFExecuteMethod;
FOnExecuteProc: TIMQFExecuteProc;
FRegExpression: string;
FRegExprModifiers: string;
FSteps: TIMQuickFixSteps;
function GetCaption: string;
procedure SetCaption(const AValue: string);
procedure SetName(const AValue: string);
procedure SetRegExpression(const AValue: string);
procedure SetRegExprModifiers(const AValue: string);
public
constructor Create;
procedure Execute(const Msg: TIDEMessageLine; Step: TIMQuickFixStep); virtual;
function IsApplicable(Line: TIDEMessageLine): boolean; virtual;
public
property Name: string read FName write SetName;
property Caption: string read GetCaption write SetCaption;
property RegExpression: string read FRegExpression write SetRegExpression;
property RegExprModifiers: string read FRegExprModifiers write SetRegExprModifiers;
property OnExecuteMethod: TIMQFExecuteMethod read FOnExecuteMethod write FOnExecuteMethod;
property OnExecuteProc: TIMQFExecuteProc read FOnExecuteProc write FOnExecuteProc;
property Steps: TIMQuickFixSteps read FSteps write FSteps;
end;
{ TIDEMsgQuickFixItems }
TIDEMsgQuickFixItems = class(TPersistent)
private
FItems: TFPList;
function GetCount: integer;
function GetItems(Index: integer): TIDEMsgQuickFixItem;
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function Add(Item: TIDEMsgQuickFixItem): integer;
procedure Remove(Item: TIDEMsgQuickFixItem);
function IndexOfName(const Name: string): integer;
function FindByName(const Name: string): TIDEMsgQuickFixItem;
function NewName(const StartValue: string): string;
public
property Count: integer read GetCount;
property Items[Index: integer]: TIDEMsgQuickFixItem read GetItems; default;
end;
{ TIDEMessagesWindowInterface }
TIDEMessagesWindowInterface = class(TForm)
protected
function GetLines(Index: integer): TIDEMessageLine; virtual; abstract;
public
procedure Clear; virtual; abstract;
procedure AddMsg(const Msg, CurDir: string; OriginalIndex: integer; Parts: TStrings = nil); virtual; abstract;
property Lines[Index: integer]: TIDEMessageLine read GetLines; default;
function LinesCount: integer; virtual; abstract;
procedure BeginBlock(ClearOldBlocks: Boolean = true); virtual; abstract;
procedure EndBlock; virtual; abstract;
function GetSelectedLine: TIDEMessageLine; virtual; abstract;
end;
var
IDEMsgQuickFixes: TIDEMsgQuickFixItems = nil; // initialized by the IDE
IDEMessagesWindow: TIDEMessagesWindowInterface = nil;// initialized by the IDE
IDEMsgScanners: TIDEMsgScanners = nil;// initialized by the IDE
procedure RegisterIDEMsgQuickFix(Item: TIDEMsgQuickFixItem);
function RegisterIDEMsgQuickFix(const Name, Caption, RegExpr: string;
Steps: TIMQuickFixSteps;
const ExecuteMethod: TIMQFExecuteMethod;
const ExecuteProc: TIMQFExecuteProc = nil): TIDEMsgQuickFixItem; overload;
procedure RegisterIDEMsgScanner(Item: TIDEMsgScannerType);
type
TFPCErrorType = (etNone, etHint, etNote, etWarning, etError, etFatal, etPanic);
const
FPCErrorTypeNames : array[TFPCErrorType] of string = (
'None','Hint','Note','Warning','Error','Fatal','Panic'
);
function FPCErrorTypeNameToType(const Name:string): TFPCErrorType;
function ParseFPCMessage(const Line: string; out Filename:string;
out CaretXY: TPoint; out MsgType: TFPCErrorType): boolean;
implementation
procedure RegisterIDEMsgQuickFix(Item: TIDEMsgQuickFixItem);
begin
IDEMsgQuickFixes.Add(Item);
end;
function RegisterIDEMsgQuickFix(const Name, Caption, RegExpr: string;
Steps: TIMQuickFixSteps;
const ExecuteMethod: TIMQFExecuteMethod; const ExecuteProc: TIMQFExecuteProc
): TIDEMsgQuickFixItem;
begin
Result:=TIDEMsgQuickFixItem.Create;
Result.Name:=Name;
Result.Caption:=Caption;
Result.RegExpression:=RegExpr;
Result.Steps:=Steps;
Result.OnExecuteMethod:=ExecuteMethod;
Result.OnExecuteProc:=ExecuteProc;
IDEMsgQuickFixes.Add(Result);
end;
procedure RegisterIDEMsgScanner(Item: TIDEMsgScannerType);
begin
IDEMsgScanners.RegisterType(Item);
end;
function FPCErrorTypeNameToType(const Name: string): TFPCErrorType;
begin
for Result:=Succ(etNone) to High(TFPCErrorType) do
if CompareText(FPCErrorTypeNames[Result],Name)=0 then exit;
Result:=etNone;
end;
function ParseFPCMessage(const Line: string; out Filename: string; out
CaretXY: TPoint; out MsgType: TFPCErrorType): boolean;
{ This assumes the line has one of the following formats
<filename>(123,45) <ErrorType>: <some text>
<filename>(123) <ErrorType>: <some text>
<filename>(456) <ErrorType>: <some text> in line (123)
Fatal: <some text>
}
var
StartPos, EndPos: integer;
begin
Result:=false;
StartPos:=1;
// skip time [0.000]
if (Line<>'') and (Line[StartPos]='[') then begin
inc(StartPos);
while (StartPos<=length(Line)) and (Line[StartPos] in ['0'..'9','.']) do
inc(StartPos);
if (StartPos<=length(Line)) and (Line[StartPos]=']') then
inc(StartPos);
while (StartPos<=length(Line)) and (Line[StartPos] in [' ']) do
inc(StartPos);
end;
if copy(Line,StartPos,7)='Fatal: ' then begin
Result:=true;
Filename:='';
MsgType:=etFatal;
exit;
end;
if copy(Line,StartPos,7)='Panic: ' then begin
Result:=true;
Filename:='';
MsgType:=etPanic;
exit;
end;
// find filename
EndPos:=StartPos;
while (EndPos<=length(Line)) and (Line[EndPos]<>'(') do inc(EndPos);
if EndPos>length(Line) then exit;
FileName:=copy(Line,StartPos,EndPos-StartPos);
// read linenumber
StartPos:=EndPos+1;
EndPos:=StartPos;
while (EndPos<=length(Line)) and (Line[EndPos] in ['0'..'9']) do inc(EndPos);
if EndPos>length(Line) then exit;
CaretXY.X:=1;
CaretXY.Y:=StrToIntDef(copy(Line,StartPos,EndPos-StartPos),-1);
if Line[EndPos]=',' then begin
// format: <filename>(123,45) <ErrorType>: <some text>
// read column
StartPos:=EndPos+1;
EndPos:=StartPos;
while (EndPos<=length(Line)) and (Line[EndPos] in ['0'..'9']) do inc(EndPos);
if EndPos>length(Line) then exit;
CaretXY.X:=StrToIntDef(copy(Line,StartPos,EndPos-StartPos),-1);
// read error type
StartPos:=EndPos+2;
while (EndPos<=length(Line)) and (Line[EndPos]<>':') do inc(EndPos);
if EndPos>length(Line) then exit;
MsgType:=FPCErrorTypeNameToType(copy(Line,StartPos,EndPos-StartPos));
Result:=true;
end else if Line[EndPos]=')' then begin
// <filename>(123) <ErrorType>: <some text>
// <filename>(456) <ErrorType>: <some text> in line (123)
// read error type
StartPos:=EndPos+2;
while (EndPos<=length(Line)) and (Line[EndPos]<>':') do inc(EndPos);
if EndPos>length(Line) then exit;
MsgType:=FPCErrorTypeNameToType(copy(Line,StartPos,EndPos-StartPos));
// read second linenumber (more useful)
while (EndPos<=length(Line)) and (Line[EndPos]<>'(') do inc(EndPos);
if EndPos>length(Line) then begin
// format: <filename>(123) <ErrorType>: <some text>
Result:=true;
exit;
end;
StartPos:=EndPos+1;
EndPos:=StartPos;
while (EndPos<=length(Line)) and (Line[EndPos] in ['0'..'9']) do inc(EndPos);
if EndPos>length(Line) then exit;
CaretXY.Y:=StrToIntDef(copy(Line,StartPos,EndPos-StartPos),-1);
Result:=true;
end;
end;
{ TIDEMsgQuickFixItem }
function TIDEMsgQuickFixItem.GetCaption: string;
begin
if FCaption<>'' then
Result:=FCaption
else
Result:=FName;
end;
procedure TIDEMsgQuickFixItem.SetCaption(const AValue: string);
begin
if FCaption=AValue then exit;
FCaption:=AValue;
end;
procedure TIDEMsgQuickFixItem.SetName(const AValue: string);
begin
if FName=AValue then exit;
FName:=AValue;
end;
procedure TIDEMsgQuickFixItem.SetRegExpression(const AValue: string);
begin
if FRegExpression=AValue then exit;
FRegExpression:=AValue;
end;
procedure TIDEMsgQuickFixItem.SetRegExprModifiers(const AValue: string);
begin
if FRegExprModifiers=AValue then exit;
FRegExprModifiers:=AValue;
end;
constructor TIDEMsgQuickFixItem.Create;
begin
FRegExprModifiers:='I';
FSteps:=[imqfoMenuItem];
end;
procedure TIDEMsgQuickFixItem.Execute(const Msg: TIDEMessageLine;
Step: TIMQuickFixStep);
begin
if Assigned(OnExecuteMethod) then
OnExecuteMethod(Self,Step,Msg);
if Assigned(OnExecuteProc) then
OnExecuteProc(Self,Step,Msg);
end;
function TIDEMsgQuickFixItem.IsApplicable(Line: TIDEMessageLine): boolean;
begin
Result:=false;
if RegExpression='' then exit;
//DebugLn('TIDEMsgQuickFixItem.IsApplicable Line.Msg="',Line.Msg,'" RegExpression="',RegExpression,'"');
Result:=REMatches(Line.Msg,RegExpression,RegExprModifiers);
end;
{ TIDEMsgQuickFixItems }
function TIDEMsgQuickFixItems.GetItems(Index: integer): TIDEMsgQuickFixItem;
begin
Result:=TIDEMsgQuickFixItem(FItems[Index]);
end;
function TIDEMsgQuickFixItems.GetCount: integer;
begin
Result:=FItems.Count;
end;
constructor TIDEMsgQuickFixItems.Create;
begin
FItems:=TFPList.Create;
end;
destructor TIDEMsgQuickFixItems.Destroy;
begin
Clear;
FreeAndNil(FItems);
inherited Destroy;
end;
procedure TIDEMsgQuickFixItems.Clear;
var
i: Integer;
begin
for i:=Count-1 downto 0 do Items[i].Free;
end;
function TIDEMsgQuickFixItems.Add(Item: TIDEMsgQuickFixItem): integer;
begin
Item.Name:=NewName(Item.Name);
Result:=FItems.Add(Item);
end;
procedure TIDEMsgQuickFixItems.Remove(Item: TIDEMsgQuickFixItem);
begin
FItems.Remove(Item);
end;
function TIDEMsgQuickFixItems.IndexOfName(const Name: string): integer;
begin
for Result:=0 to Count-1 do
if CompareText(Items[Result].Name,Name)=0 then exit;
Result:=-1;
end;
function TIDEMsgQuickFixItems.FindByName(const Name: string
): TIDEMsgQuickFixItem;
var
i: LongInt;
begin
i:=IndexOfName(Name);
if i>=0 then
Result:=Items[i]
else
Result:=nil;
end;
function TIDEMsgQuickFixItems.NewName(const StartValue: string): string;
begin
Result:=StartValue;
if IndexOfName(Result)<0 then exit;
Result:=CreateFirstIdentifier(StartValue);
//DebugLn('TIDEMsgQuickFixItems.NewName Result="',Result,'" StartValue="',StartValue,'"');
while IndexOfName(Result)>=0 do
Result:=CreateNextIdentifier(Result);
end;
{ TIDEMessageLine }
procedure TIDEMessageLine.SetDirectory(const AValue: string);
begin
if FDirectory = AValue then
exit;
FDirectory := AValue;
end;
procedure TIDEMessageLine.SetMsg(const AValue: string);
begin
if FMsg = AValue then
exit;
FMsg := AValue;
end;
constructor TIDEMessageLine.Create;
begin
FPosition := -1;
FVisiblePosition := -1;
end;
destructor TIDEMessageLine.Destroy;
begin
FParts.Free;
inherited Destroy;
end;
procedure TIDEMessageLine.GetSourcePosition(out Filename: string; out
LineNumber, Column: integer);
begin
if Parts<>nil then begin
Filename:=Parts.Values['Filename'];
LineNumber:=StrToIntDef(Parts.Values['Line'],0);
Column:=StrToIntDef(Parts.Values['Column'],0);
end else begin
Filename:='';
LineNumber:=0;
Column:=0;
end;
end;
procedure TIDEMessageLine.SetSourcePosition(const Filename: string;
const LineNumber, Column: integer);
var
BracketClosePos: LongInt;
s: String;
CommaPos: LongInt;
BracketOpenPos: LongInt;
begin
if Parts<>nil then begin
if Filename<>'' then
Parts.Values['Filename']:=Filename;
if LineNumber>0 then
Parts.Values['Line']:=IntToStr(LineNumber);
if Column>0 then
Parts.Values['Column']:=IntToStr(Column);
if ExtractFilePath(Filename)<>'' then
Directory:=ExtractFilePath(Filename);
end;
BracketOpenPos:=System.Pos('(',Msg);
if (BracketOpenPos>0) then begin
if (Filename<>'') then begin
Msg:=Filename+copy(Msg,BracketOpenPos,length(Msg));
BracketOpenPos:=length(Filename)+1;
end;
CommaPos:=System.Pos(',',Msg);
if LineNumber>0 then begin
if CommaPos>0 then begin
s:=IntToStr(LineNumber);
Msg:=copy(Msg,1,BracketOpenPos)+s
+copy(Msg,CommaPos,length(Msg));
end else begin
s:=IntToStr(LineNumber);
Msg:=copy(Msg,1,BracketOpenPos)+s+',1'
+copy(Msg,BracketOpenPos+1,length(Msg));
end;
CommaPos:=BracketOpenPos+length(s)+1;
end;
if CommaPos>0 then begin
BracketClosePos:=System.Pos(')',Msg);
if BracketClosePos>0 then begin
if Column>0 then begin
s:=IntToStr(Column);
Msg:=copy(Msg,1,CommaPos)+s+copy(Msg,BracketClosePos,length(Msg));
end;
end;
end;
end else begin
Msg:=Filename+'('+IntToStr(LineNumber)+','+IntToStr(Column)+')'+Msg;
end;
end;
{ TIDEMessageLineList }
function TIDEMessageLineList.GetCount: integer;
begin
Result:=FItems.Count;
end;
function TIDEMessageLineList.GetItems(Index: integer): TIDEMessageLine;
begin
Result:=TIDEMessageLine(FItems[Index]);
end;
function TIDEMessageLineList.GetParts(Index: integer): TStrings;
begin
Result:=Items[Index].Parts;
end;
procedure TIDEMessageLineList.SetParts(Index: integer; const AValue: TStrings);
begin
Items[Index].Parts:=AValue;
end;
constructor TIDEMessageLineList.Create;
begin
FItems:=TFPList.Create;
end;
destructor TIDEMessageLineList.Destroy;
begin
Clear;
FreeAndNil(FItems);
inherited Destroy;
end;
procedure TIDEMessageLineList.Clear;
var
i: Integer;
begin
for i:=0 to FItems.Count-1 do TObject(FItems[i]).Free;
FItems.Clear;
end;
function TIDEMessageLineList.Add(const Msg: string): integer;
var
Item: TIDEMessageLine;
begin
Item:=TIDEMessageLine.Create;
Item.Msg:=Msg;
Result:=Add(Item);
end;
function TIDEMessageLineList.Add(Item: TIDEMessageLine): integer;
begin
Result:=FItems.Add(Item);
Item.OriginalIndex:=Result;
end;
procedure TIDEMessageLineList.Delete(Index: Integer);
begin
TObject(FItems[Index]).Free;
FItems.Delete(Index);
end;
{ TIDEMsgScanner }
procedure TIDEMsgScanner.SetWorkingDirectory(const AValue: string);
begin
if FWorkingDirectory=AValue then exit;
FWorkingDirectory:=AValue;
end;
constructor TIDEMsgScanner.Create(TheScannerType: TIDEMsgScannerType;
TheLines: TIDEMessageLineList);
begin
FScannerType:=TheScannerType;
FLines:=TheLines;
end;
procedure TIDEMsgScanner.EndScan;
begin
end;
{ TIDEMsgScanners }
function TIDEMsgScanners.GetCount: integer;
begin
Result:=fTypes.Count;
end;
function TIDEMsgScanners.GetItems(Index: integer): TIDEMsgScannerType;
begin
Result:=TIDEMsgScannerType(fTypes[Index]);
end;
function TIDEMsgScanners.GetScannerCount: integer;
begin
Result:=fScanners.Count;
end;
function TIDEMsgScanners.GetScanners(Index: integer): TIDEMsgScanner;
begin
Result:=TIDEMsgScanner(fScanners[Index]);
end;
constructor TIDEMsgScanners.Create;
begin
fTypes:=TFPList.Create;
fScanners:=TFPList.Create;
end;
destructor TIDEMsgScanners.Destroy;
var
i: Integer;
begin
for i:=0 to fTypes.Count-1 do TObject(fTypes[i]).Free;
FreeAndNil(fTypes);
for i:=0 to fScanners.Count-1 do TObject(fScanners[i]).Free;
FreeAndNil(fScanners);
inherited Destroy;
end;
procedure TIDEMsgScanners.RegisterType(aType: TIDEMsgScannerType);
begin
if (aType.Name='') or (not IsValidIdent(aType.Name)) then
raise Exception.Create('TIDEMsgScanners.RegisterType invalid name "'+dbgstr(aType.Name)+'"');
aType.Name:=CreateUniqueName(aType.Name);
fTypes.Add(aType);
end;
procedure TIDEMsgScanners.UnregisterType(aType: TIDEMsgScannerType);
begin
fTypes.Remove(aType);
end;
function TIDEMsgScanners.CreateUniqueName(const aName: string): string;
var
i: Integer;
begin
Result:=aName;
if IndexOfName(Result)<0 then exit;
i:=1;
repeat
Result:=aName+'_'+IntToStr(i);
until IndexOfName(Result)<0;
end;
function TIDEMsgScanners.IndexOfName(const aTypeName: string): integer;
begin
Result:=fTypes.Count-1;
while (Result>=0)
and (SysUtils.CompareText(Items[Result].Name,aTypeName)<>0) do
dec(Result);
end;
function TIDEMsgScanners.TypeOfName(const aTypeName: string
): TIDEMsgScannerType;
var
i: LongInt;
begin
i:=IndexOfName(aTypeName);
if i>=0 then
Result:=Items[i]
else
Result:=nil;
end;
function TIDEMsgScanners.IndexOfShortDesc(const ShortDescription: string
): integer;
begin
Result:=fTypes.Count-1;
while (Result>=0)
and (SysUtils.CompareText(Items[Result].ShortDescription,ShortDescription)<>0) do
dec(Result);
end;
function TIDEMsgScanners.TypeOfShortDesc(const ShortDescription: string
): TIDEMsgScannerType;
var
i: LongInt;
begin
i:=IndexOfShortDesc(ShortDescription);
if i>=0 then
Result:=Items[i]
else
Result:=nil;
end;
{$ENDIF EnableNewExtTools}
end.
|