mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 22:19:18 +02:00
codetools: improved error message on unit not found
git-svn-id: trunk@37265 -
This commit is contained in:
parent
aa7b1efed9
commit
bb32bf4cdb
@ -694,12 +694,6 @@ type
|
|||||||
function FindNonForwardClass(Params: TFindDeclarationParams): boolean;
|
function FindNonForwardClass(Params: TFindDeclarationParams): boolean;
|
||||||
function FindCodeToolForUsedUnit(const AnUnitName, AnUnitInFilename: string;
|
function FindCodeToolForUsedUnit(const AnUnitName, AnUnitInFilename: string;
|
||||||
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
||||||
function FindUnitSourceWithUnitIdentifier(UsesNode: TCodeTreeNode;
|
|
||||||
const AnUnitIdentifier: string; ExceptionOnNotFound: boolean
|
|
||||||
): TCodeBuffer; // ToDo: dotted
|
|
||||||
function FindCodeToolForUnitIdentifier(UsesNode: TCodeTreeNode;
|
|
||||||
const AnUnitIdentifier: string; ExceptionOnNotFound: boolean
|
|
||||||
): TFindDeclarationTool; // ToDo: dotted
|
|
||||||
function FindIdentifierInInterface(AskingTool: TFindDeclarationTool;
|
function FindIdentifierInInterface(AskingTool: TFindDeclarationTool;
|
||||||
Params: TFindDeclarationParams): boolean;
|
Params: TFindDeclarationParams): boolean;
|
||||||
function CompareNodeIdentifier(Node: TCodeTreeNode;
|
function CompareNodeIdentifier(Node: TCodeTreeNode;
|
||||||
@ -780,7 +774,8 @@ type
|
|||||||
function IsHiddenUsedUnit(TheUnitName: PChar): boolean;
|
function IsHiddenUsedUnit(TheUnitName: PChar): boolean;
|
||||||
|
|
||||||
function FindUnitSource(const AnUnitName,
|
function FindUnitSource(const AnUnitName,
|
||||||
AnUnitInFilename: string; ExceptionOnNotFound: boolean): TCodeBuffer;
|
AnUnitInFilename: string; ExceptionOnNotFound: boolean;
|
||||||
|
ErrorPos: integer = 0): TCodeBuffer;
|
||||||
function FindUnitCaseInsensitive(var AnUnitName,
|
function FindUnitCaseInsensitive(var AnUnitName,
|
||||||
AnUnitInFilename: string): string;
|
AnUnitInFilename: string): string;
|
||||||
procedure GatherUnitAndSrcPath(var UnitPath, CompleteSrcPath: string);
|
procedure GatherUnitAndSrcPath(var UnitPath, CompleteSrcPath: string);
|
||||||
@ -2000,7 +1995,7 @@ begin
|
|||||||
MoveCursorToCleanPos(UnitNamePos.StartPos);
|
MoveCursorToCleanPos(UnitNamePos.StartPos);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
AUnitName:=ExtractUsedUnitNameAtCursor(@UnitInFilename);
|
AUnitName:=ExtractUsedUnitNameAtCursor(@UnitInFilename);
|
||||||
NewPos.Code:=FindUnitSource(AUnitName,UnitInFilename,true);
|
NewPos.Code:=FindUnitSource(AUnitName,UnitInFilename,true,UnitNamePos.StartPos);
|
||||||
NewPos.X:=1;
|
NewPos.X:=1;
|
||||||
NewPos.Y:=1;
|
NewPos.Y:=1;
|
||||||
NewTopLine:=1;
|
NewTopLine:=1;
|
||||||
@ -2042,7 +2037,7 @@ var
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
// search in search paths
|
// search in search paths
|
||||||
Code:=FindUnitSource(AUnitName,UnitInFilename,false);
|
Code:=FindUnitSource(AUnitName,UnitInFilename,false,Node.StartPos);
|
||||||
Result:=(Code<>nil) and (CompareFilenames(Code.Filename,AFilename)=0);
|
Result:=(Code<>nil) and (CompareFilenames(Code.Filename,AFilename)=0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2076,7 +2071,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindUnitSource(const AnUnitName,
|
function TFindDeclarationTool.FindUnitSource(const AnUnitName,
|
||||||
AnUnitInFilename: string; ExceptionOnNotFound: boolean): TCodeBuffer;
|
AnUnitInFilename: string; ExceptionOnNotFound: boolean; ErrorPos: integer
|
||||||
|
): TCodeBuffer;
|
||||||
var
|
var
|
||||||
CompiledFilename: string;
|
CompiledFilename: string;
|
||||||
AFilename: String;
|
AFilename: String;
|
||||||
@ -2118,6 +2114,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
if (Result=nil) and ExceptionOnNotFound then begin
|
if (Result=nil) and ExceptionOnNotFound then begin
|
||||||
|
if ErrorPos>0 then
|
||||||
|
MoveCursorToCleanPos(ErrorPos)
|
||||||
|
else
|
||||||
|
CurPos.StartPos:=-1;
|
||||||
if CompiledFilename<>'' then begin
|
if CompiledFilename<>'' then begin
|
||||||
// there is a compiled unit, only the source was not found
|
// there is a compiled unit, only the source was not found
|
||||||
RaiseExceptionInstance(
|
RaiseExceptionInstance(
|
||||||
@ -3544,11 +3544,13 @@ var
|
|||||||
out IsPredefined: boolean; var Context: TFindContext);
|
out IsPredefined: boolean; var Context: TFindContext);
|
||||||
var
|
var
|
||||||
TypeFound: Boolean;
|
TypeFound: Boolean;
|
||||||
NameNode: TCodeTreeNode;
|
|
||||||
TestContext: TFindContext;
|
TestContext: TFindContext;
|
||||||
IdentStart: LongInt;
|
IdentStart: LongInt;
|
||||||
SubParams: TFindDeclarationParams;
|
SubParams: TFindDeclarationParams;
|
||||||
aNode: TCodeTreeNode;
|
aNode: TCodeTreeNode;
|
||||||
|
AnUnitIdentifier: String;
|
||||||
|
UnitInFilename: AnsiString;
|
||||||
|
NewCode: TCodeBuffer;
|
||||||
begin
|
begin
|
||||||
IsPredefined:=false;
|
IsPredefined:=false;
|
||||||
SubParams:=TFindDeclarationParams.Create;
|
SubParams:=TFindDeclarationParams.Create;
|
||||||
@ -3573,16 +3575,22 @@ var
|
|||||||
// skip search in proc parameters
|
// skip search in proc parameters
|
||||||
SubParams.ContextNode:=SubParams.ContextNode.Parent;
|
SubParams.ContextNode:=SubParams.ContextNode.Parent;
|
||||||
TypeFound:=FindIdentifierInContext(SubParams);
|
TypeFound:=FindIdentifierInContext(SubParams);
|
||||||
if TypeFound and (SubParams.NewNode.Desc in [ctnUseUnit,ctnUsesSection])
|
if TypeFound and (SubParams.NewNode.Desc=ctnUseUnit)
|
||||||
and (SubParams.NewCodeTool=Self)
|
and (SubParams.NewCodeTool=Self)
|
||||||
then begin
|
then begin
|
||||||
NameNode:=SubParams.NewNode;
|
|
||||||
SubParams.NewNode:=nil;
|
|
||||||
{$IFDEF ShowTriedBaseContexts}
|
{$IFDEF ShowTriedBaseContexts}
|
||||||
debugln(['TFindDeclarationTool.FindBaseTypeOfNode.SearchIdentifier is a unit, getting tool...']);
|
debugln(['TFindDeclarationTool.FindBaseTypeOfNode.SearchIdentifier is an entry in the uses section, getting tool...']);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
SubParams.NewCodeTool:=FindCodeToolForUnitIdentifier(
|
AnUnitIdentifier:=ExtractUsedUnitName(SubParams.NewNode,@UnitInFilename);
|
||||||
NameNode,GetIdentifier(@Src[IdentStart]),true);
|
NewCode:=FindUnitSource(AnUnitIdentifier,UnitInFilename,true,SubParams.NewNode.StartPos);
|
||||||
|
if Assigned(FOnGetCodeToolForBuffer) then
|
||||||
|
SubParams.NewCodeTool:=FOnGetCodeToolForBuffer(Self,NewCode,false)
|
||||||
|
else if NewCode=TCodeBuffer(Scanner.MainCode) then
|
||||||
|
SubParams.NewCodeTool:=Self;
|
||||||
|
if (SubParams.NewCodeTool=nil) then begin
|
||||||
|
CurPos.StartPos:=-1;
|
||||||
|
RaiseException(Format('Unable to create codetool for "%s"',[NewCode.Filename]));
|
||||||
|
end;
|
||||||
SubParams.NewCodeTool.BuildTree(lsrImplementationStart);
|
SubParams.NewCodeTool.BuildTree(lsrImplementationStart);
|
||||||
SubParams.NewNode:=SubParams.NewCodeTool.Tree.Root;
|
SubParams.NewNode:=SubParams.NewCodeTool.Tree.Root;
|
||||||
end;
|
end;
|
||||||
@ -6170,92 +6178,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TFindDeclarationTool.FindUnitSourceWithUnitIdentifier(
|
|
||||||
UsesNode: TCodeTreeNode; const AnUnitIdentifier: string;
|
|
||||||
ExceptionOnNotFound: boolean): TCodeBuffer;
|
|
||||||
|
|
||||||
procedure RaiseUnitNotFound;
|
|
||||||
begin
|
|
||||||
CurPos.StartPos:=-1;
|
|
||||||
RaiseExceptionInstance(
|
|
||||||
ECodeToolUnitNotFound.Create(Self,Format(ctsUnitNotFound,[AnUnitIdentifier]),
|
|
||||||
AnUnitIdentifier));
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
UnitNamePos: TAtomPosition;
|
|
||||||
UnitInFilePos: TAtomPosition;
|
|
||||||
UnitInFilename: String;
|
|
||||||
begin
|
|
||||||
Result:=nil;
|
|
||||||
{$IFDEF ShowTriedContexts}
|
|
||||||
DebugLn('TFindDeclarationTool.FindUnitSourceWithUnitIdentifier A');
|
|
||||||
{$ENDIF}
|
|
||||||
{$IFDEF CheckNodeTool}CheckNodeTool(UsesNode);{$ENDIF}
|
|
||||||
// reparse uses section
|
|
||||||
MoveCursorToNodeStart(UsesNode);
|
|
||||||
if (UsesNode.Desc=ctnUsesSection) then begin
|
|
||||||
ReadNextAtom;
|
|
||||||
if not UpAtomIs('USES') then
|
|
||||||
RaiseUsesExpected;
|
|
||||||
end;
|
|
||||||
repeat
|
|
||||||
ReadNextAtom; // read name
|
|
||||||
if AtomIsChar(';') then break;
|
|
||||||
AtomIsIdentifierE;
|
|
||||||
UnitNamePos:=CurPos;
|
|
||||||
ReadNextAtom;
|
|
||||||
if UpAtomIs('IN') then begin
|
|
||||||
ReadNextAtom;
|
|
||||||
if not AtomIsStringConstant then RaiseStrConstExpected;
|
|
||||||
UnitInFilePos:=CurPos;
|
|
||||||
ReadNextAtom;
|
|
||||||
end else
|
|
||||||
UnitInFilePos.StartPos:=-1;
|
|
||||||
if CompareIdentifierPtrs(@Src[UnitNamePos.StartPos],
|
|
||||||
PChar(Pointer(AnUnitIdentifier)))=0
|
|
||||||
then begin
|
|
||||||
// cursor is on a AUnitName -> try to locate it
|
|
||||||
if UnitInFilePos.StartPos>=1 then begin
|
|
||||||
UnitInFilename:=copy(Src,UnitInFilePos.StartPos+1,
|
|
||||||
UnitInFilePos.EndPos-UnitInFilePos.StartPos-2)
|
|
||||||
end else
|
|
||||||
UnitInFilename:='';
|
|
||||||
Result:=FindUnitSource(AnUnitIdentifier,UnitInFilename,true);
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
if AtomIsChar(';') then break;
|
|
||||||
if not AtomIsChar(',') then
|
|
||||||
RaiseExceptionFmt(ctsStrExpectedButAtomFound,[';',GetAtom])
|
|
||||||
until (CurPos.StartPos>SrcLen);
|
|
||||||
{$IFDEF ShowTriedContexts}
|
|
||||||
DebugLn('TFindDeclarationTool.FindUnitSourceWithUnitIdentifier END identifier not found in uses section');
|
|
||||||
{$ENDIF}
|
|
||||||
if ExceptionOnNotFound then
|
|
||||||
RaiseUnitNotFound;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TFindDeclarationTool.FindCodeToolForUnitIdentifier(
|
|
||||||
UsesNode: TCodeTreeNode; const AnUnitIdentifier: string;
|
|
||||||
ExceptionOnNotFound: boolean): TFindDeclarationTool;
|
|
||||||
var
|
|
||||||
NewCode: TCodeBuffer;
|
|
||||||
begin
|
|
||||||
Result:=nil;
|
|
||||||
NewCode:=FindUnitSourceWithUnitIdentifier(UsesNode,AnUnitIdentifier,
|
|
||||||
ExceptionOnNotFound);
|
|
||||||
if NewCode=nil then
|
|
||||||
exit;
|
|
||||||
if Assigned(FOnGetCodeToolForBuffer) then
|
|
||||||
Result:=FOnGetCodeToolForBuffer(Self,NewCode,false)
|
|
||||||
else if NewCode=TCodeBuffer(Scanner.MainCode) then
|
|
||||||
Result:=Self;
|
|
||||||
if (Result=nil) and ExceptionOnNotFound then begin
|
|
||||||
CurPos.StartPos:=-1;
|
|
||||||
RaiseException(Format('Unable to create codetool for "%s"',[NewCode.Filename]));
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TFindDeclarationTool.FindIdentifierInInterface(
|
function TFindDeclarationTool.FindIdentifierInInterface(
|
||||||
AskingTool: TFindDeclarationTool; Params: TFindDeclarationParams): boolean;
|
AskingTool: TFindDeclarationTool; Params: TFindDeclarationParams): boolean;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user