mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-11 12:09:30 +01:00
implemented identifier completion for uses section
git-svn-id: trunk@8353 -
This commit is contained in:
parent
29663822c6
commit
7ffc2d0f43
@ -3253,6 +3253,7 @@ var
|
|||||||
NewItem: TUnitFileInfo;
|
NewItem: TUnitFileInfo;
|
||||||
begin
|
begin
|
||||||
AnUnitName:=ExtractFileNameOnly(Filename);
|
AnUnitName:=ExtractFileNameOnly(Filename);
|
||||||
|
//DebugLn('AddFilename AnUnitName="',AnUnitName,'" Filename="',Filename,'"');
|
||||||
if (not KeepDoubles) then begin
|
if (not KeepDoubles) then begin
|
||||||
if (TreeOfUnitFiles<>nil)
|
if (TreeOfUnitFiles<>nil)
|
||||||
and (TreeOfUnitFiles.FindKey(Pointer(AnUnitName),
|
and (TreeOfUnitFiles.FindKey(Pointer(AnUnitName),
|
||||||
@ -3275,8 +3276,10 @@ var
|
|||||||
FileInfo: TSearchRec;
|
FileInfo: TSearchRec;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
|
//DebugLn('SearchDirectory ADirectory="',ADirectory,'"');
|
||||||
if DirectoryAlreadySearched(ADirectory) then exit;
|
if DirectoryAlreadySearched(ADirectory) then exit;
|
||||||
MarkDirectoryAsSearched(ADirectory);
|
MarkDirectoryAsSearched(ADirectory);
|
||||||
|
//DebugLn('SearchDirectory searching ...');
|
||||||
|
|
||||||
if not DirPathExists(ADirectory) then exit;
|
if not DirPathExists(ADirectory) then exit;
|
||||||
if SysUtils.FindFirst(ADirectory+FileMask,faAnyFile,FileInfo)=0 then begin
|
if SysUtils.FindFirst(ADirectory+FileMask,faAnyFile,FileInfo)=0 then begin
|
||||||
@ -3286,7 +3289,7 @@ var
|
|||||||
then
|
then
|
||||||
continue;
|
continue;
|
||||||
if ExtensionFits(FileInfo.Name) then begin
|
if ExtensionFits(FileInfo.Name) then begin
|
||||||
AddFilename(FileInfo.Name);
|
AddFilename(ADirectory+FileInfo.Name);
|
||||||
end;
|
end;
|
||||||
until SysUtils.FindNext(FileInfo)<>0;
|
until SysUtils.FindNext(FileInfo)<>0;
|
||||||
end;
|
end;
|
||||||
@ -3329,19 +3332,20 @@ end;
|
|||||||
procedure FreeTreeOfUnitFiles(TreeOfUnitFiles: TAVLTree);
|
procedure FreeTreeOfUnitFiles(TreeOfUnitFiles: TAVLTree);
|
||||||
begin
|
begin
|
||||||
TreeOfUnitFiles.FreeAndClear;
|
TreeOfUnitFiles.FreeAndClear;
|
||||||
|
TreeOfUnitFiles.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareUnitFileInfos(Data1, Data2: Pointer): integer;
|
function CompareUnitFileInfos(Data1, Data2: Pointer): integer;
|
||||||
begin
|
begin
|
||||||
Result:=SysUtils.CompareText(TUnitFileInfo(Data1).UnitName,
|
Result:=CompareIdentifiers(PChar(TUnitFileInfo(Data1).UnitName),
|
||||||
TUnitFileInfo(Data2).UnitName);
|
PChar(TUnitFileInfo(Data2).UnitName));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CompareUnitNameAndUnitFileInfo(UnitnamePAnsiString,
|
function CompareUnitNameAndUnitFileInfo(UnitnamePAnsiString,
|
||||||
UnitFileInfo: Pointer): integer;
|
UnitFileInfo: Pointer): integer;
|
||||||
begin
|
begin
|
||||||
Result:=SysUtils.CompareText(PAnsiString(UnitnamePAnsiString)^,
|
Result:=CompareIdentifiers(PChar(UnitnamePAnsiString),
|
||||||
TUnitFileInfo(UnitFileInfo).UnitName);
|
PChar(TUnitFileInfo(UnitFileInfo).UnitName));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure RaiseCatchableException(const Msg: string);
|
procedure RaiseCatchableException(const Msg: string);
|
||||||
|
|||||||
@ -942,8 +942,48 @@ end;
|
|||||||
|
|
||||||
procedure TIdentCompletionTool.GatherUnitnames(CleanPos: integer;
|
procedure TIdentCompletionTool.GatherUnitnames(CleanPos: integer;
|
||||||
const Context: TFindContext; BeautifyCodeOptions: TBeautifyCodeOptions);
|
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
|
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;
|
end;
|
||||||
|
|
||||||
function TIdentCompletionTool.GatherIdentifiers(
|
function TIdentCompletionTool.GatherIdentifiers(
|
||||||
|
|||||||
@ -46,6 +46,8 @@ type
|
|||||||
{ TPascalReaderTool }
|
{ TPascalReaderTool }
|
||||||
|
|
||||||
TPascalReaderTool = class(TPascalParserTool)
|
TPascalReaderTool = class(TPascalParserTool)
|
||||||
|
protected
|
||||||
|
CachedSourceName: string;
|
||||||
public
|
public
|
||||||
function FindDeepestExpandedNodeAtPos(CleanCursorPos: integer;
|
function FindDeepestExpandedNodeAtPos(CleanCursorPos: integer;
|
||||||
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
ExceptionOnNotFound: boolean): TCodeTreeNode;
|
||||||
@ -140,6 +142,7 @@ type
|
|||||||
): boolean;
|
): boolean;
|
||||||
|
|
||||||
// sections
|
// sections
|
||||||
|
function GetSourceName: string;
|
||||||
function GetSourceType: TCodeTreeNodeDesc;
|
function GetSourceType: TCodeTreeNodeDesc;
|
||||||
function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
|
function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
|
||||||
function ExtractSourceName: string;
|
function ExtractSourceName: string;
|
||||||
@ -1426,6 +1429,16 @@ begin
|
|||||||
Result:=UpAtomIs('CONST') or UpAtomIs('VAR') or UpAtomIs('OUT');
|
Result:=UpAtomIs('CONST') or UpAtomIs('VAR') or UpAtomIs('OUT');
|
||||||
end;
|
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
|
function TPascalReaderTool.PropertyIsDefault(PropertyNode: TCodeTreeNode
|
||||||
): boolean;
|
): boolean;
|
||||||
begin
|
begin
|
||||||
|
|||||||
@ -65,7 +65,6 @@ type
|
|||||||
|
|
||||||
TStandardCodeTool = class(TIdentCompletionTool)
|
TStandardCodeTool = class(TIdentCompletionTool)
|
||||||
private
|
private
|
||||||
CachedSourceName: string;
|
|
||||||
function ReadTilGuessedUnclosedBlock(MinCleanPos: integer;
|
function ReadTilGuessedUnclosedBlock(MinCleanPos: integer;
|
||||||
ReadOnlyOneBlock: boolean): boolean;
|
ReadOnlyOneBlock: boolean): boolean;
|
||||||
function ReadForwardTilAnyBracketClose: boolean;
|
function ReadForwardTilAnyBracketClose: boolean;
|
||||||
@ -75,7 +74,6 @@ type
|
|||||||
function Explore(WithStatements: boolean): boolean;
|
function Explore(WithStatements: boolean): boolean;
|
||||||
|
|
||||||
// source name e.g. 'unit UnitName;'
|
// source name e.g. 'unit UnitName;'
|
||||||
function GetSourceName: string;
|
|
||||||
function GetCachedSourceName: string;
|
function GetCachedSourceName: string;
|
||||||
function RenameSource(const NewName: string;
|
function RenameSource(const NewName: string;
|
||||||
SourceChangeCache: TSourceChangeCache): boolean;
|
SourceChangeCache: TSourceChangeCache): boolean;
|
||||||
@ -309,16 +307,6 @@ end;
|
|||||||
|
|
||||||
{ TStandardCodeTool }
|
{ 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;
|
function TStandardCodeTool.GetCachedSourceName: string;
|
||||||
Params: none
|
Params: none
|
||||||
|
|||||||
@ -177,6 +177,12 @@ begin
|
|||||||
s:='enum';
|
s:='enum';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
ctnUnit:
|
||||||
|
begin
|
||||||
|
AColor:=clBlack;
|
||||||
|
s:='unit';
|
||||||
|
end;
|
||||||
|
|
||||||
else
|
else
|
||||||
AColor:=clGray;
|
AColor:=clGray;
|
||||||
s:='';
|
s:='';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user