mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 10:19:36 +02:00
codetools: search dotted unitnames in namespaces
This commit is contained in:
parent
98ab457e1b
commit
efe7efbc39
@ -225,7 +225,7 @@ type
|
||||
SearchPath: string; AnyCase: boolean): string; // search in unitpath
|
||||
function FindUnitSourceInCompletePath(var AUnitName, InFilename: string; // search in unitpath and unitpaths of output dirs
|
||||
AnyCase: boolean; FPCSrcSearchRequiresPPU: boolean = false;
|
||||
const AddNameSpaces: string = ''): string;
|
||||
const AddNameSpaces: string = ''; WithNamespaces: boolean = true): string;
|
||||
// find ppu/dcu file
|
||||
function FindCompiledUnitInUnitSet(const AUnitName: string): string;
|
||||
function FindCompiledUnitInCompletePath(const AnUnitname: string; AnyCase: boolean): string;
|
||||
@ -1663,9 +1663,9 @@ begin
|
||||
Result:='';
|
||||
end;
|
||||
|
||||
function TCTDirectoryCache.FindUnitSourceInCompletePath(var AUnitName,
|
||||
InFilename: string; AnyCase: boolean; FPCSrcSearchRequiresPPU: boolean;
|
||||
const AddNameSpaces: string): string;
|
||||
function TCTDirectoryCache.FindUnitSourceInCompletePath(var AUnitName, InFilename: string;
|
||||
AnyCase: boolean; FPCSrcSearchRequiresPPU: boolean; const AddNameSpaces: string;
|
||||
WithNamespaces: boolean): string;
|
||||
|
||||
function FindInFilenameLowUp(aFilename: string): string;
|
||||
begin
|
||||
@ -1754,8 +1754,7 @@ begin
|
||||
end else begin
|
||||
// normal unit name
|
||||
|
||||
if Pos('.',AUnitName)<1 then begin
|
||||
// generic unit -> search with namespaces
|
||||
if WithNamespaces then begin
|
||||
NameSpaces:=MergeWithDelimiter(Strings[ctdcsNamespaces],AddNameSpaces,';');
|
||||
if NameSpaces<>'' then begin
|
||||
// search with additional namespaces, separated by semicolon
|
||||
@ -1772,7 +1771,7 @@ begin
|
||||
if IsValidIdent(aNameSpace,true,true) then begin
|
||||
aName:=aNameSpace+'.'+AUnitName;
|
||||
Result:=FindUnitSourceInCompletePath(aName,InFilename,AnyCase,
|
||||
FPCSrcSearchRequiresPPU,'');
|
||||
FPCSrcSearchRequiresPPU,'',false);
|
||||
if Result<>'' then begin
|
||||
AUnitName:=RightStr(aName,length(aName)-length(aNameSpace)-1);
|
||||
exit;
|
||||
@ -1823,7 +1822,8 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
AddToCache(UnitSrc,AUnitName,Result);
|
||||
if AddNameSpaces='' then
|
||||
AddToCache(UnitSrc,AUnitName,Result);
|
||||
end;
|
||||
if Result<>'' then begin
|
||||
// improve unit name
|
||||
|
@ -68,11 +68,12 @@ unit TestFindDeclaration;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, contnrs, fpcunit, testregistry, FileProcs, LazFileUtils,
|
||||
LazLogger, CodeToolManager, ExprEval, CodeCache, BasicCodeTools,
|
||||
Classes, SysUtils, contnrs, fpcunit, testregistry, StrUtils,
|
||||
FileProcs, LazFileUtils, LazLogger,
|
||||
CodeToolManager, ExprEval, CodeCache, BasicCodeTools,
|
||||
CustomCodeTool, CodeTree, FindDeclarationTool, KeywordFuncLists,
|
||||
IdentCompletionTool, DefineTemplates, DirectoryCacher, CTUnitGraph, StrUtils,
|
||||
TestPascalParser;
|
||||
IdentCompletionTool, DefineTemplates, DirectoryCacher, CTUnitGraph,
|
||||
TestGlobals, TestPascalParser;
|
||||
|
||||
const
|
||||
MarkDecl = '#'; // a declaration, must be unique
|
||||
@ -172,12 +173,14 @@ type
|
||||
procedure TestFindDeclaration_IncludeSearch_StarStar;
|
||||
procedure TestFindDeclaration_FindFPCSrcNameSpacedUnits;
|
||||
|
||||
// unit namespaces
|
||||
// unit namespaces and dotted unitnames
|
||||
procedure TestFindDeclaration_NS_Program; // todo
|
||||
procedure TestFindDeclaration_NS_ProgLocalVsUses;
|
||||
procedure TestFindDeclaration_NS_UnitIntfVsUses;
|
||||
procedure TestFindDeclaration_NS_UnitImplVsIntfUses;
|
||||
procedure TestFindDeclaration_NS_UnitImplVsImplUses;
|
||||
procedure TestDirectoyCache_NS_SearchDotted;
|
||||
procedure TestFindDeclaration_NS_SearchDottedUsesInNS;
|
||||
|
||||
// directives
|
||||
procedure TestFindDeclaration_Directive_OperatorIn;
|
||||
@ -1977,6 +1980,52 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestFindDeclaration.TestDirectoyCache_NS_SearchDotted;
|
||||
var
|
||||
DotsUnit: TCodeBuffer;
|
||||
aUnitName, InFile, Filename: String;
|
||||
begin
|
||||
AddNameSpace('nsA');
|
||||
DotsUnit:=CodeToolBoss.CreateFile('nsA.foo.bar.pp');
|
||||
try
|
||||
aUnitName:='foo.bar';
|
||||
InFile:='';
|
||||
Filename:=CodeToolBoss.DirectoryCachePool.FindUnitSourceInCompletePath('',aUnitName,InFile);
|
||||
AssertEquals('nsA.foo.bar.pp',Filename);
|
||||
finally
|
||||
DotsUnit.IsDeleted:=true;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestFindDeclaration.TestFindDeclaration_NS_SearchDottedUsesInNS;
|
||||
var
|
||||
DotsUnit: TCodeBuffer;
|
||||
begin
|
||||
AddNameSpace('nsA');
|
||||
DotsUnit:=CodeToolBoss.CreateFile('nsA.foo.bar.pp');
|
||||
try
|
||||
DotsUnit.Source:=LinesToStr([
|
||||
'unit nsA.Foo.Bar;',
|
||||
'interface',
|
||||
'var Size: word;',
|
||||
'implementation',
|
||||
'end.']);
|
||||
|
||||
StartUnit;
|
||||
Add([
|
||||
'implementation',
|
||||
'uses foo.bar;',
|
||||
'begin',
|
||||
' Size{declaration:nsA.foo.bar.Size}:=1',
|
||||
' foo.bar.Size{declaration:nsA.foo.bar.Size}:=2',
|
||||
'end.',
|
||||
'']);
|
||||
FindDeclarations(Code);
|
||||
finally
|
||||
DotsUnit.IsDeleted:=true;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TTestFindDeclaration.TestFindDeclaration_Directive_OperatorIn;
|
||||
begin
|
||||
StartProgram;
|
||||
|
Loading…
Reference in New Issue
Block a user