IDE: quickfix item for identifier not found: search via code browser

git-svn-id: trunk@21532 -
This commit is contained in:
mattias 2009-09-01 21:57:19 +00:00
parent be5c686379
commit 6d1ab9f902
6 changed files with 193 additions and 19 deletions

View File

@ -74,7 +74,7 @@ object CodeBrowserView: TCodeBrowserView
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 53
Top = 187
Top = 202
Width = 611
Anchors = [akTop, akLeft, akRight]
AutoSize = True
@ -133,8 +133,8 @@ object CodeBrowserView: TCodeBrowserView
AnchorSideTop.Control = OptionsGroupBox
AnchorSideTop.Side = asrBottom
Left = 0
Height = 276
Top = 246
Height = 261
Top = 261
Width = 623
Align = alBottom
Anchors = [akTop, akLeft, akRight, akBottom]
@ -164,14 +164,14 @@ object CodeBrowserView: TCodeBrowserView
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 6
Height = 109
Height = 124
Top = 72
Width = 611
Anchors = [akTop, akLeft, akRight]
AutoSize = True
BorderSpacing.Around = 6
Caption = 'LevelsGroupBox'
ClientHeight = 90
ClientHeight = 105
ClientWidth = 607
TabOrder = 3
object PackageFilterBeginsSpeedButton: TSpeedButton

View File

