Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions client/source/DelphiLint.Plugin.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ object PluginCore: TPluginCore
ShortCut = 57420
OnExecute = ActionAnalyzeOpenFilesExecute
end
object ActionAnalyzeChangedFiles: TAction
Category = 'DelphiLint'
Caption = 'Analyze &Changed Files'
Hint = 'Analyze all files with uncommitted version control changes'
ImageIndex = 2
OnExecute = ActionAnalyzeChangedFilesExecute
end
object ActionAnalyzeShort: TAction
Caption = 'Analyze'
ImageIndex = 3
Expand Down
85 changes: 85 additions & 0 deletions client/source/DelphiLint.Plugin.pas
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ TPluginCore = class(TDataModule)
ActionOpenProjectOptions: TAction;
ActionOpenSettings: TAction;
ActionAnalyzeOpenFiles: TAction;
ActionAnalyzeChangedFiles: TAction;
ActionRestartServer: TAction;
ActionClearActiveFile: TAction;
procedure ActionShowToolWindowExecute(Sender: TObject);
procedure ActionAnalyzeActiveFileExecute(Sender: TObject);
procedure ActionRestartServerExecute(Sender: TObject);
procedure ActionAnalyzeOpenFilesExecute(Sender: TObject);
procedure ActionAnalyzeChangedFilesExecute(Sender: TObject);
procedure ActionOpenSettingsExecute(Sender: TObject);
procedure ActionOpenProjectOptionsExecute(Sender: TObject);
procedure ActionClearActiveFileExecute(Sender: TObject);
Expand Down Expand Up @@ -119,10 +121,12 @@ implementation
System.SysUtils
, System.UITypes
, System.IOUtils
, System.StrUtils
, Vcl.ComCtrls
, Vcl.Dialogs
, Winapi.Windows
, DelphiLint.Utils
, DelphiLint.VersionControl
, DelphiLint.SetupForm
, DelphiLint.Version
, DelphiLint.Resources
Expand Down Expand Up @@ -226,6 +230,83 @@ procedure TPluginCore.ActionAnalyzeOpenFilesExecute(Sender: TObject);

//______________________________________________________________________________________________________________________

procedure TPluginCore.ActionAnalyzeChangedFilesExecute(Sender: TObject);
var
ProjectFile: string;
ProjectDir: string;
ChangedFiles: TArray<string>;
NormalizedChangedFiles: TArray<string>;
Files: TArray<string>;
Module: IIDEModule;
begin
if LintContext.Settings.ClientAutoShowToolWindow then begin
ShowToolWindow;
end;

if not TryGetProjectFile(ProjectFile) then begin
TaskMessageDlg(
'DelphiLint cannot analyze changed files.',
'There is no open Delphi project.',
mtWarning,
[mbOK],
0);
Exit;
end;

if not TryGetProjectDirectory(ProjectDir) then begin
ProjectDir := TPath.GetDirectoryName(ProjectFile);
end;

if not TryGetChangedDelphiFiles(ProjectDir, ChangedFiles) then begin
TaskMessageDlg(
'DelphiLint cannot analyze changed files.',
'The project is not in a Git repository, or Git could not be run.',
mtWarning,
[mbOK],
0);
Exit;
end;

if Length(ChangedFiles) = 0 then begin
TaskMessageDlg(
'DelphiLint cannot analyze changed files.',
'There are no changed files that can be analyzed.',
mtWarning,
[mbOK],
0);
Exit;
end;

if LintContext.Settings.ClientSaveBeforeAnalysis then begin
NormalizedChangedFiles := TArrayUtils.Map<string, string>(
ChangedFiles,
function(Path: string): string
begin
Result := NormalizePath(Path);
end);

for Module in DelphiLint.Utils.GetOpenSourceModules do begin
if IndexStr(NormalizePath(Module.FileName), NormalizedChangedFiles) <> -1 then begin
try
Module.Save(True);
except
on E: Exception do begin
Log.Warn('Module %s could not be saved', [Module.FileName]);
end;
end;
end;
end;
end;

Files := Copy(ChangedFiles);
SetLength(Files, Length(Files) + 1);
Files[Length(Files) - 1] := ProjectFile;

Analyzer.AnalyzeFiles(Files, ProjectFile);
end;

//______________________________________________________________________________________________________________________

procedure TPluginCore.ActionClearActiveFileExecute(Sender: TObject);
var
SourceEditor: IIDESourceEditor;
Expand Down Expand Up @@ -406,6 +487,7 @@ procedure TPluginCore.CreateMainMenu;
AddSeparator;
AddItem(ActionAnalyzeActiveFile);
AddItem(ActionAnalyzeOpenFiles);
AddItem(ActionAnalyzeChangedFiles);
AddSeparator;
AddItem(ActionClearActiveFile);
AddSeparator;
Expand Down Expand Up @@ -469,13 +551,15 @@ procedure TPluginCore.RefreshAnalysisActions;
ActionAnalyzeActiveFile.Enabled := True;
ActionAnalyzeShort.Enabled := True;
ActionAnalyzeOpenFiles.Enabled := True;
ActionAnalyzeChangedFiles.Enabled := True;
ActionClearActiveFile.Enabled := TryGetCurrentSourceEditor(SourceEditor)
and (Length(Analyzer.GetIssues(SourceEditor.FileName)) > 0);
end
else begin
ActionAnalyzeActiveFile.Enabled := False;
ActionAnalyzeShort.Enabled := False;
ActionAnalyzeOpenFiles.Enabled := False;
ActionAnalyzeChangedFiles.Enabled := False;
ActionClearActiveFile.Enabled := False;
end;
end;
Expand Down Expand Up @@ -511,6 +595,7 @@ procedure TPluginCore.RemoveToolbarActions(IDEServices: IIDEServices);
for ToolBar in CToolBars do begin
RemoveAction(ActionAnalyzeActiveFile, IDEServices.GetToolBar(ToolBar));
RemoveAction(ActionAnalyzeOpenFiles, IDEServices.GetToolBar(ToolBar));
RemoveAction(ActionAnalyzeChangedFiles, IDEServices.GetToolBar(ToolBar));
RemoveAction(ActionShowToolWindow, IDEServices.GetToolBar(ToolBar));
RemoveAction(ActionOpenProjectOptions, IDEServices.GetToolBar(ToolBar));
RemoveAction(ActionOpenSettings, IDEServices.GetToolBar(ToolBar));
Expand Down
3 changes: 3 additions & 0 deletions client/source/DelphiLint.ToolFrame.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ object LintToolFrame: TLintToolFrame
object AnalyzeOpenFiles1: TMenuItem
Action = PluginCore.ActionAnalyzeOpenFiles
end
object AnalyzeChangedFiles1: TMenuItem
Action = PluginCore.ActionAnalyzeChangedFiles
end
object Separator1: TMenuItem
Caption = '-'
end
Expand Down
1 change: 1 addition & 0 deletions client/source/DelphiLint.ToolFrame.pas
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TLintToolFrame = class(TFrame)
AnalyzePopupMenu: TPopupMenu;
AnalyzeCurrentFile1: TMenuItem;
AnalyzeOpenFiles1: TMenuItem;
AnalyzeChangedFiles1: TMenuItem;
StatusPanel: TPanel;
ProgLabel: TLabel;
ResizeIndicatorPanel: TPanel;
Expand Down
Loading