mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 16:40:48 +02:00
identifier completion: improved heuristic to recognize LValue
git-svn-id: trunk@9292 -
This commit is contained in:
parent
1dc696deef
commit
a3cbfca3a5
@ -6247,13 +6247,6 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{if (fdfCollect in params.Flags)
|
|
||||||
and (FoundContext.Node.Parent<>nil)
|
|
||||||
and (FoundContext.Node.Parent.Desc in AllClassSections)
|
|
||||||
and () then begin
|
|
||||||
|
|
||||||
end;}
|
|
||||||
|
|
||||||
Result:=ifrProceedSearch;
|
Result:=ifrProceedSearch;
|
||||||
if (Params.FoundProc=nil) then begin
|
if (Params.FoundProc=nil) then begin
|
||||||
// this is the first proc found
|
// this is the first proc found
|
||||||
|
@ -120,9 +120,9 @@ type
|
|||||||
TIdentifierListFlags = set of TIdentifierListFlag;
|
TIdentifierListFlags = set of TIdentifierListFlag;
|
||||||
|
|
||||||
TIdentifierListContextFlag = (
|
TIdentifierListContextFlag = (
|
||||||
ilcfStartInStatement,
|
ilcfStartInStatement, // context starts in statements. e.g. between begin..end
|
||||||
ilcfStartIsLValue,
|
ilcfStartIsLValue, // position is start of one statement. e.g. 'A:='
|
||||||
ilcfContextNeedsEndSemicolon
|
ilcfNeedsEndSemicolon // after context a semicolon is needed. e.g. 'A end'
|
||||||
);
|
);
|
||||||
TIdentifierListContextFlags = set of TIdentifierListContextFlag;
|
TIdentifierListContextFlags = set of TIdentifierListContextFlag;
|
||||||
|
|
||||||
@ -1117,6 +1117,7 @@ var
|
|||||||
ExprType: TExpressionType;
|
ExprType: TExpressionType;
|
||||||
ContextExprStartPos: Integer;
|
ContextExprStartPos: Integer;
|
||||||
StartInSubContext: Boolean;
|
StartInSubContext: Boolean;
|
||||||
|
StartPosOfVariable: LongInt;
|
||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if IdentifierList=nil then IdentifierList:=TIdentifierList.Create;
|
if IdentifierList=nil then IdentifierList:=TIdentifierList.Create;
|
||||||
@ -1216,44 +1217,56 @@ begin
|
|||||||
GatherUsefulIdentifiers(IdentStartPos,GatherContext,BeautifyCodeOptions);
|
GatherUsefulIdentifiers(IdentStartPos,GatherContext,BeautifyCodeOptions);
|
||||||
|
|
||||||
// check for incomplete context
|
// check for incomplete context
|
||||||
|
|
||||||
// context bracket level
|
// context bracket level
|
||||||
CurrentIdentifierList.StartBracketLvl:=
|
CurrentIdentifierList.StartBracketLvl:=
|
||||||
GetBracketLvl(Src,CursorNode.StartPos,IdentStartPos,
|
GetBracketLvl(Src,CursorNode.StartPos,IdentStartPos,
|
||||||
Scanner.NestedComments);
|
Scanner.NestedComments);
|
||||||
|
if CursorNode.Desc in AllPascalStatements then begin
|
||||||
|
CurrentIdentifierList.ContextFlags:=
|
||||||
|
CurrentIdentifierList.ContextFlags+[ilcfStartInStatement];
|
||||||
|
end;
|
||||||
|
// context in front of
|
||||||
|
StartPosOfVariable:=FindStartOfVariable(IdentStartPos);
|
||||||
|
if StartPosOfVariable>0 then begin
|
||||||
|
MoveCursorToCleanPos(StartPosOfVariable);
|
||||||
|
ReadPriorAtom;
|
||||||
|
CurrentIdentifierList.StartAtomInFront:=CurPos;
|
||||||
|
// check if LValue
|
||||||
|
if (ilcfStartInStatement in CurrentIdentifierList.ContextFlags) then
|
||||||
|
begin
|
||||||
|
if (CurPos.Flag in [cafSemicolon,cafBegin,cafEnd])
|
||||||
|
or WordIsBlockKeyWord.DoItUpperCase(UpperSrc,
|
||||||
|
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos)
|
||||||
|
then begin
|
||||||
|
CurrentIdentifierList.ContextFlags:=
|
||||||
|
CurrentIdentifierList.ContextFlags+[ilcfStartIsLValue];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
// context behind
|
// context behind
|
||||||
if IdentEndPos<SrcLen then begin
|
if IdentEndPos<SrcLen then begin
|
||||||
MoveCursorToCleanPos(IdentEndPos);
|
MoveCursorToCleanPos(IdentEndPos);
|
||||||
ReadNextAtom;
|
ReadNextAtom;
|
||||||
CurrentIdentifierList.StartAtomBehind:=CurPos;
|
CurrentIdentifierList.StartAtomBehind:=CurPos;
|
||||||
// check if in statement
|
// check if in statement
|
||||||
if CursorNode.Desc in AllPascalStatements then begin
|
if (ilcfStartInStatement in CurrentIdentifierList.ContextFlags) then
|
||||||
CurrentIdentifierList.ContextFlags:=
|
begin
|
||||||
CurrentIdentifierList.ContextFlags+[ilcfStartInStatement];
|
if (CurrentIdentifierList.StartBracketLvl=0) then begin
|
||||||
// check if at end of statement
|
// check if end needs semicolon
|
||||||
if (CurPos.Flag in [cafEnd,cafBegin])
|
if (CurPos.Flag in [cafEnd,cafBegin])
|
||||||
or ((not UpAtomIs('ELSE'))
|
|
||||||
and (CurPos.Flag=cafWord)
|
|
||||||
and (not PositionsInSameLine(Src,IdentEndPos,CurPos.StartPos)))
|
|
||||||
then
|
|
||||||
if CurrentIdentifierList.StartBracketLvl=0 then begin
|
|
||||||
// TODO: improve heuristic to add semicolon
|
|
||||||
//CurrentIdentifierList.ContextFlags:=
|
|
||||||
// CurrentIdentifierList.ContextFlags+[ilcfContextNeedsEndSemicolon];
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
// context in front of
|
|
||||||
MoveCursorToCleanPos(IdentStartPos);
|
|
||||||
ReadPriorAtom;
|
|
||||||
CurrentIdentifierList.StartAtomInFront:=CurPos;
|
|
||||||
// check if LValue
|
|
||||||
if (ilcfStartInStatement in CurrentIdentifierList.ContextFlags) then begin
|
|
||||||
if (CurPos.Flag in [cafSemicolon,cafBegin,cafEnd])
|
|
||||||
or WordIsBlockKeyWord.DoItUpperCase(UpperSrc,
|
or WordIsBlockKeyWord.DoItUpperCase(UpperSrc,
|
||||||
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos)
|
CurPos.StartPos,CurPos.EndPos-CurPos.StartPos)
|
||||||
then
|
or ((CurPos.Flag=cafWord)
|
||||||
|
and (not UpAtomIs('ELSE'))
|
||||||
|
and (not PositionsInSameLine(Src,IdentEndPos,CurPos.StartPos)))
|
||||||
|
then begin
|
||||||
|
// add semicolon
|
||||||
CurrentIdentifierList.ContextFlags:=
|
CurrentIdentifierList.ContextFlags:=
|
||||||
CurrentIdentifierList.ContextFlags+[ilcfStartIsLValue];
|
CurrentIdentifierList.ContextFlags+[ilcfNeedsEndSemicolon];
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -381,8 +381,9 @@ begin
|
|||||||
Result:=Result+AddChar;
|
Result:=Result+AddChar;
|
||||||
|
|
||||||
// add semicolon for statement ends
|
// add semicolon for statement ends
|
||||||
if (ilcfContextNeedsEndSemicolon in IdentList.ContextFlags) then begin
|
if (ilcfNeedsEndSemicolon in IdentList.ContextFlags) then begin
|
||||||
Result:=Result+';';
|
Result:=Result+';';
|
||||||
|
DebugLn('GetIdentCompletionValue ilcfStartIsLValue in IdentList.ContextFlags=',dbgs(ilcfStartIsLValue in IdentList.ContextFlags));
|
||||||
if (not CursorAtEnd) or IdentItem.HasChilds
|
if (not CursorAtEnd) or IdentItem.HasChilds
|
||||||
or (ilcfStartIsLValue in IdentList.ContextFlags) then
|
or (ilcfStartIsLValue in IdentList.ContextFlags) then
|
||||||
inc(CursorToLeft);
|
inc(CursorToLeft);
|
||||||
|
Loading…
Reference in New Issue
Block a user