From 7943f543f2985225d9c58fe62d5595116cefc770 Mon Sep 17 00:00:00 2001 From: mattias Date: Tue, 8 May 2018 09:09:48 +0000 Subject: [PATCH] codetools: use unit scopes from fpc output git-svn-id: trunk@57844 - --- components/codetools/codetoolmanager.pas | 6 +++++ components/codetools/definetemplates.pas | 32 ++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 3c6decf97a..41de3ae80b 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -43,6 +43,7 @@ uses Classes, SysUtils, contnrs, TypInfo, types, Laz_AVL_Tree, // LazUtils LazFileUtils, LazFileCache, LazMethodList, LazDbgLog, AvgLvlTree, + LazUtilities, // Codetools FileProcs, BasicCodeTools, CodeToolsStrConsts, EventCodeTool, CodeTree, CodeAtom, SourceChanger, DefineTemplates, CodeCache, @@ -1702,6 +1703,7 @@ function TCodeToolManager.GetNamespacesForDirectory(const Directory: string; var Evaluator: TExpressionEvaluator; FPCFullVersion: LongInt; + UnitSet: TFPCUnitSetCache; begin if UseCache then begin Result:=DirectoryCachePool.GetString(Directory,ctdcsNamespaces,true) @@ -1716,6 +1718,10 @@ begin if FPCFullVersion>=30101 then Result:=Evaluator[NamespacesMacroName]; end; + // add default unit scopes from compiler cfg + UnitSet:=GetUnitSetForDirectory(Directory); + if UnitSet<>nil then + Result:=MergeWithDelimiter(Result,UnitSet.GetUnitScopes,';'); end; end; diff --git a/components/codetools/definetemplates.pas b/components/codetools/definetemplates.pas index d64a1935a5..d9abc96c54 100644 --- a/components/codetools/definetemplates.pas +++ b/components/codetools/definetemplates.pas @@ -977,6 +977,7 @@ type procedure IncreaseChangeStamp; function GetUnitSetID: string; function GetFirstFPCCfg: string; + function GetUnitScopes: string; end; { TCompilerDefinesCache } @@ -8636,7 +8637,6 @@ var i: Integer; p: Integer; StartPos: Integer; - Filename: String; begin Clear; @@ -10378,19 +10378,41 @@ function TFPCUnitSetCache.GetFirstFPCCfg: string; var Cfg: TPCTargetConfigCache; i: Integer; + Files: TPCConfigFileStateList; begin Result:=''; Cfg:=GetConfigCache(false); if Cfg=nil then exit; - if Cfg.ConfigFiles=nil then exit; - for i:=0 to Cfg.ConfigFiles.Count-1 do begin - if Cfg.ConfigFiles[i].FileExists then begin - Result:=Cfg.ConfigFiles[i].Filename; + Files:=Cfg.ConfigFiles; + if Files=nil then exit; + for i:=0 to Files.Count-1 do begin + if Files[i].FileExists then begin + Result:=Files[i].Filename; exit; end; end; end; +function TFPCUnitSetCache.GetUnitScopes: string; +var + Cfg: TPCTargetConfigCache; + Scopes: TStrings; + Scope: String; + i: Integer; +begin + Result:=''; + Cfg:=GetConfigCache(false); + if Cfg=nil then exit; + Scopes:=Cfg.UnitScopes; + if Scopes=nil then exit; + for i:=0 to Scopes.Count-1 do begin + Scope:=Scopes[i]; + if Scope='' then continue; + Result:=Result+';'+Scope; + end; + Delete(Result,1,1); +end; + initialization InitDefaultFPCSourceRules;