From ab03974ccf00cc666298e33ab616fd5682e68c13 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 1 Jan 2025 13:36:12 +0100 Subject: [PATCH] codetools: fixed find used unit with ampersands --- components/codetools/basiccodetools.pas | 10 ++++++++ components/codetools/directorycacher.pas | 2 +- components/codetools/finddeclarationtool.pas | 24 ++++---------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index b4388234ff..c98df0e843 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -205,6 +205,7 @@ function TrimCodeSpace(const ACode: string): string; function CodeIsOnlySpace(const ACode: string; FromPos, ToPos: integer): boolean; function StringToPascalConst(const s: string): string; function UnicodeSpacesToASCII(const s: string): string; +function RemoveAmpersands(const s: string): string; // string constants function SplitStringConstant(const StringConstant: string; @@ -5768,6 +5769,15 @@ begin until false; end; +function RemoveAmpersands(const s: string): string; +var + i: SizeInt; +begin + Result:=s; + for i:=length(Result) downto 1 do + if Result[i]='&' then Delete(Result,i,1); +end; + function SplitStringConstant(const StringConstant: string; FirstLineLength, OtherLineLengths, Indent: integer; const aLineBreak: string): string; diff --git a/components/codetools/directorycacher.pas b/components/codetools/directorycacher.pas index 71e1fc0f05..02b056ad68 100644 --- a/components/codetools/directorycacher.pas +++ b/components/codetools/directorycacher.pas @@ -1813,7 +1813,7 @@ begin if Result='' then begin // search in unit set {$IFDEF ShowTriedUnits} - DebugLn(['TCTDirectoryCache.FindUnitSourceInCompletePath unit ',AUnitName,' not found in SrcPath="',SrcPath,'" Directory="',Directory,'" searchin in unitset ...']); + DebugLn(['TCTDirectoryCache.FindUnitSourceInCompletePath unit ',AUnitName,' not found in SrcPath="',SrcPath,'" Directory="',Directory,'" searching in unitset ...']); {$ENDIF} Result:=FindUnitInUnitSet(AUnitName,FPCSrcSearchRequiresPPU); {$IFDEF ShowTriedUnits} diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 224f24c886..6ebb5788ec 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -3262,27 +3262,13 @@ begin RaiseException(20171214184519,'TFindDeclarationTool.FindUnitSource Invalid Data'); if (Scanner.OnLoadSource=nil) then RaiseException(20171214184527,'TFindDeclarationTool.FindUnitSource Invalid Data'); - // check project source name first - if (Tree<>nil) and (Tree.Root<>nil) then begin - Node:=Tree.Root.FirstChild; - if (Node<>nil) and - (Node.Parent.Desc in [ctnProgram, ctnLibrary,ctnPackage]) and - (Node.Desc=ctnSrcName) then begin - curSrc:= ExtractIdentifierWithPoints(Node.StartPos,false); - if (CompareDottedIdentifiers(PChar(curSrc),PChar(AnUnitName))=0) - and (Length(curSrc)=Length(AnUnitName)) then - Result:=TCodeBuffer(Scanner.OnLoadSource(Self,Scanner.MainFilename,true)); - end; - end; - if Result=nil then begin // original code, only units - NewUnitName:=AnUnitName; - NewInFilename:=AnUnitInFilename; + NewUnitName:=RemoveAmpersands(AnUnitName); + NewInFilename:=AnUnitInFilename; - AFilename:=DirectoryCache.FindUnitSourceInCompletePath( - NewUnitName,NewInFilename,false,false,AddedNameSpace); - Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AFilename,true)); - end; + AFilename:=DirectoryCache.FindUnitSourceInCompletePath( + NewUnitName,NewInFilename,false,false,AddedNameSpace); + Result:=TCodeBuffer(Scanner.OnLoadSource(Self,AFilename,true)); if (Result=nil) and Assigned(OnFindUsedUnit) then begin // no unit found