codecompletion: forward proc body position now block sensitive

git-svn-id: trunk@4877 -
This commit is contained in:
mattias 2003-12-06 19:20:46 +00:00
parent 9ef4196e0f
commit 77694e4aa0
7 changed files with 178 additions and 49 deletions

View File

@ -53,7 +53,7 @@ function FindNextIDEDirective(const ASource: string; StartPos: integer;
function CleanCodeFromComments(const DirtyCode: string;
NestedComments: boolean): string;
// line ranges and indent
// indent
procedure GetLineStartEndAtPosition(const Source:string; Position:integer;
var LineStart,LineEnd:integer);
function GetLineIndent(const Source: string; Position: integer): integer;
@ -62,10 +62,6 @@ function GetBlockMinIndent(const Source: string;
function GetIndentStr(Indent: integer): string;
procedure IndentText(const Source: string; Indent, TabWidth: integer;
var NewSource: string);
function LineEndCount(const Txt: string): integer;
function LineEndCount(const Txt: string; var LengthOfLastLine:integer): integer;
function PositionsInSameLine(const Source: string;
Pos1, Pos2: integer): boolean;
// identifiers
procedure GetIdentStartEndAtPosition(const Source:string; Position:integer;
@ -76,6 +72,12 @@ function FindNextIdentifier(const Source: string; StartPos, MaxPos: integer
): integer;
// line/code ends
function LineEndCount(const Txt: string): integer;
function LineEndCount(const Txt: string; var LengthOfLastLine:integer): integer;
function EmptyCodeLineCount(const Source: string; StartPos, EndPos: integer;
NestedComments: boolean): integer;
function PositionsInSameLine(const Source: string;
Pos1, Pos2: integer): boolean;
function FindFirstNonSpaceCharInLine(const Source: string;
Position: integer): integer;
function FindLineEndOrCodeInFrontOfPosition(const Source: string;
@ -1167,6 +1169,87 @@ begin
inc(LineEnd);
end;
function EmptyCodeLineCount(const Source: string; StartPos, EndPos: integer;
NestedComments: boolean): integer;
{ search forward for a line end or code
ignore line ends in comments
Result is Position of Start of Line End
}
var SrcLen: integer;
SrcPos: Integer;
procedure ReadComment(var P: integer);
begin
case Source[P] of
'{':
begin
inc(P);
while (P<=SrcLen) and (Source[P]<>'}') do begin
if NestedComments and (Source[P] in ['{','(','/']) then
ReadComment(P)
else
inc(P);
end;
inc(P);
end;
'(':
begin
inc(P);
if (P<=SrcLen) and (Source[P]='*') then begin
inc(P);
while (P<=SrcLen-1)
and ((Source[P]<>'*') or (Source[P-1]<>')')) do begin
if NestedComments and (Source[P] in ['{','(','/']) then
ReadComment(P)
else
inc(P);
end;
inc(P,2);
end;
end;
'/':
begin
inc(P);
if (P<=SrcLen) and (Source[P]='/') then begin
inc(P);
while (P<=SrcLen)
and (not (Source[P] in [#10,#13])) do begin
if NestedComments and (Source[P] in ['{','(','/']) then
ReadComment(P)
else
inc(P);
end;
end;
end;
end;
end;
begin
Result:=0;
SrcLen:=length(Source);
if EndPos>SrcLen then EndPos:=SrcLen+1;
SrcPos:=StartPos;
while (SrcPos<EndPos) do begin
case Source[SrcPos] of
'{','(','/':
ReadComment(SrcPos);
#10,#13:
begin
// skip line end
inc(SrcPos);
if (SrcPos<EndPos) and (Source[SrcPos] in [#10,#13])
and (Source[SrcPos]<>Source[SrcPos-1]) then
inc(SrcPos);
// count empty lines
if (SrcPos<EndPos) and (Source[SrcPos] in [#10,#13]) then
inc(Result);
end;
else
inc(SrcPos);
end;
end;
end;
function PositionsInSameLine(const Source: string;
Pos1, Pos2: integer): boolean;
var

View File

@ -367,6 +367,12 @@ var
ProcAVLNode, NearestAVLNode: TAVLTreeNode;
ProcNodeExt, NearestNodeExt: TCodeTreeNodeExtension;
InsertBehind: boolean;
NearestAVLNodeInFront: TAVLTreeNode;
NearestAVLNodeBehind: TAVLTreeNode;
ProcPosInFront: Integer;
ProcPosBehind: Integer;
EmptyLinesInFront: Integer;
EmptyLinesBehind: Integer;
begin
IsInInterface:=ProcNode.HasParentOfType(ctnInterface);
if IsInInterface then begin
@ -413,7 +419,7 @@ begin
ProcBodyNodes:=GatherProcNodes(StartSearchProc,
[phpInUpperCase,phpIgnoreForwards,phpIgnoreMethods],'');
// delete current proc from tree
// remove current forward proc from tree
ProcAVLNode:=FindAVLNodeWithNode(ForwardProcNodes,ProcNode);
if ProcAVLNode=nil then
RaiseException('TCodeCompletionCodeTool.FindInsertPositionForForwardProc '
@ -427,19 +433,53 @@ begin
// sort forward proc definitions with source position
ForwardProcNodes.OnCompare:=@CompareCodeTreeNodeExtWithNodeStartPos;
{ For debugging:
ProcAVLNode:=ForwardProcNodes.FindLowest;
// For debugging:
{ProcAVLNode:=ForwardProcNodes.FindLowest;
while ProcAVLNode<>nil do begin
NearestProcNode:=TCodeTreeNodeExtension(ProcAVLNode.Data).Node;
writeln('FindInsertPositionForForwardProc B ',NearestProcNode.StartPos,' "',copy(Src,NearestProcNode.StartPos,20),'"');
ProcAVLNode:=ForwardProcNodes.FindSuccessor(ProcAVLNode);
end;}
// find nearest forward proc
// find nearest forward procs (distance measured in chars)
NearestAVLNode:=ForwardProcNodes.FindNearest(ProcNodeExt);
if NearestAVLNode<>nil then begin
//writeln('FindInsertPositionForForwardProc Nearest ',TCodeTreeNodeExtension(NearestAVLNode.Data).Node.StartPos,' ',ProcNode.StartPos);
// find nearest forward procs in front and after
if TCodeTreeNodeExtension(NearestAVLNode.Data).Node.StartPos
<ProcNode.StartPos
then begin
NearestAVLNodeInFront:=NearestAVLNode;
NearestAVLNodeBehind:=ForwardProcNodes.FindPrecessor(NearestAVLNode);
end else begin
NearestAVLNodeInFront:=ForwardProcNodes.FindSuccessor(NearestAVLNode);
NearestAVLNodeBehind:=NearestAVLNode;
end;
// choose the nearest of both (distance measured in emtpy lines,
// this way blocks of procs are kept)
if (NearestAVLNodeInFront<>nil) and (NearestAVLNodeBehind<>nil) then
begin
ProcPosInFront:=
TCodeTreeNodeExtension(NearestAVLNodeInFront.Data).Node.StartPos;
ProcPosBehind:=
TCodeTreeNodeExtension(NearestAVLNodeBehind.Data).Node.StartPos;
EmptyLinesInFront:=EmptyCodeLineCount(Src,
ProcPosInFront,ProcNode.StartPos,Scanner.NestedComments);
EmptyLinesBehind:=EmptyCodeLineCount(Src,
ProcNode.StartPos,ProcPosBehind,Scanner.NestedComments);
//writeln('FindInsertPositionForForwardProc Nearest InFront or After: EmptyLinesInFront=',EmptyLinesInFront,' EmptyLinesBehind=',EmptyLinesBehind);
if EmptyLinesInFront<EmptyLinesBehind then
NearestAVLNode:=NearestAVLNodeInFront
else
NearestAVLNode:=NearestAVLNodeBehind;
end;
NearestNodeExt:=TCodeTreeNodeExtension(NearestAVLNode.Data);
NearestProcNode:=NearestNodeExt.Node;
//writeln('FindInsertPositionForForwardProc C ',NearestProcNode.StartPos,' "',copy(Src,NearestProcNode.StartPos,20),'"');
InsertBehind:=NearestProcNode.StartPos<ProcNode.StartPos;

View File

@ -1489,7 +1489,7 @@ begin
with TBetterRegistry.Create do
begin
try
RootKey := integer(HKEY_LOCAL_MACHINE);
RootKey := HKEY_LOCAL_MACHINE;
{$IFNDEF SYN_LAZARUS}
if OpenKeyReadOnly('\SOFTWARE\Borland\C++Builder') then
begin
@ -1524,13 +1524,13 @@ function TSynCppSyn.UseUserSettings(settingIndex: integer): boolean;
begin
for i := 1 to Length(name) do
if name[i] = ' ' then name[i] := '_';
Result := attri.LoadFromBorlandRegistry(integer(HKEY_CURRENT_USER),
Result := attri.LoadFromBorlandRegistry(HKEY_CURRENT_USER,
'\SOFTWARE\Borland\C++Builder\'+settingTag+'\Highlight',name,true);
end; { ReadCPPB1 }
function ReadCPPB3OrMore(settingTag: string; attri: TSynHighlighterAttributes; key: string): boolean;
begin
Result := attri.LoadFromBorlandRegistry(integer(HKEY_CURRENT_USER),
Result := attri.LoadFromBorlandRegistry(HKEY_CURRENT_USER,
'\Software\Borland\C++Builder\'+settingTag+'\Editor\Highlight',
key,false);
end; { ReadCPPB3OrMore }

View File

@ -1580,7 +1580,7 @@ begin
with TBetterRegistry.Create do
begin
try
RootKey := integer(HKEY_LOCAL_MACHINE);
RootKey := HKEY_LOCAL_MACHINE;
{$IFNDEF SYN_LAZARUS}
// ToDo Registry
if OpenKeyReadOnly('\SOFTWARE\Borland\Delphi') then
@ -1618,14 +1618,14 @@ function TSynPasSyn.UseUserSettings(settingIndex: integer): boolean;
begin
for i := 1 to Length(name) do
if name[i] = ' ' then name[i] := '_';
Result := attri.LoadFromBorlandRegistry(integer(HKEY_CURRENT_USER),
Result := attri.LoadFromBorlandRegistry(HKEY_CURRENT_USER,
'\Software\Borland\Delphi\'+settingTag+'\Highlight',name,true);
end; { ReadDelphi2Or3 }
function ReadDelphi4OrMore(settingTag: string;
attri: TSynHighlighterAttributes; key: string): boolean;
begin
Result := attri.LoadFromBorlandRegistry(integer(HKEY_CURRENT_USER),
Result := attri.LoadFromBorlandRegistry(HKEY_CURRENT_USER,
'\Software\Borland\Delphi\'+settingTag+'\Editor\Highlight',
key,false);
end; { ReadDelphi4OrMore }

View File

@ -482,7 +482,7 @@ msgstr "W
#: lazarusidestrconsts:dlgautodel
msgid "Auto delete file"
msgstr "Automagicznie usuń plik"
msgstr "Automatycznie usuń plik"
#: lazarusidestrconsts:liscodetoolsdefsautogeneratednodescannotbeedited
msgid "Auto generated nodes can not be edited."
@ -490,7 +490,7 @@ msgstr "W
#: lazarusidestrconsts:dlgautoident
msgid "Auto Indent"
msgstr "Automagiczne wcięcia"
msgstr "Automatyczne wcięcia"
#: lazarusidestrconsts:lisoipautoinstalldynamic
msgid "auto install dynamic"
@ -846,7 +846,7 @@ msgstr "Czy
#: lazarusidestrconsts:lismenucleandirectory
msgid "Clean directory"
msgstr ""
msgstr "Czyść katalogi"
#: lazarusidestrconsts:liscleanlazarussource
msgid "Clean Lazarus Source"
@ -854,7 +854,7 @@ msgstr "Czy
#: lazarusidestrconsts:liscldircleansubdirectories
msgid "Clean sub directories"
msgstr ""
msgstr "Czyść podkatalogi"
#: lazarusidestrconsts:lislazbuildcleanbuild
msgid "Clean+Build"
@ -1254,7 +1254,7 @@ msgstr "Utw
#: lazarusidestrconsts:lismenueditorcreatesubmenu
msgid "Create Submenu"
msgstr ""
msgstr "Utwórz podmenu"
#: lazarusidestrconsts:dlgruberbandcreationcolor
msgid "Creation"
@ -1418,15 +1418,15 @@ msgstr "B
#: lazarusidestrconsts:lisdeletefilefailed
msgid "Delete file failed"
msgstr "Nie mogłem usunąć pliku"
msgstr "Nie można usunąć pliku"
#: lazarusidestrconsts:lismenueditordeletefromtemplate
msgid "Delete From Template..."
msgstr ""
msgstr "Skasuj z szablonu"
#: lazarusidestrconsts:lismenueditordeleteitem
msgid "Delete Item"
msgstr ""
msgstr "Skasuj element"
#: lazarusidestrconsts:srkmecdeletelastchar
msgid "Delete Last Char"
@ -2318,7 +2318,7 @@ msgstr "Przewijaj o p
#: lazarusidestrconsts:lismenueditorhandleonclickevent
msgid "Handle OnCLick Event"
msgstr ""
msgstr "przechwyć zdarzenie OnClick"
#: lazarusidestrconsts:srvk_hanja
msgid "Hanja"
@ -2650,7 +2650,7 @@ msgstr "Wstaw z tablicy znak
#: lazarusidestrconsts:lismenueditorinsertfromtemplate
msgid "Insert From Template..."
msgstr ""
msgstr "Wstaw z szablonu"
#: lazarusidestrconsts:srkmecinsertgplnotice
msgid "Insert GPL notice"
@ -2682,11 +2682,11 @@ msgstr "Tryb wstawiania"
#: lazarusidestrconsts:lismenueditorinsertnewitemafter
msgid "Insert New Item (after)"
msgstr ""
msgstr "Wstaw nowy element (poniżej)"
#: lazarusidestrconsts:lismenueditorinsertnewitembefore
msgid "Insert New Item (before)"
msgstr ""
msgstr "Wstaw nowy element (powyżej)"
#: lazarusidestrconsts:liscodetoolsdefsinsertnodeaschild
msgid "Insert node as child"
@ -2738,7 +2738,7 @@ msgstr "zainstalowany statycznie"
#: lazarusidestrconsts:lispkgmanginstallingthepackagewillautomaticallyinstall
msgid "Installing the package %s will automatically install the package(s):%s%s"
msgstr "Zainstalowanie pakietu %s spowoduje automagiczne doinstalowanie pakietu(ów):%s%s"
msgstr "Zainstalowanie pakietu %s spowoduje automatyczne doinstalowanie pakietu(ów):%s%s"
#: lazarusidestrconsts:ideinterbase
msgid "Interbase Data Access"
@ -2934,7 +2934,7 @@ msgstr "Kana"
#: lazarusidestrconsts:liscldirkeepalltextfiles
msgid "Keep all text files"
msgstr ""
msgstr "Zatrzymaj wszystkie pliki tekstowe"
#: lazarusidestrconsts:dlgkeepcaretx
msgid "Keep Caret X"
@ -2946,7 +2946,7 @@ msgstr "Trzymaj istotne zmienne w rejestrach"
#: lazarusidestrconsts:liscldirkeepfilesmatchingfilter
msgid "Keep files matching filter"
msgstr ""
msgstr "Zatrzymaj wyselekcjonowane pliki"
#: lazarusidestrconsts:dlgforwardprocskeeporder
msgid "Keep order of procedures"
@ -3198,7 +3198,7 @@ msgstr "Utw
#: lazarusidestrconsts:lispckoptsmanualcompilationneverautomatically
msgid "Manual compilation (never automatically)"
msgstr "Ręczna kompilacja (nigdy automagiczna)"
msgstr "Ręczna kompilacja (nigdy automatyczna)"
#: lazarusidestrconsts:dlgmargingutter
msgid "Margin and gutter"
@ -3422,11 +3422,11 @@ msgstr "W g
#: lazarusidestrconsts:lismenueditormoveup
msgid "Move Up(left)"
msgstr ""
msgstr "W górę na lewo"
#: lazarusidestrconsts:lismenueditormovedown
msgid "Move Up(right)"
msgstr ""
msgstr "W górę na prawo"
#: lazarusidestrconsts:dlgmulti
msgid "Multi"
@ -4270,7 +4270,7 @@ msgstr "Chcesz usun
#: lazarusidestrconsts:liscldirremovefilesmatchingfilter
msgid "Remove files matching filter"
msgstr ""
msgstr "Usuń wyselekcjonowane pliki"
#: lazarusidestrconsts:lismenuremovefromproject
msgid "Remove from Project"
@ -4490,7 +4490,7 @@ msgstr "Zapisz jako..."
#: lazarusidestrconsts:lismenueditorsaveastemplate
msgid "Save As Template..."
msgstr ""
msgstr "Zapisz jako szablon ..."
#: lazarusidestrconsts:lissavechangestoproject
msgid "Save changes to project %s?"
@ -4954,7 +4954,7 @@ msgstr "Ostrze
#: lazarusidestrconsts:liscldirsimplesyntaxeginsteadof
msgid "Simple Syntax (e.g. * instead of .*)"
msgstr ""
msgstr "Prosta składnia (e.g. * zamiast .*)"
#: lazarusidestrconsts:fdmsizeword
msgid "Size"
@ -5058,11 +5058,11 @@ msgstr "Zwyk
#: lazarusidestrconsts:lismenutemplatedescriptionstandardeditmenu
msgid "Standard Edit Menu"
msgstr ""
msgstr "Standardowe menu Edycja"
#: lazarusidestrconsts:lismenutemplatedescriptionstandardfilemenu
msgid "Standard File Menu"
msgstr ""
msgstr "Standardowe menu PLIK"
#: lazarusidestrconsts:lismenutemplatedescriptionstandardhelpmenu
msgid "Standard Help Menu"
@ -5210,11 +5210,11 @@ msgstr "Docelowa nazwa programu"
#: lazarusidestrconsts:dlgtargetos
msgid "Target OS"
msgstr "Docelowy system"
msgstr "Docelowy system operacyjny"
#: lazarusidestrconsts:liscotargetosspecificoptions
msgid "Target OS specific options"
msgstr ""
msgstr "Specyficzne opcje docelowego OS"
#: lazarusidestrconsts:lislazbuildtargetos
msgid "Target OS:"
@ -5494,7 +5494,7 @@ msgstr "Pakiet %s jest w
#: lazarusidestrconsts:lispckoptsthepackagehastheautoinstallflagthismeans
msgid "The package %s%s%s has the auto install flag.%sThis means it will be installed in the IDE. Installation packages%smust be designtime Packages."
msgstr "Pakiet %s%s%s ma znacznik auto instalacji.%sTo oznacza, że będzie ona automagicznie instalowany przez IDE. Instalowane pakiety%smuszą być pakietami projektowymi."
msgstr "Pakiet %s%s%s ma znacznik auto instalacji.%sTo oznacza, że będzie ona automatycznie instalowany przez IDE. Instalowane pakiety%smuszą być pakietami projektowymi."
#: lazarusidestrconsts:lispkgsysthepackageisinstalledbutnovalidpackagefilewasfound
msgid "The package %s%s%s is installed, but no valid package file was found.%sA broken dummy package was created."
@ -5542,7 +5542,7 @@ msgstr "Nazwa zak
#: lazarusidestrconsts:liscodetoolsdefsthepathtothefreepascalcompilerforthisproject
msgid "The path to the free pascal compiler for this project. Only required if you set the FPC CVS source below. Used to autocreate macros."
msgstr "Ścieżka do kompilatora FPC dla tego projektu. Wymagana jeśli ustawisz źródło CVS FPC poniżej. Używana do automagicznego tworzenia makr."
msgstr "Ścieżka do kompilatora FPC dla tego projektu. Wymagana jeśli ustawisz źródło CVS FPC poniżej. Używana do automatycznego tworzenia makr."
#: lazarusidestrconsts:liscodetoolsdefsthepathtothefreepascalcompilerforexample
msgid "The path to the free pascal compiler.%s For example %s/usr/bin/ppc386 -n%s or %s/usr/local/bin/fpc @/etc/11fpc.cfg%s."
@ -5658,7 +5658,7 @@ msgstr "ten komunikat pomocy"
#: lazarusidestrconsts:lisresourcefilecomment
msgid "This is an automatically generated lazarus resource file"
msgstr "To jest automagicznie wygenerowany plik zasobów lazarusa"
msgstr "To jest automatycznie wygenerowany plik zasobów lazarusa"
#: lazarusidestrconsts:lispkgsysthisisthedefaultpackageusedonlyforcomponents
msgid "This is the default package. Used only for components without a package. These components are outdated."
@ -6318,7 +6318,7 @@ msgstr "Wirtualny modu
#: lazarusidestrconsts:lisaf2pisvirtualunit
msgid "Virtual unit (source is not in package)"
msgstr ""
msgstr "Wirtualny moduł (brak źródeł w pakiecie)"
#: lazarusidestrconsts:dlgvisiblegutter
msgid "Visible gutter"
@ -6346,7 +6346,7 @@ msgstr "Czujki"
#: lazarusidestrconsts:dlgautocreatenewforms
msgid "When creating new forms, add them to auto-created forms"
msgstr "Nowe formularze dodawaj do automagicznie tworzonych"
msgstr "Nowe formularze dodawaj do tworzonych automatycznie"
#: lazarusidestrconsts:lisfindfilewhere
msgid "Where"
@ -6414,5 +6414,5 @@ msgstr "Nie mo
#: lazarusidestrconsts:lispkgmangthisfilewasautomaticallycreatedbylazarusdonotedit
msgid "{ This file was automatically created by Lazarus. Do not edit!%s This source is only used to compile and install%s the package %s.%s}%s"
msgstr "{ Ten plik został automagicznie utworzony przez Lazarusa. Nie zmieniaj go!%s Jest używany tylko do kompilowania i instalacji%s pakietu %s.%s}%s"
msgstr "{ Ten plik został automatycznie utworzony przez Lazarusa. Nie zmieniaj go!%s Jest używany tylko do kompilowania i instalacji%s pakietu %s.%s}%s"

View File

@ -49,7 +49,7 @@ type
ricfRGBA, // one pixel contains red, green, blue and alpha
// If AlphaPrec=0 then there is no alpha.
// Same for RedPrec, GreenPrec and BluePrec.
ricfGray // R=G=B. The Red stores the Gray. AlphaPec can be >0.
ricfGray // R=G=B. The Red stores the Gray. AlphaPrec can be >0.
);
TRawImageByteOrder = (
@ -209,6 +209,9 @@ end.
{ =============================================================================
$Log$
Revision 1.23 2003/12/06 19:20:46 mattias
codecompletion: forward proc body position now block sensitive
Revision 1.22 2003/11/28 11:25:49 mattias
added BitOrder for RawImages

View File

@ -2357,7 +2357,7 @@ end;
------------------------------------------------------------------------------}
Procedure TWinControl.WMSetFocus(var Message: TLMSetFocus);
Begin
Assert(False, Format('Trace:TODO: [TWinControl.LMSetFocus] %s', [ClassName]));
Assert(False, Format('Trace: %s', [ClassName]));
DoEnter;
end;
@ -2370,7 +2370,7 @@ end;
------------------------------------------------------------------------------}
procedure TWinControl.WMKillFocus(var Message: TLMKillFocus);
begin
Assert(False, Format('Trace: TODO: [TWinControl.LMKillFocus] %s', [ClassName]));
Assert(False, Format('Trace: %s', [ClassName]));
DoExit;
end;
@ -3136,6 +3136,9 @@ end;
{ =============================================================================
$Log$
Revision 1.180 2003/12/06 19:20:46 mattias
codecompletion: forward proc body position now block sensitive
Revision 1.179 2003/11/23 00:28:51 mattias
fixed closing IDE while debugging