ide+codetools: less hints

This commit is contained in:
mattias 2023-08-03 18:07:54 +02:00
parent 74f240f5f3
commit 68920c7d01
11 changed files with 192 additions and 11 deletions

View File

@ -238,7 +238,7 @@ type
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure AddIndent(Typ, SubType: TFABBlockType; SrcPos, Indent: integer);
procedure AddIndent(Typ, SubType: TFABBlockType; {%H-}SrcPos, Indent: integer);
function GetSmallestIndent(Typ: TFABBlockType): integer;// -1 if none found
function GetIndent(Typ, SubType: TFABBlockType;
UseNoneIfNotFound,

View File

@ -813,7 +813,7 @@ begin
Result:=(ANodeExt.Flags=ord(ncpPublishedVars))
or (ANodeExt.Flags=ord(ncpPublishedProcs));
else
Result:=false;
Result:=false{%H-};
end;
end;

View File

@ -6559,7 +6559,7 @@ begin
ctdcsUnitSet: Result:=GetUnitSetIDForDirectory(ADirectory,false);
ctdcsFPCUnitPath: Result:=GetFPCUnitPathForDirectory(ADirectory,false);
ctdcsNamespaces: Result:=GetNamespacesForDirectory(ADirectory,false);
else RaiseCatchableException('');
else RaiseCatchableException(''){%H-};
end;
end;

View File

@ -812,7 +812,7 @@ var
end;
else
exit;
exit{%H-};
end;
Result:=true;
end;

View File

@ -978,6 +978,10 @@ type
function FindUnitCaseInsensitive(var AnUnitName,
AnUnitInFilename: string): string;
procedure GatherUnitAndSrcPath(var UnitPath, CompleteSrcPath: string);
function GatherUnitFiles(const SearchPath,
Extensions, NameSpacePath: string; KeepDoubles, CaseInsensitive: boolean;
var TreeOfUnitFiles, TreeOfNamespaces: TAVLTree): boolean;
function SearchUnitInUnitSet(const TheUnitName: string): string;
function GetNameSpaces: string;
@ -3153,6 +3157,183 @@ begin
//DebugLn('TFindDeclarationTool.GatherUnitAndSrcPath UnitPath="',UnitPath,'" CompleteSrcPath="',CompleteSrcPath,'"');
end;
function TFindDeclarationTool.GatherUnitFiles(const SearchPath, Extensions,
NameSpacePath: string; KeepDoubles, CaseInsensitive: boolean;
var TreeOfUnitFiles, TreeOfNamespaces: TAVLTree): boolean;
{
SearchPath: semicolon separated list of directories
Extensions: semicolon separated list of extensions (e.g. 'pas;.pp;ppu')
NameSpacePath: gather files only from this namespace path, empty '' for all
KeepDoubles: false to return only the first match of each unit
CaseInsensitive: true to ignore case on comparing extensions
TreeOfUnitFiles: tree of TUnitFileInfo
TreeOfNamespaces: tree of TNameSpaceInfo }
var
SearchedDirectories: TAVLTree; // tree of AnsiString
function DirectoryAlreadySearched(const ADirectory: string): boolean;
begin
Result:=(SearchedDirectories<>nil)
and (SearchedDirectories.Find(Pointer(ADirectory))<>nil);
end;
procedure MarkDirectoryAsSearched(const ADirectory: string);
var
s: String;
begin
// increase refcount
//DebugLn('MarkDirectoryAsSearched ',ADirectory);
s:=ADirectory; // increase refcount
if SearchedDirectories=nil then
SearchedDirectories:=TAVLTree.Create(@CompareAnsiStringFilenames);
SearchedDirectories.Add(Pointer(s));
Pointer(s):=nil; // keep refcount
end;
procedure FreeSearchedDirectories;
var
ANode: TAVLTreeNode;
s: String;
begin
if SearchedDirectories=nil then exit;
s:='';
ANode:=SearchedDirectories.FindLowest;
while ANode<>nil do begin
Pointer(s):=ANode.Data;
//DebugLn('FreeSearchedDirectories ',s);
s:=''; // decrease refcount
ANode:=SearchedDirectories.FindSuccessor(ANode);
end;
if s='' then ;
SearchedDirectories.Free;
end;
function ExtensionFits(const Filename: string): boolean;
var
ExtStart: Integer;
ExtLen: Integer; // length without '.'
CurExtStart: Integer;
CurExtEnd: LongInt;
CompareCaseInsensitive: Boolean;
p: Integer;
begin
CompareCaseInsensitive:=CaseInsensitive;
{$IFDEF Windows}
CompareCaseInsensitive:=true;
{$ENDIF}
ExtStart:=length(Filename);
while (ExtStart>=1) and (not (Filename[ExtStart] in [PathDelim,'.'])) do
dec(ExtStart);
if (ExtStart>0) and (Filename[ExtStart]='.') then begin
// filename has an extension
ExtLen:=length(Filename)-ExtStart;
inc(ExtStart);
CurExtStart:=1;
while (CurExtStart<=length(Extensions)) do begin
// skip '.'
if Extensions[CurExtStart]='.' then inc(CurExtStart);
// read till semicolon
CurExtEnd:=CurExtStart;
while (CurExtEnd<=length(Extensions)) and (Extensions[CurExtEnd]<>';')
do
inc(CurExtEnd);
if (CurExtEnd>CurExtStart) and (CurExtEnd-CurExtStart=ExtLen) then begin
// compare extension
p:=ExtLen-1;
while (p>=0) do begin
if CompareCaseInsensitive then begin
if UpChars[Filename[ExtStart+p]]
<>UpChars[Extensions[CurExtStart+p]]
then
break;
end else begin
if Filename[ExtStart+p]<>Extensions[CurExtStart+p] then
break;
end;
dec(p);
end;
if p<0 then begin
// extension fit
Result:=true;
exit;
end;
end;
CurExtStart:=CurExtEnd+1;
end;
end;
Result:=false;
end;
procedure CollectFile(const aFilename: string);
begin
if ExtensionFits(aFilename) then
AddToTreeOfUnitFilesOrNamespaces(TreeOfUnitFiles, TreeOfNamespaces,
NameSpacePath, aFilename, CaseInsensitive, KeepDoubles);
end;
function SearchDirectory(const ADirectory: string): boolean;
var
Cache: TCTDirectoryBaseCache;
StarCache: TCTStarDirectoryCache;
DirCache: TCTDirectoryCache;
i: Integer;
begin
Result:=true;
//DebugLn('SearchDirectory ADirectory="',ADirectory,'"');
if DirectoryAlreadySearched(ADirectory) then exit;
MarkDirectoryAsSearched(ADirectory);
//DebugLn('SearchDirectory searching ...');
Cache:=DirectoryCache.Pool.GetBaseCache(ADirectory);
if Cache=nil then exit;
Cache.UpdateListing;
if Cache is TCTStarDirectoryCache then
begin
StarCache:=TCTStarDirectoryCache(Cache);
for i:=0 to StarCache.Listing.Count-1 do
CollectFile(StarCache.Listing.GetSubDirFilename(i));
end else if Cache is TCTDirectoryCache then begin
DirCache:=TCTDirectoryCache(Cache);
for i:=0 to DirCache.Listing.Count-1 do
CollectFile(DirCache.Directory+DirCache.Listing.GetFilename(i));
end;
end;
var
PathStartPos: Integer;
PathEndPos: LongInt;
CurDir, BaseDir: String;
begin
Result:=false;
SearchedDirectories:=nil;
try
// search all paths in SearchPath
BaseDir:=ExtractFilePath(MainFilename);
PathStartPos:=1;
while PathStartPos<=length(SearchPath) do begin
PathEndPos:=PathStartPos;
while (PathEndPos<=length(SearchPath)) and (SearchPath[PathEndPos]<>';')
do
inc(PathEndPos);
if PathEndPos>PathStartPos then begin
CurDir:=AppendPathDelim(TrimFilename(
copy(SearchPath,PathStartPos,PathEndPos-PathStartPos)));
if not FilenameIsAbsolute(CurDir) then
CurDir:=AppendPathDelim(BaseDir)+CurDir;
if not SearchDirectory(CurDir) then exit;
end;
PathStartPos:=PathEndPos;
while (PathStartPos<=length(SearchPath))
and (SearchPath[PathStartPos]=';') do
inc(PathStartPos);
end;
Result:=true;
finally
FreeSearchedDirectories;
end;
end;
function TFindDeclarationTool.SearchUnitInUnitSet(const TheUnitName: string): string;
begin
Result:=DirectoryCache.FindUnitInUnitSet(TheUnitName);

View File

@ -475,7 +475,7 @@ begin
ogetParentChild: Result:=10;
ogetAncestorInherited: Result:=1;
ogetAliasOld: Result:=1;
else Result:=100;
else Result:=100{%H-};
end;
end;

View File

@ -280,7 +280,7 @@ begin
OuterRadiusY:=(y2-y1)/2;
InnerRadiusX:=OuterRadiusX*InnerSize;
InnerRadiusY:=OuterRadiusY*InnerSize;
SetLength(Points,OuterCnt*2+2);
SetLength(Points{%H-},OuterCnt*2+2);
j:=0;
// outer arc
for i:=0 to OuterCnt do begin

View File

@ -5600,7 +5600,7 @@ var
p, StartP, EndP: PChar;
const
space: char = ' ';
{%H-}space: char = ' ';
begin
LastStreamPos:=ExtractMemStream.Position;
if LastAtoms.HasPrior then begin

View File

@ -602,7 +602,7 @@ var
ParentNode: TCodeTreeNode;
OldPos: TAtomPosition;
const
SemiColon : char = ';';
{%H-}SemiColon : char = ';';
procedure PrependName(const Prepend: string; var aPath: string);
begin

View File

@ -32,7 +32,7 @@ unit IDEOptionDefs;
interface
uses
Classes, SysUtils, types,
Classes, SysUtils,
// LazUtils
LazFileUtils, LazConfigStorage, Laz2_XMLCfg, LazUTF8,
// BuildIntf

View File

@ -301,7 +301,7 @@ function CreateBuildMatrixOptionGUID: string;
var
i: Integer;
begin
SetLength(Result,12);
SetLength(Result{%H-},12);
for i:=1 to length(Result) do
Result[i]:=chr(ord('0')+random(10));
end;
@ -728,7 +728,7 @@ begin
l:=p-StartP;
while p^ in [#10,#13] do inc(p);
if l=0 then continue; // skip empty strings
SetLength(CurMode,l);
SetLength(CurMode{%H-},l);
System.Move(StartP^,CurMode[1],l);
if Assigned(SaveModes) and not SaveModes(CurMode) then continue;
// convert a single comma to double comma