mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-22 15:28:50 -05:00
Fixed small bug in Code Insight + made a start with code hints.
This commit is contained in:
parent
1bf4d9724d
commit
4748f5611d
@ -32,6 +32,7 @@ uses
|
|||||||
v_ideCodeInsight, v_ideCodeParser, CastaliaPasLexTypes, CastaliaSimplePasPar, SynEditHighlighter;
|
v_ideCodeInsight, v_ideCodeParser, CastaliaPasLexTypes, CastaliaSimplePasPar, SynEditHighlighter;
|
||||||
const
|
const
|
||||||
ecCodeCompletion = ecUserFirst;
|
ecCodeCompletion = ecUserFirst;
|
||||||
|
ecCodeHints = ecUserFirst + 1;
|
||||||
type
|
type
|
||||||
TScriptState = (ss_None,ss_Running,ss_Paused,ss_Stopping);
|
TScriptState = (ss_None,ss_Running,ss_Paused,ss_Stopping);
|
||||||
{
|
{
|
||||||
@ -256,89 +257,145 @@ var
|
|||||||
mp: TCodeInsight;
|
mp: TCodeInsight;
|
||||||
ms: TMemoryStream;
|
ms: TMemoryStream;
|
||||||
ItemList, InsertList: TStringList;
|
ItemList, InsertList: TStringList;
|
||||||
sp, ep: Integer;
|
sp, ep,bcc,cc,bck: Integer;
|
||||||
p: TPoint;
|
p: TPoint;
|
||||||
s, Filter: string;
|
s, Filter: string;
|
||||||
Attri: TSynHighlighterAttributes;
|
Attri: TSynHighlighterAttributes;
|
||||||
|
d: TDeclaration;
|
||||||
|
dd: TDeclaration;
|
||||||
begin
|
begin
|
||||||
if (Command = ecCodeCompletion) and ((not SynEdit.GetHighlighterAttriAtRowCol(SynEdit.CaretXY, s, Attri)) or (Attri.Name = 'Identifier')) then
|
if ((not SynEdit.GetHighlighterAttriAtRowCol(SynEdit.CaretXY, s, Attri)) or (Attri.Name = 'Identifier')) then
|
||||||
begin
|
begin
|
||||||
{form1.FunctionListShown(True);
|
if (Command = ecCodeCompletion) then
|
||||||
with form1.frmFunctionList do
|
begin;
|
||||||
if editSearchList.CanFocus then
|
{form1.FunctionListShown(True);
|
||||||
begin;
|
with form1.frmFunctionList do
|
||||||
editSearchList.SetFocus;
|
if editSearchList.CanFocus then
|
||||||
LineText := SynEdit.LineText;
|
begin;
|
||||||
Caret:=SynEdit.LogicalCaretXY;
|
editSearchList.SetFocus;
|
||||||
i := Caret.X - 1;
|
LineText := SynEdit.LineText;
|
||||||
endi := caret.x;
|
Caret:=SynEdit.LogicalCaretXY;
|
||||||
if (i > length(LineText)) or ((i = 0) and (length(lineText) = 0)) then
|
i := Caret.X - 1;
|
||||||
|
endi := caret.x;
|
||||||
|
if (i > length(LineText)) or ((i = 0) and (length(lineText) = 0)) then
|
||||||
|
begin
|
||||||
|
SearchText:= '';
|
||||||
|
CompletionLine := PadRight(linetext,caret.x);
|
||||||
|
end
|
||||||
|
else begin
|
||||||
|
while (i > 0) and (LineText[i] in ['a'..'z','A'..'Z','0'..'9','_']) do
|
||||||
|
dec(i);
|
||||||
|
while LineText[endi] in ['a'..'z','A'..'Z','0'..'9','_'] do
|
||||||
|
inc(endi);
|
||||||
|
SearchText := Trim(copy(LineText, i + 1, Caret.X - i - 1));
|
||||||
|
CompletionLine := LineText;
|
||||||
|
end;
|
||||||
|
CompletionStart:= LineText;
|
||||||
|
Delete(CompletionLine,i+1,endi - i - 1);
|
||||||
|
Insert('%s',CompletionLine,i+1);
|
||||||
|
CompletionCaret := Point(endi,Caret.y);
|
||||||
|
StartWordCompletion:= Point(i+1,caret.y);
|
||||||
|
mDebugLn(CompletionLine);
|
||||||
|
mDebugLn(CompletionStart);
|
||||||
|
InCodeCompletion := true;
|
||||||
|
editSearchList.Text:= SearchText;
|
||||||
|
editSearchList.SelStart:= Length(searchText);
|
||||||
|
SynEdit.SelectedColor.Style:= [fsUnderline];
|
||||||
|
SynEdit.SelectedColor.Foreground:= clBlack;
|
||||||
|
SynEdit.SelectedColor.Background:= clWhite;
|
||||||
|
Synedit.MarkupByClass[TSynEditMarkupHighlightAllCaret].TempDisable;
|
||||||
|
end;}
|
||||||
|
mp := TCodeInsight.Create;
|
||||||
|
mp.FileName := ScriptFile;
|
||||||
|
mp.OnMessage := @Form1.OnCCMessage;
|
||||||
|
mp.OnFindInclude := @Form1.OnCCFindInclude;
|
||||||
|
|
||||||
|
ms := TMemoryStream.Create;
|
||||||
|
ItemList := TStringList.Create;
|
||||||
|
InsertList := TStringList.Create;
|
||||||
|
InsertList.Sorted := True;
|
||||||
|
|
||||||
|
Synedit.Lines.SaveToStream(ms);
|
||||||
|
|
||||||
|
try
|
||||||
|
Filter := WordAtCaret(Synedit, sp, ep);
|
||||||
|
Form1.CodeCompletionStart := Point(sp, Synedit.CaretY);
|
||||||
|
mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1);
|
||||||
|
|
||||||
|
s := mp.GetExpressionAtPos;
|
||||||
|
if (s <> '') then
|
||||||
begin
|
begin
|
||||||
SearchText:= '';
|
sp := LastDelimiter('.', s);
|
||||||
CompletionLine := PadRight(linetext,caret.x);
|
if (sp > 0) then
|
||||||
end
|
Delete(s, sp, Length(s) - sp + 1)
|
||||||
else begin
|
else
|
||||||
while (i > 0) and (LineText[i] in ['a'..'z','A'..'Z','0'..'9','_']) do
|
s := '';
|
||||||
dec(i);
|
|
||||||
while LineText[endi] in ['a'..'z','A'..'Z','0'..'9','_'] do
|
|
||||||
inc(endi);
|
|
||||||
SearchText := Trim(copy(LineText, i + 1, Caret.X - i - 1));
|
|
||||||
CompletionLine := LineText;
|
|
||||||
end;
|
end;
|
||||||
CompletionStart:= LineText;
|
|
||||||
Delete(CompletionLine,i+1,endi - i - 1);
|
|
||||||
Insert('%s',CompletionLine,i+1);
|
|
||||||
CompletionCaret := Point(endi,Caret.y);
|
|
||||||
StartWordCompletion:= Point(i+1,caret.y);
|
|
||||||
mDebugLn(CompletionLine);
|
|
||||||
mDebugLn(CompletionStart);
|
|
||||||
InCodeCompletion := true;
|
|
||||||
editSearchList.Text:= SearchText;
|
|
||||||
editSearchList.SelStart:= Length(searchText);
|
|
||||||
SynEdit.SelectedColor.Style:= [fsUnderline];
|
|
||||||
SynEdit.SelectedColor.Foreground:= clBlack;
|
|
||||||
SynEdit.SelectedColor.Background:= clWhite;
|
|
||||||
Synedit.MarkupByClass[TSynEditMarkupHighlightAllCaret].TempDisable;
|
|
||||||
end;}
|
|
||||||
mp := TCodeInsight.Create;
|
|
||||||
mp.FileName := ScriptFile;
|
|
||||||
mp.OnMessage := @Form1.OnCCMessage;
|
|
||||||
mp.OnFindInclude := @Form1.OnCCFindInclude;
|
|
||||||
|
|
||||||
ms := TMemoryStream.Create;
|
mp.FillSynCompletionProposal(ItemList, InsertList, s);
|
||||||
ItemList := TStringList.Create;
|
p := SynEdit.ClientToScreen(SynEdit.RowColumnToPixels(Point(ep, SynEdit.CaretY)));
|
||||||
InsertList := TStringList.Create;
|
p.y := p.y + SynEdit.LineHeight;
|
||||||
InsertList.Sorted := True;
|
Form1.CodeCompletionForm.Show(p, ItemList, InsertList, Filter, SynEdit);
|
||||||
|
finally
|
||||||
Synedit.Lines.SaveToStream(ms);
|
FreeAndNil(ms);
|
||||||
|
FreeAndNil(mp);
|
||||||
try
|
ItemList.Free;
|
||||||
Filter := WordAtCaret(Synedit, sp, ep);
|
InsertList.Free;
|
||||||
Form1.CodeCompletionStart := Point(sp, Synedit.CaretY);
|
|
||||||
mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1);
|
|
||||||
|
|
||||||
s := mp.GetExpressionAtPos;
|
|
||||||
if (s <> '') then
|
|
||||||
begin
|
|
||||||
sp := LastDelimiter('.', s);
|
|
||||||
if (sp > 0) then
|
|
||||||
Delete(s, sp, Length(s) - sp + 1)
|
|
||||||
else
|
|
||||||
s := '';
|
|
||||||
end;
|
end;
|
||||||
|
end else
|
||||||
|
if command = ecCodeHints then
|
||||||
|
begin
|
||||||
|
mp := TCodeInsight.Create;
|
||||||
|
mp.OnMessage := @form1.OnCCMessage;
|
||||||
|
mp.OnFindInclude := @form1.OnCCFindInclude;
|
||||||
|
|
||||||
mp.FillSynCompletionProposal(ItemList, InsertList, s);
|
ms := TMemoryStream.Create;
|
||||||
p := SynEdit.ClientToScreen(SynEdit.RowColumnToPixels(Point(ep, SynEdit.CaretY)));
|
synedit.Lines.SaveToStream(ms);
|
||||||
p.y := p.y + SynEdit.LineHeight;
|
|
||||||
Form1.CodeCompletionForm.Show(p, ItemList, InsertList, Filter, SynEdit);
|
try
|
||||||
finally
|
Synedit.GetWordBoundsAtRowCol(Synedit.CaretXY, sp, ep);
|
||||||
FreeAndNil(ms);
|
mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1);
|
||||||
FreeAndNil(mp);
|
//mp.Position := Synedit.SelStart + (ep - Synedit.CaretX) - 1;
|
||||||
ItemList.Free;
|
|
||||||
InsertList.Free;
|
bcc := 1;
|
||||||
|
bck := 0;
|
||||||
|
cc := 0;
|
||||||
|
s := mp.GetExpressionAtPos(bcc, bck, cc, True);
|
||||||
|
if (s <> '') then
|
||||||
|
Delete(s, Length(s), 1);
|
||||||
|
|
||||||
|
d := mp.FindVarBase(s);
|
||||||
|
dd := nil;
|
||||||
|
while (d <> nil) and (d <> dd) and (d.Owner <> nil) and (not ((d is TciProcedureDeclaration) or (d.Owner is TciProcedureDeclaration))) do
|
||||||
|
begin
|
||||||
|
dd := d;
|
||||||
|
d := d.Owner.Items.GetFirstItemOfClass(TciTypeKind);
|
||||||
|
if (d <> nil) then
|
||||||
|
begin
|
||||||
|
d := TciTypeKind(d).GetRealType;
|
||||||
|
if (d is TciReturnType) then
|
||||||
|
d := d.Owner;
|
||||||
|
end;
|
||||||
|
if (d <> nil) and (d.Owner <> nil) and (not ((d is TciProcedureDeclaration) or (d.Owner is TciProcedureDeclaration))) then
|
||||||
|
d := mp.FindVarBase(d.CleanText)
|
||||||
|
else
|
||||||
|
Break;
|
||||||
|
end;
|
||||||
|
if (d <> nil) and (d <> dd) and (d.Owner <> nil) and ((d is TciProcedureDeclaration) or (d.Owner is TciProcedureDeclaration)) then
|
||||||
|
begin
|
||||||
|
if (not (d is TciProcedureDeclaration)) and (d.Owner is TciProcedureDeclaration) then
|
||||||
|
d := d.Owner;
|
||||||
|
if (TciProcedureDeclaration(d).SynParams <> '') then
|
||||||
|
formWriteln(TciProcedureDeclaration(d).SynParams)
|
||||||
|
else
|
||||||
|
FormWriteln('<no parameters expected>');
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
FreeAndNil(ms);
|
||||||
|
FreeAndNil(mp);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if Form1.CodeCompletionForm.Visible then
|
if Form1.CodeCompletionForm.Visible then
|
||||||
case Command of
|
case Command of
|
||||||
ecDeleteChar, ecDeleteWord, ecDeleteEOL:
|
ecDeleteChar, ecDeleteWord, ecDeleteEOL:
|
||||||
@ -522,6 +579,7 @@ begin
|
|||||||
MarkCaret.IgnoreKeywords := true;
|
MarkCaret.IgnoreKeywords := true;
|
||||||
end;
|
end;
|
||||||
AddKey(SynEdit,ecCodeCompletion,VK_SPACE,[ssCtrl]);
|
AddKey(SynEdit,ecCodeCompletion,VK_SPACE,[ssCtrl]);
|
||||||
|
AddKey(SynEdit,ecCodeHints,VK_SPACE,[ssCtrl,ssShift]);
|
||||||
// TSynPasSyn(SynEdit.Highlighter).NestedComments:= false; Does not work :(
|
// TSynPasSyn(SynEdit.Highlighter).NestedComments:= false; Does not work :(
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ uses
|
|||||||
colourpicker, framescript, windowselector, lcltype, ActnList,
|
colourpicker, framescript, windowselector, lcltype, ActnList,
|
||||||
SynExportHTML, SynEditKeyCmds, SynEditHighlighter,
|
SynExportHTML, SynEditKeyCmds, SynEditHighlighter,
|
||||||
SynEditMarkupHighAll, LMessages, Buttons,mmisc,
|
SynEditMarkupHighAll, LMessages, Buttons,mmisc,
|
||||||
stringutil,mufasatypesutil,mufasabase,
|
stringutil,mufasatypesutil,mufasabase, v_ideCodeParser,
|
||||||
about, framefunctionlist, ocr, updateform, simbasettings, psextension, virtualextension,
|
about, framefunctionlist, ocr, updateform, simbasettings, psextension, virtualextension,
|
||||||
extensionmanager, settingssandbox, v_ideCodeInsight, CastaliaPasLexTypes,
|
extensionmanager, settingssandbox, v_ideCodeInsight, CastaliaPasLexTypes,
|
||||||
CastaliaSimplePasPar, v_AutoCompleteForm, PSDump;
|
CastaliaSimplePasPar, v_AutoCompleteForm, PSDump;
|
||||||
@ -2213,17 +2213,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.ButtonTrayClick(Sender: TObject);
|
procedure TForm1.ButtonTrayClick(Sender: TObject);
|
||||||
{var
|
|
||||||
ms : TMemoryStream;
|
|
||||||
fs : TFileStream;}
|
|
||||||
begin
|
begin
|
||||||
{
|
self.hide;
|
||||||
fs := TFileStream.Create('c:\remake\fonts.tar.bz2',fmOpenRead);
|
|
||||||
ms := DecompressBZip2(fs);
|
|
||||||
fs.free;
|
|
||||||
UnTar(ms,'c:\remake\fonttest\',true);
|
|
||||||
ms.free;}
|
|
||||||
Form1.Hide;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean
|
procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean
|
||||||
|
@ -864,17 +864,16 @@ begin
|
|||||||
a := GetParamDeclarations;
|
a := GetParamDeclarations;
|
||||||
for i := Low(a) to High(a) do
|
for i := Low(a) to High(a) do
|
||||||
begin
|
begin
|
||||||
if (fItems[i] is TciConstParameter) then
|
if (a[i] is TciConstParameter) then
|
||||||
s := 'const '
|
s := 'const '
|
||||||
else if (fItems[i] is TciOutParameter) then
|
else if (a[i] is TciOutParameter) then
|
||||||
s := 'out '
|
s := 'out '
|
||||||
else if (fItems[i] is TciInParameter) then
|
else if (a[i] is TciInParameter) then
|
||||||
s := 'in '
|
s := 'in '
|
||||||
else if (fItems[i] is TciVarParameter) then
|
else if (a[i] is TciVarParameter) then
|
||||||
s := 'var '
|
s := 'var '
|
||||||
else
|
else
|
||||||
s := '';
|
s := '';
|
||||||
|
|
||||||
d := a[i].Items.GetFirstItemOfClass(TciParameterType);
|
d := a[i].Items.GetFirstItemOfClass(TciParameterType);
|
||||||
if (d <> nil) then
|
if (d <> nil) then
|
||||||
t := ': ' + d.ShortText
|
t := ': ' + d.ShortText
|
||||||
|
Loading…
Reference in New Issue
Block a user