implemented identifier completion for uses section

git-svn-id: trunk@8353 -
This commit is contained in:
mattias 2005-12-21 19:13:06 +00:00
parent 29663822c6
commit 7ffc2d0f43
5 changed files with 69 additions and 18 deletions

View File

@ -3253,6 +3253,7 @@ var
NewItem: TUnitFileInfo;
begin
AnUnitName:=ExtractFileNameOnly(Filename);
//DebugLn('AddFilename AnUnitName="',AnUnitName,'" Filename="',Filename,'"');
if (not KeepDoubles) then begin
if (TreeOfUnitFiles<>nil)
and (TreeOfUnitFiles.FindKey(Pointer(AnUnitName),
@ -3275,8 +3276,10 @@ var
FileInfo: TSearchRec;
begin
Result:=true;
//DebugLn('SearchDirectory ADirectory="',ADirectory,'"');
if DirectoryAlreadySearched(ADirectory) then exit;
MarkDirectoryAsSearched(ADirectory);
//DebugLn('SearchDirectory searching ...');
if not DirPathExists(ADirectory) then exit;
if SysUtils.FindFirst(ADirectory+FileMask,faAnyFile,FileInfo)=0 then begin
@ -3286,7 +3289,7 @@ var
then
continue;
if ExtensionFits(FileInfo.Name) then begin
AddFilename(FileInfo.Name);
AddFilename(ADirectory+FileInfo.Name);
end;
until SysUtils.FindNext(FileInfo)<>0;
end;
@ -3329,19 +3332,20 @@ end;
procedure FreeTreeOfUnitFiles(TreeOfUnitFiles: TAVLTree);
begin
TreeOfUnitFiles.FreeAndClear;
TreeOfUnitFiles.Free;
end;
function CompareUnitFileInfos(Data1, Data2: Pointer): integer;
begin
Result:=SysUtils.CompareText(TUnitFileInfo(Data1).UnitName,
TUnitFileInfo(Data2).UnitName);
Result:=CompareIdentifiers(PChar(TUnitFileInfo(Data1).UnitName),
PChar(TUnitFileInfo(Data2).UnitName));
end;
function CompareUnitNameAndUnitFileInfo(UnitnamePAnsiString,
UnitFileInfo: Pointer): integer;
begin
Result:=SysUtils.CompareText(PAnsiString(UnitnamePAnsiString)^,
TUnitFileInfo(UnitFileInfo).UnitName);
Result:=CompareIdentifiers(PChar(UnitnamePAnsiString),
PChar(TUnitFileInfo(UnitFileInfo).UnitName));
end;
procedure RaiseCatchableException(const Msg: string);

View File

@ -942,8 +942,48 @@ end;
procedure TIdentCompletionTool.GatherUnitnames(CleanPos: integer;
const Context: TFindContext; BeautifyCodeOptions: TBeautifyCodeOptions);
var
UnitPath, SrcPath: string;
BaseDir: String;
TreeOfUnitFiles: TAVLTree;
ANode: TAVLTreeNode;
UnitFileInfo: TUnitFileInfo;
NewItem: TIdentifierListItem;
UnitExt: String;
SrcExt: String;
CurSourceName: String;
begin
UnitPath:='';
SrcPath:='';
GatherUnitAndSrcPath(UnitPath,SrcPath);
//DebugLn('TIdentCompletionTool.GatherUnitnames UnitPath="',UnitPath,'" SrcPath="',SrcPath,'"');
BaseDir:=ExtractFilePath(MainFilename);
TreeOfUnitFiles:=nil;
try
// search in unitpath
UnitExt:='pp;pas;ppu';
GatherUnitFiles(BaseDir,UnitPath,UnitExt,false,true,TreeOfUnitFiles);
// search in srcpath
SrcExt:='pp;pas';
GatherUnitFiles(BaseDir,SrcPath,SrcExt,false,true,TreeOfUnitFiles);
// create list
CurSourceName:=GetSourceName;
ANode:=TreeOfUnitFiles.FindLowest;
while ANode<>nil do begin
UnitFileInfo:=TUnitFileInfo(ANode.Data);
if CompareIdentifiers(PChar(UnitFileInfo.UnitName),PChar(CurSourceName))<>0
then begin
NewItem:=TIdentifierListItem.Create(
icompCompatible,true,0,
CurrentIdentifierList.CreateIdentifier(UnitFileInfo.UnitName),
0,nil,nil,ctnUnit);
CurrentIdentifierList.Add(NewItem);
end;
ANode:=TreeOfUnitFiles.FindSuccessor(ANode);
end;
finally
FreeTreeOfUnitFiles(TreeOfUnitFiles);
end;
end;
function TIdentCompletionTool.GatherIdentifiers(

View File

@ -46,6 +46,8 @@ type
{ TPascalReaderTool }
TPascalReaderTool = class(TPascalParserTool)
protected
CachedSourceName: string;
public
function FindDeepestExpandedNodeAtPos(CleanCursorPos: integer;
ExceptionOnNotFound: boolean): TCodeTreeNode;
@ -140,6 +142,7 @@ type
): boolean;
// sections
function GetSourceName: string;
function GetSourceType: TCodeTreeNodeDesc;
function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
function ExtractSourceName: string;
@ -1426,6 +1429,16 @@ begin
Result:=UpAtomIs('CONST') or UpAtomIs('VAR') or UpAtomIs('OUT');
end;
function TPascalReaderTool.GetSourceName: string;
var NamePos: TAtomPosition;
begin
Result:='';
BuildTree(true);
if not GetSourceNamePos(NamePos) then exit;
CachedSourceName:=copy(Src,NamePos.StartPos,NamePos.EndPos-NamePos.StartPos);
Result:=CachedSourceName;
end;
function TPascalReaderTool.PropertyIsDefault(PropertyNode: TCodeTreeNode
): boolean;
begin

View File

@ -65,7 +65,6 @@ type
TStandardCodeTool = class(TIdentCompletionTool)
private
CachedSourceName: string;
function ReadTilGuessedUnclosedBlock(MinCleanPos: integer;
ReadOnlyOneBlock: boolean): boolean;
function ReadForwardTilAnyBracketClose: boolean;
@ -75,7 +74,6 @@ type
function Explore(WithStatements: boolean): boolean;
// source name e.g. 'unit UnitName;'
function GetSourceName: string;
function GetCachedSourceName: string;
function RenameSource(const NewName: string;
SourceChangeCache: TSourceChangeCache): boolean;
@ -309,16 +307,6 @@ end;
{ TStandardCodeTool }
function TStandardCodeTool.GetSourceName: string;
var NamePos: TAtomPosition;
begin
Result:='';
BuildTree(true);
if not GetSourceNamePos(NamePos) then exit;
CachedSourceName:=copy(Src,NamePos.StartPos,NamePos.EndPos-NamePos.StartPos);
Result:=CachedSourceName;
end;
{-------------------------------------------------------------------------------
function TStandardCodeTool.GetCachedSourceName: string;
Params: none

View File

@ -176,6 +176,12 @@ begin
AColor:=clOlive;
s:='enum';
end;
ctnUnit:
begin
AColor:=clBlack;
s:='unit';
end;
else
AColor:=clGray;