@ -26,7 +26,7 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
+'onsGroupBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'
+#7#14'LevelsGroupBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#23'AnchorSideRig'
+'ht.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#21'AnchorSid'
+'eBottom.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'5'#3'Top'#3#187#0#5'Wi'
+'eBottom.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'5'#3'Top'#3#202#0#5'Wi'
+'dth'#3'c'#2#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#18
+'BorderSpacing.Left'#2#6#17'BorderSpacing.Top'#2#6#19'BorderSpacing.Right'#2
+#6#7'Caption'#6#15'OptionsGroupBox'#29'ChildSizing.EnlargeHorizontal'#7#24'c'
@ -49,8 +49,8 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
+'g.Around'#2#6#7'Caption'#6#22'ShowEmptyNodesCheckBox'#13'OnEditingDone'#7#25
+'ShowPrivateCheckBoxChange'#8'TabOrder'#2#2#0#0#0#9'TTreeView'#14'BrowseTree'
+'View'#21'AnchorSideTop.Control'#7#15'OptionsGroupBox'#18'AnchorSideTop.Side'
+#7#9'asrBottom'#4'Left'#2#0#6'Height'#3#20#1#3'Top'#3#246#0#5'Width'#3'o'#2#5
+'Align'#7#8'alBottom'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'
+#7#9'asrBottom'#4'Left'#2#0#6'Height'#3#5#1#3'Top'#3#5#1#5'Width'#3'o'#2#5'A'
+'lign'#7#8'alBottom'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'
+#0#17'BorderSpacing.Top'#2#6#17'DefaultItemHeight'#2#19#6'Images'#7#10'Image'
+'List1'#14'ParentShowHint'#8#9'PopupMenu'#7#10'PopupMenu1'#8'ReadOnly'#9#8'S'
+'howHint'#9#8'TabOrder'#2#2#11'OnMouseDown'#7#23'BrowseTreeViewMouseDown'#10
@ -61,9 +61,9 @@ LazarusResources.Add('TCodeBrowserView','FORMDATA',[
+'anels'#14#0#0#0#9'TGroupBox'#14'LevelsGroupBox'#22'AnchorSideLeft.Control'#7
+#5'Owner'#21'AnchorSideTop.Control'#7#13'ScopeGroupBox'#18'AnchorSideTop.Sid'
+'e'#7#9'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight'
+'.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'm'#3'Top'#2'H'#5'Width'#3'c'#2
+'.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#2'|'#3'Top'#2'H'#5'Width'#3'c'#2
+#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#20'BorderSpacin'
+'g.Around'#2#6#7'Caption'#6#14'LevelsGroupBox'#12'ClientHeight'#2'Z'#11'Clie'
+'g.Around'#2#6#7'Caption'#6#14'LevelsGroupBox'#12'ClientHeight'#2'i'#11'Clie'
+'ntWidth'#3'_'#2#8'TabOrder'#2#3#0#12'TSpeedButton'#30'PackageFilterBeginsSp'
,'eedButton'#22'AnchorSideLeft.Control'#7#17'PackageFilterEdit'#19'AnchorSide'
+'Left.Side'#7#9'asrBottom'#21'AnchorSideTop.Control'#7#17'PackageFilterEdit'

View File

@ -51,10 +51,10 @@ uses
CodeToolManager, PascalParserTool, LinkScanner, FileProcs, CodeIndex,
StdCodeTools, SourceLog,
// IDEIntf
SrcEditorIntf, IDEDialogs, LazConfigStorage, Project, PackageIntf,
IDECommands, LazIDEIntf, DialogProcs,
SrcEditorIntf, IDEMsgIntf, IDEDialogs, LazConfigStorage, Project, PackageIntf,
TextTools, IDECommands, LazIDEIntf, DialogProcs,
// IDE
PackageSystem, PackageDefs, LazarusIDEStrConsts, IDEOptionDefs,
PackageSystem, PackageDefs, LazarusIDEStrConsts, IDEOptionDefs, MsgQuickFixes,
BasePkgManager, AddToProjectDlg, EnvironmentOpts;
@ -324,7 +324,6 @@ type
procedure ExpandCollapseAllNodesInTreeView(NodeType: TExpandableNodeType;
Expand: boolean);
procedure CopyNode(TVNode: TTreeNode; NodeType: TCopyNodeType);
procedure InvalidateStage(AStage: TCodeBrowserWorkStage);
function GetSelectedUnit: TCodeBrowserUnit;
function GetSelectedPackage: TLazPackage;
function GetCurUnitInSrcEditor(out FileOwner: TObject;
@ -337,6 +336,12 @@ type
procedure EndUpdate;
function ExportTree: TModalResult;
function ExportTreeAsText(Filename: string): TModalResult;
function GetScopeToCurUnitOwner(UseFCLAsDefault: boolean): string;
function SetScopeToCurUnitOwner(UseFCLAsDefault,
WithRequiredPackages: boolean): boolean;
procedure SetFilterToSimpleIdentifier(Identifier: string);
procedure InvalidateStage(AStage: TCodeBrowserWorkStage);
public
property ParserRoot: TCodeBrowserUnitList read FParserRoot;
property WorkingParserRoot: TCodeBrowserUnitList read FWorkingParserRoot;
property ViewRoot: TCodeBrowserUnitList read FViewRoot;
@ -354,11 +359,23 @@ type
property UpdateNeeded: boolean read FUpdateNeeded write SetUpdateNeeded;
end;
{ TQuickFixIdentifierNotFound_Search }
TQuickFixIdentifierNotFound_Search = class(TIDEMsgQuickFixItem)
public
constructor Create;
function IsApplicable(Line: TIDEMessageLine): boolean; override;
procedure Execute(const Msg: TIDEMessageLine; Step: TIMQuickFixStep); override;
end;
var
CodeBrowserView: TCodeBrowserView = nil;
function StringToCodeBrowserTextFilter(const s: string): TCodeBrowserTextFilter;
procedure InitCodeBrowserQuickFixItems;
procedure CreateCodeBrowser;
implementation
const
@ -389,6 +406,17 @@ begin
Result:=cbtfBegins;
end;
procedure InitCodeBrowserQuickFixItems;
begin
RegisterIDEMsgQuickFix(TQuickFixIdentifierNotFound_Search.Create);
end;
procedure CreateCodeBrowser;
begin
if CodeBrowserView=nil then
CodeBrowserView:=TCodeBrowserView.Create(LazarusIDE.OwningComponent);
end;
{ TCodeBrowserView }
@ -2667,6 +2695,73 @@ begin
end;
end;
function TCodeBrowserView.GetScopeToCurUnitOwner(UseFCLAsDefault: boolean
): string;
var
SrcEdit: TSourceEditorInterface;
Code: TCodeBuffer;
MainCode: TCodeBuffer;
Owners: TFPList;
begin
Result:='';
if UseFCLAsDefault then
Result:=PackageGraph.FCLPackage.Name;
SrcEdit:=SourceEditorWindow.ActiveEditor;
if SrcEdit=nil then exit;
Code:=TCodeBuffer(SrcEdit.CodeToolsBuffer);
if Code=nil then exit;
MainCode:=CodeToolBoss.GetMainCode(Code);
if MainCode<>nil then
Code:=MainCode;
Owners:=PkgBoss.GetPossibleOwnersOfUnit(Code.FileName,[]);
try
if (Owners=nil) or (Owners.Count=0) then exit;
if TObject(Owners[0])=Project1 then begin
Result:=ProjectDescription;
exit;
end;
if TObject(Owners[0]) is TLazPackage then begin
Result:=TLazPackage(Owners[0]).Name;
exit;
end;
finally
Owners.Free;
end;
end;
function TCodeBrowserView.SetScopeToCurUnitOwner(UseFCLAsDefault,
WithRequiredPackages: boolean): boolean;
var
NewScope: String;
begin
Result:=false;
NewScope:=GetScopeToCurUnitOwner(UseFCLAsDefault);
if NewScope='' then exit;
ScopeComboBox.Text:=NewScope;
ScopeWithRequiredPackagesCheckBox.Checked:=WithRequiredPackages;
InvalidateStage(cbwsGetScopeOptions);
end;
procedure TCodeBrowserView.SetFilterToSimpleIdentifier(Identifier: string);
begin
ShowPackagesCheckBox.Checked:=true;
PackageFilterEdit.Text:='';
PackageFilterContainsSpeedButton.Down:=true;
ShowUnitsCheckBox.Checked:=true;
UnitFilterEdit.Text:='';
UnitFilterContainsSpeedButton.Down:=true;
ShowIdentifiersCheckBox.Checked:=true;
IdentifierFilterEdit.Text:=Identifier;
IdentifierFilterBeginsSpeedButton.Down:=true;
ShowEmptyNodesCheckBox.Checked:=false;
InvalidateStage(cbwsGetViewOptions);
end;
procedure TCodeBrowserView.BrowseTreeViewShowHint(Sender: TObject;
HintInfo: PHintInfo);
var
@ -2960,6 +3055,84 @@ begin
Result:=Levels.IndexOf(CodeBrowserLevelNames[Level])>=0;
end;
{ TQuickFixIdentifierNotFound_Search }
constructor TQuickFixIdentifierNotFound_Search.Create;
begin
Name:='Search identifier: Error: Identifier not found "identifier"';
Caption:='Search identifier';
Steps:=[imqfoMenuItem];
end;
function TQuickFixIdentifierNotFound_Search.IsApplicable(Line: TIDEMessageLine
): boolean;
const
SearchStr = ') Error: Identifier not found "';
var
Msg: String;
p: integer;
Code: TCodeBuffer;
Filename: string;
Caret: TPoint;
begin
Result:=false;
if (Line.Parts=nil) then exit;
Msg:=Line.Msg;
p:=System.Pos(SearchStr,Msg);
if p<1 then exit;
inc(p,length(SearchStr));
Line.GetSourcePosition(Filename,Caret.Y,Caret.X);
if (Filename='') or (Caret.X<1) or (Caret.Y<1) then exit;
Code:=CodeToolBoss.LoadFile(Filename,true,false);
if Code=nil then exit;
Result:=true;
end;
procedure TQuickFixIdentifierNotFound_Search.Execute(
const Msg: TIDEMessageLine; Step: TIMQuickFixStep);
var
Identifier: String;
CodeBuf: TCodeBuffer;
Filename: string;
Caret: TPoint;
begin
if Step=imqfoMenuItem then begin
DebugLn(['TQuickFixIdentifierNotFound_Search.Execute ']);
// get source position
// (FPC reports position right after the unknown identifier
// for example right after FilenameIsAbsolute)
if not GetMsgLineFilename(Msg,CodeBuf) then exit;
Msg.GetSourcePosition(Filename,Caret.Y,Caret.X);
if not LazarusIDE.BeginCodeTools then begin
DebugLn(['TQuickFixIdentifierNotFound_Search.Execute failed because IDE busy']);
exit;
end;
// get identifier
if not REMatches(Msg.Msg,'Error: Identifier not found "([a-z_0-9]+)"','I') then begin
DebugLn('TQuickFixIdentifierNotFound_Search invalid message ',Msg.Msg);
exit;
end;
Identifier:=REVar(1);
DebugLn(['TQuickFixIdentifierNotFound_Search.Execute Identifier=',Identifier]);
if (Identifier='') or (not IsValidIdent(Identifier)) then begin
DebugLn(['TQuickFixIdentifierNotFound_Search.Execute not an identifier "',dbgstr(Identifier),'"']);
exit;
end;
if LazarusIDE.DoOpenFileAndJumpToPos(Filename,Caret,-1,-1,OpnFlagsPlainFile
)<>mrOk
then exit;
// start code browser
CreateCodeBrowser;
CodeBrowserView.SetScopeToCurUnitOwner(true,true);
CodeBrowserView.SetFilterToSimpleIdentifier(Identifier);
CodeBrowserView.ShowOnTop;
end;
end;
initialization
{$I codebrowser.lrs}

View File

@ -1917,6 +1917,7 @@ end;
procedure TMainIDE.SetupIDEMsgQuickFixItems;
begin
InitStandardIDEQuickFixItems;
InitCodeBrowserQuickFixItems;
end;
procedure TMainIDE.SetupStartProject;
@ -8133,10 +8134,7 @@ end;
procedure TMainIDE.DoShowCodeBrowser;
begin
if CodeBrowserView=nil then begin
CodeBrowserView:=TCodeBrowserView.Create(OwningComponent);
end;
CreateCodeBrowser;
CodeBrowserView.ShowOnTop;
end;

View File

@ -541,7 +541,7 @@ begin
exit;
end;
// get class name
// get identifier
if not REMatches(Msg.Msg,'Error: Identifier not found "([a-z_0-9]+)"','I') then begin
DebugLn('TQuickFixIdentifierNotFoundAddLocal invalid message ',Msg.Msg);
exit;

View File

@ -45,6 +45,9 @@ type
);
TOpenFlags = set of TOpenFlag;
const
OpnFlagsPlainFile = [ofOnlyIfExists,ofQuiet,ofRegularFile,ofVirtualFile,ofDoNotLoadResource];
type
// new file flags
TNewFlag = (
nfIsPartOfProject, // force IsPartOfProject,