codetools: identifier completion: fixed search in type of var/const

git-svn-id: trunk@29418 -
This commit is contained in:
mattias 2011-02-07 22:55:37 +00:00
parent 91f5747254
commit 602515e7d2
5 changed files with 19 additions and 6 deletions

View File

@ -91,8 +91,8 @@ begin
Filename:=CleanAndExpandFilename(ParamStr(1));
X:=StrToInt(ParamStr(2));
Y:=StrToInt(ParamStr(3));
writeln('File: ',Filename,' Line=',Y,' Column=',X);
end;
writeln('File: ',Filename,' Line=',Y,' Column=',X);
// Step 1: load the file
Code:=CodeToolBoss.LoadFile(Filename,false,false);

View File

@ -40,6 +40,7 @@ var
Y: Integer;
Cnt: longint;
i: Integer;
Line: String;
begin
if (ParamCount>=1) and (Paramcount<3) then begin
writeln('Usage:');
@ -59,6 +60,7 @@ begin
Filename:=ExpandFileName(ParamStr(1));
X:=StrToInt(ParamStr(2));
Y:=StrToInt(ParamStr(3));
writeln('File: ',Filename,' Line=',Y,' Column=',X);
end;
// load the file
@ -71,6 +73,8 @@ begin
// gather identifiers:
writeln('GatherIdentifiers ',Code.Filename,'(X=',X,',Y=',Y,')');
Line:=Code.GetLine(Y-1);
writeln('Line ',Y,': ',copy(Line,1,X-1),'|',copy(Line,X,length(Line)));
if CodeToolBoss.GatherIdentifiers(Code,X,Y) then
begin
writeln('Identifiers found: Count=',CodeToolBoss.IdentifierList.Count,' FilteredCount=',CodeToolBoss.IdentifierList.GetFilteredCount);
@ -79,7 +83,10 @@ begin
for i:=0 to Cnt-1 do
writeln(i,'/',CodeToolBoss.IdentifierList.GetFilteredCount,': ',CodeToolBoss.IdentifierList.FilteredItems[i].AsString);
end else begin
raise Exception.Create('GatherIdentifiers failed');
if CodeToolBoss.ErrorMessage<>'' then
writeln('Parse error: ',CodeToolBoss.ErrorMessage)
else
writeln('Error: no context');
end;
end.

View File

@ -14,7 +14,7 @@ type
function DoSomething(Arg: T): T;
end;
TGenericClass<T1,T2> = class(TInterfacedObject, IGenericInterface<T1>)
F: T2;
F: T21;
type
Intf = IGenericInterface<Integer>;
function DoSomething(Arg: T1): T2;

View File

@ -1509,6 +1509,7 @@ begin
// ToDo: DirtySrc
Result:=FindDeclarationOfIdentAtParam(Params);
end else begin
debugln(['TFindDeclarationTool.FindDeclaration AAA1']);
Include(Params.Flags,fdfIgnoreCurContextNode);
if SearchForward then
Include(Params.Flags,fdfSearchForward);
@ -6012,7 +6013,7 @@ var
OldInput: TFindDeclarationInput;
begin
Result:=false;
//debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ',VarConstNode.DescAsString]);
debugln(['TFindDeclarationTool.FindIdentifierInTypeOfConstant ',VarConstNode.DescAsString]);
TypeNode:=VarConstNode.FirstChild;
if TypeNode=nil then exit;
if TypeNode.Desc=ctnIdentifier then begin

View File

@ -1795,7 +1795,7 @@ begin
GatherContext:=CreateFindContext(Self,CursorNode);
IgnoreCurContext:=false;
//DebugLn(['TIdentCompletionTool.FindCollectionContext IdentStartPos=',dbgstr(copy(Src,IdentStartPos,20))]);
//DebugLn(['TIdentCompletionTool.FindCollectionContext IdentStartPos=',dbgstr(copy(Src,IdentStartPos,20)),' ',CursorNode.DescAsString]);
ContextExprStartPos:=GetContextExprStartPos(IdentStartPos,CursorNode);
if GatherContext.Node.Desc=ctnWithVariable then begin
if GatherContext.Node.PriorBrother<>nil then
@ -1809,10 +1809,12 @@ begin
GatherContext.Node:=GatherContext.Node.Parent;
GatherContext.Node:=GatherContext.Node.Parent;
IgnoreCurContext:=true;
end else if GatherContext.Node.Desc=ctnIdentifier then begin
IgnoreCurContext:=true;
end;
StartInSubContext:=false;
//DebugLn(['TIdentCompletionTool.FindCollectionContext ContextExprStartPos=',ContextExprStartPos,' "',dbgstr(copy(Src,ContextExprStartPos,20)),'" IdentStartPos="',dbgstr(copy(Src,IdentStartPos,20)),'"']);
//DebugLn(['TIdentCompletionTool.FindCollectionContext ContextExprStartPos=',ContextExprStartPos,' "',dbgstr(copy(Src,ContextExprStartPos,20)),'" IdentStartPos="',dbgstr(copy(Src,IdentStartPos,20)),'" Gather=',FindContextToString(GatherContext)]);
if ContextExprStartPos<IdentStartPos then begin
MoveCursorToCleanPos(IdentStartPos);
Params.ContextNode:=CursorNode;
@ -1821,6 +1823,7 @@ begin
fdfSearchInParentNodes,fdfSearchInAncestors];
if IgnoreCurContext then
Params.Flags:=Params.Flags+[fdfIgnoreCurContextNode];
debugln(['TIdentCompletionTool.FindCollectionContext ',fdfIgnoreCurContextNode in Params.Flags]);
ExprType:=FindExpressionTypeOfTerm(ContextExprStartPos,IdentStartPos,
Params,false);
//DebugLn(['TIdentCompletionTool.FindCollectionContext ',ExprTypeToString(ExprType)]);
@ -2048,6 +2051,8 @@ begin
DebugLn('TIdentCompletionTool.GatherIdentifiers F');
{$ENDIF}
CurrentIdentifierList.Context:=GatherContext;
if GatherContext.Node.Desc=ctnIdentifier then
Params.Flags:=Params.Flags+[fdfIgnoreCurContextNode];
GatherContext.Tool.FindIdentifierInContext(Params);
end;