mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-24 08:18:52 -05:00
AutoShow codecompletion.
This commit is contained in:
parent
f5c6880829
commit
a50a9199d0
@ -88,13 +88,13 @@ type
|
|||||||
{ public declarations }
|
{ public declarations }
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1): string;
|
function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1; Offset: Integer = 0): string;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
uses
|
uses
|
||||||
SimbaUnit, SynEditTypes, LCLIntF, StrUtils,framefunctionlist;
|
SimbaUnit, SynEditTypes, LCLIntF, StrUtils,framefunctionlist;
|
||||||
|
|
||||||
function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1): string;
|
function WordAtCaret(e: TSynEdit; var sp, ep: Integer; Start: Integer = -1; Offset: Integer = 0): string;
|
||||||
var
|
var
|
||||||
s: string;
|
s: string;
|
||||||
l: Integer;
|
l: Integer;
|
||||||
@ -102,6 +102,7 @@ begin
|
|||||||
Result := '';
|
Result := '';
|
||||||
if (Start = -1) then
|
if (Start = -1) then
|
||||||
Start := e.CaretX;
|
Start := e.CaretX;
|
||||||
|
Start := Start + Offset;
|
||||||
sp := Start - 1;
|
sp := Start - 1;
|
||||||
ep := Start - 1;
|
ep := Start - 1;
|
||||||
s := e.Lines[e.CaretY - 1];
|
s := e.Lines[e.CaretY - 1];
|
||||||
@ -222,10 +223,16 @@ var
|
|||||||
s: string;
|
s: string;
|
||||||
sp, ep: Integer;
|
sp, ep: Integer;
|
||||||
begin
|
begin
|
||||||
if (Command = ecChar) and (AChar = '(') and (SimbaForm.ParamHint.Visible = false) and (SimbaForm.ShowHintAuto) then
|
if (Command = ecChar) then
|
||||||
|
if(AChar = '(') and (SimbaForm.ParamHint.Visible = False) and (SimbaForm.ShowParamHintAuto) then
|
||||||
begin
|
begin
|
||||||
Command2:= ecCodeHints;
|
Command2:= ecCodeHints;
|
||||||
SynEditProcessUserCommand(sender,command2,achar,nil);
|
SynEditProcessUserCommand(sender,command2,achar,nil);
|
||||||
|
end
|
||||||
|
else if(AChar = '.') and (SimbaForm.CodeCompletionForm.Visible = False) and (SimbaForm.ShowCodeCompletionAuto) then
|
||||||
|
begin
|
||||||
|
Command2:= ecCodeCompletion;
|
||||||
|
SynEditProcessUserCommand(sender,command2,achar, Pointer(@s));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if SimbaForm.CodeCompletionForm.Visible then
|
if SimbaForm.CodeCompletionForm.Visible then
|
||||||
@ -328,43 +335,6 @@ begin
|
|||||||
if (Command = ecCodeCompletion) and ((not SynEdit.GetHighlighterAttriAtRowCol(SynEdit.CaretXY, s, Attri)) or
|
if (Command = ecCodeCompletion) and ((not SynEdit.GetHighlighterAttriAtRowCol(SynEdit.CaretXY, s, Attri)) or
|
||||||
((Attri.Name <> SYNS_AttrComment) and (Attri.name <> SYNS_AttrString) and (Attri.name <> SYNS_AttrDirective))) then
|
((Attri.Name <> SYNS_AttrComment) and (Attri.name <> SYNS_AttrString) and (Attri.name <> SYNS_AttrDirective))) then
|
||||||
begin
|
begin
|
||||||
{SimbaForm.FunctionListShown(True);
|
|
||||||
with SimbaForm.frmFunctionList do
|
|
||||||
if editSearchList.CanFocus then
|
|
||||||
begin;
|
|
||||||
editSearchList.SetFocus;
|
|
||||||
LineText := SynEdit.LineText;
|
|
||||||
Caret:=SynEdit.LogicalCaretXY;
|
|
||||||
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 := TCodeInsight.Create;
|
||||||
mp.FileName := ScriptFile;
|
mp.FileName := ScriptFile;
|
||||||
mp.OnMessage := @SimbaForm.OnCCMessage;
|
mp.OnMessage := @SimbaForm.OnCCMessage;
|
||||||
@ -399,10 +369,17 @@ begin
|
|||||||
s := '';
|
s := '';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if (Data <> nil) then //If showing automatically
|
||||||
|
if (s <> '') and (((mp.DeclarationAtPos <> nil) and (mp.DeclarationAtPos is TciCompoundStatement)) or ((mp.DeclarationAtPos.Owner <> nil) and (mp.DeclarationAtPos.Owner is TciCompoundStatement))) then
|
||||||
|
Data := nil;
|
||||||
|
|
||||||
|
if (Data = nil) then
|
||||||
|
begin
|
||||||
mp.FillSynCompletionProposal(ItemList, InsertList, s);
|
mp.FillSynCompletionProposal(ItemList, InsertList, s);
|
||||||
p := SynEdit.ClientToScreen(SynEdit.RowColumnToPixels(Point(ep, SynEdit.CaretY)));
|
p := SynEdit.ClientToScreen(SynEdit.RowColumnToPixels(Point(ep, SynEdit.CaretY)));
|
||||||
p.y := p.y + SynEdit.LineHeight;
|
p.y := p.y + SynEdit.LineHeight;
|
||||||
SimbaForm.CodeCompletionForm.Show(p, ItemList, InsertList, Filter, SynEdit);
|
SimbaForm.CodeCompletionForm.Show(p, ItemList, InsertList, Filter, SynEdit);
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
FreeAndNil(ms);
|
FreeAndNil(ms);
|
||||||
FreeAndNil(mp);
|
FreeAndNil(mp);
|
||||||
@ -425,9 +402,9 @@ begin
|
|||||||
Synedit.GetWordBoundsAtRowCol(Synedit.CaretXY, sp, ep);
|
Synedit.GetWordBoundsAtRowCol(Synedit.CaretXY, sp, ep);
|
||||||
s := SynEdit.Lines[SynEdit.Carety-1];
|
s := SynEdit.Lines[SynEdit.Carety-1];
|
||||||
if ep > length(s) then //We are outside the real text, go back to the last char
|
if ep > length(s) then //We are outside the real text, go back to the last char
|
||||||
mp.Run(ms, nil, Synedit.SelStart - ep + length(s),true)
|
mp.Run(ms, nil, Synedit.SelStart - ep + length(s), True)
|
||||||
else
|
else
|
||||||
mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1,true);
|
mp.Run(ms, nil, Synedit.SelStart + (ep - Synedit.CaretX) - 1, True);
|
||||||
bcc := 1;bck := 0;cc := 0;
|
bcc := 1;bck := 0;cc := 0;
|
||||||
s := mp.GetExpressionAtPos(bcc, bck, cc,posi, true);
|
s := mp.GetExpressionAtPos(bcc, bck, cc,posi, true);
|
||||||
|
|
||||||
@ -544,8 +521,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TScriptFrame.HandleErrorData;
|
procedure TScriptFrame.HandleErrorData;
|
||||||
var
|
|
||||||
i : integer;
|
|
||||||
begin
|
begin
|
||||||
if ErrorData.Module <> '' then
|
if ErrorData.Module <> '' then
|
||||||
begin;
|
begin;
|
||||||
|
@ -359,14 +359,16 @@ type
|
|||||||
function GetIncludePath: String;
|
function GetIncludePath: String;
|
||||||
function GetPluginPath: string;
|
function GetPluginPath: string;
|
||||||
function GetScriptState: TScriptState;
|
function GetScriptState: TScriptState;
|
||||||
function GetShowHintAuto: boolean;
|
function GetShowParamHintAuto: boolean;
|
||||||
|
function GetShowCodeCompletionAuto: Boolean;
|
||||||
function GetSimbaNews: String;
|
function GetSimbaNews: String;
|
||||||
procedure SetExtPath(const AValue: string);
|
procedure SetExtPath(const AValue: string);
|
||||||
procedure SetFontPath(const AValue: String);
|
procedure SetFontPath(const AValue: String);
|
||||||
procedure SetIncludePath(const AValue: String);
|
procedure SetIncludePath(const AValue: String);
|
||||||
procedure SetPluginPath(const AValue: string);
|
procedure SetPluginPath(const AValue: string);
|
||||||
procedure SetScriptPath(const AValue: string);
|
procedure SetScriptPath(const AValue: string);
|
||||||
procedure SetShowHintAuto(const AValue: boolean);
|
procedure SetShowParamHintAuto(const AValue: boolean);
|
||||||
|
procedure SetShowCodeCompletionAuto(const AValue: boolean);
|
||||||
procedure SetScriptState(const State: TScriptState);
|
procedure SetScriptState(const State: TScriptState);
|
||||||
function LoadSettingDef(const Key, Def : string) : string;
|
function LoadSettingDef(const Key, Def : string) : string;
|
||||||
function CreateSetting(const Key, Value : string) : string;
|
function CreateSetting(const Key, Value : string) : string;
|
||||||
@ -421,7 +423,8 @@ type
|
|||||||
procedure InitalizeTMThread(var Thread : TMThread);
|
procedure InitalizeTMThread(var Thread : TMThread);
|
||||||
procedure HandleParameters;
|
procedure HandleParameters;
|
||||||
procedure OnSaveScript(const Filename : string);
|
procedure OnSaveScript(const Filename : string);
|
||||||
property ShowHintAuto : boolean read GetShowHintAuto write SetShowHintAuto;
|
property ShowParamHintAuto : boolean read GetShowParamHintAuto write SetShowParamHintAuto;
|
||||||
|
property ShowCodeCompletionAuto: Boolean read GetShowCodeCompletionAuto write SetShowCodeCompletionAuto;
|
||||||
property IncludePath : String read GetIncludePath write SetIncludePath;
|
property IncludePath : String read GetIncludePath write SetIncludePath;
|
||||||
property FontPath : String read GetFontPath write SetFontPath;
|
property FontPath : String read GetFontPath write SetFontPath;
|
||||||
property PluginPath : string read GetPluginPath write SetPluginPath;
|
property PluginPath : string read GetPluginPath write SetPluginPath;
|
||||||
@ -1163,6 +1166,7 @@ begin
|
|||||||
CreateSetting('Settings/MainForm/NormalSize','739:555');
|
CreateSetting('Settings/MainForm/NormalSize','739:555');
|
||||||
CreateSetting('Settings/FunctionList/ShowOnStart','True');
|
CreateSetting('Settings/FunctionList/ShowOnStart','True');
|
||||||
CreateSetting('Settings/CodeHints/ShowAutomatically','True');
|
CreateSetting('Settings/CodeHints/ShowAutomatically','True');
|
||||||
|
CreateSetting('Settings/CodeCompletion/ShowAutomatically','True');
|
||||||
CreateSetting('Settings/SourceEditor/LazColors','True');
|
CreateSetting('Settings/SourceEditor/LazColors','True');
|
||||||
CreateSetting('Settings/Extensions/FileExtension','sex');
|
CreateSetting('Settings/Extensions/FileExtension','sex');
|
||||||
|
|
||||||
@ -2580,11 +2584,16 @@ begin
|
|||||||
result := CurrScript.FScriptState;
|
result := CurrScript.FScriptState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSimbaForm.GetShowHintAuto: boolean;
|
function TSimbaForm.GetShowParamHintAuto: boolean;
|
||||||
begin
|
begin
|
||||||
Result := LowerCase(LoadSettingDef('Settings/CodeHints/ShowAutomatically','True')) = 'true';
|
Result := LowerCase(LoadSettingDef('Settings/CodeHints/ShowAutomatically','True')) = 'true';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSimbaForm.GetShowCodeCompletionAuto: boolean;
|
||||||
|
begin
|
||||||
|
Result := LowerCase(LoadSettingDef('Settings/CodeCompletion/ShowAutomatically','True')) = 'true';
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSimbaForm.SetFontPath(const AValue: String);
|
procedure TSimbaForm.SetFontPath(const AValue: String);
|
||||||
begin
|
begin
|
||||||
SetSetting('Settings/Fonts/Path',AValue,true);
|
SetSetting('Settings/Fonts/Path',AValue,true);
|
||||||
@ -2755,9 +2764,14 @@ begin
|
|||||||
TThread.Synchronize(nil,@HandleScriptStartData);
|
TThread.Synchronize(nil,@HandleScriptStartData);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSimbaForm.SetShowHintAuto(const AValue: boolean);
|
procedure TSimbaForm.SetShowParamHintAuto(const AValue: boolean);
|
||||||
begin
|
begin
|
||||||
SetSetting('Settings/CodeHints/ShowAutomatically',Booltostr(AValue,true));
|
SetSetting('Settings/CodeHints/ShowAutomatically', Booltostr(AValue,true));
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSimbaForm.SetShowCodeCompletionAuto(const AValue: boolean);
|
||||||
|
begin
|
||||||
|
SetSetting('Settings/CodeCompletion/ShowAutomatically', Booltostr(AValue,true));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$ifdef mswindows}
|
{$ifdef mswindows}
|
||||||
|
Loading…
Reference in New Issue
Block a user