mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-22 23:38:50 -05:00
Added support for DLLs to code completion.
This commit is contained in:
parent
48eba95926
commit
ac693b663c
@ -249,6 +249,7 @@ begin
|
|||||||
with FillThread,FillThread.Analyzer do
|
with FillThread,FillThread.Analyzer do
|
||||||
begin
|
begin
|
||||||
OnFindInclude := @SimbaForm.OnCCFindInclude;
|
OnFindInclude := @SimbaForm.OnCCFindInclude;
|
||||||
|
OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
|
||||||
FileName := SimbaForm.CurrScript.ScriptFile;
|
FileName := SimbaForm.CurrScript.ScriptFile;
|
||||||
MS := TMemoryStream.Create;
|
MS := TMemoryStream.Create;
|
||||||
MS.Write(Script[1],length(script));
|
MS.Write(Script[1],length(script));
|
||||||
|
@ -173,6 +173,7 @@ begin
|
|||||||
mp.FileName := ScriptFile;
|
mp.FileName := ScriptFile;
|
||||||
mp.OnMessage := @SimbaForm.OnCCMessage;
|
mp.OnMessage := @SimbaForm.OnCCMessage;
|
||||||
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
|
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
|
||||||
|
mp.OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
|
||||||
|
|
||||||
ms := TMemoryStream.Create;
|
ms := TMemoryStream.Create;
|
||||||
SynEdit.Lines.SaveToStream(ms);
|
SynEdit.Lines.SaveToStream(ms);
|
||||||
@ -349,6 +350,7 @@ begin
|
|||||||
mp.FileName := ScriptFile;
|
mp.FileName := ScriptFile;
|
||||||
mp.OnMessage := @SimbaForm.OnCCMessage;
|
mp.OnMessage := @SimbaForm.OnCCMessage;
|
||||||
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
|
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
|
||||||
|
mp.OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
|
||||||
|
|
||||||
ms := TMemoryStream.Create;
|
ms := TMemoryStream.Create;
|
||||||
ItemList := TStringList.Create;
|
ItemList := TStringList.Create;
|
||||||
@ -396,6 +398,7 @@ begin
|
|||||||
mp := TCodeInsight.Create;
|
mp := TCodeInsight.Create;
|
||||||
mp.OnMessage := @SimbaForm.OnCCMessage;
|
mp.OnMessage := @SimbaForm.OnCCMessage;
|
||||||
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
|
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
|
||||||
|
mp.OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
|
||||||
|
|
||||||
ms := TMemoryStream.Create;
|
ms := TMemoryStream.Create;
|
||||||
synedit.Lines.SaveToStream(ms);
|
synedit.Lines.SaveToStream(ms);
|
||||||
|
@ -335,6 +335,7 @@ type
|
|||||||
procedure OnCCMessage(Sender: TObject; const Typ: TMessageEventType; const Msg: string; X, Y: Integer);
|
procedure OnCCMessage(Sender: TObject; const Typ: TMessageEventType; const Msg: string; X, Y: Integer);
|
||||||
procedure OnCompleteCode(Str: string);
|
procedure OnCompleteCode(Str: string);
|
||||||
function OnCCFindInclude(Sender: TObject; var FileName: string): Boolean;
|
function OnCCFindInclude(Sender: TObject; var FileName: string): Boolean;
|
||||||
|
function OnCCLoadLibrary(Sender: TObject; var LibName: string; out ci: TCodeInsight): Boolean;
|
||||||
private
|
private
|
||||||
PopupTab : integer;
|
PopupTab : integer;
|
||||||
RecentFileItems : array of TMenuItem;
|
RecentFileItems : array of TMenuItem;
|
||||||
@ -532,6 +533,39 @@ begin
|
|||||||
result := false;
|
result := false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TSimbaForm.OnCCLoadLibrary(Sender: TObject; var LibName: string; out ci: TCodeInsight): Boolean;
|
||||||
|
var
|
||||||
|
i, Index: Integer;
|
||||||
|
b: TStringList;
|
||||||
|
ms: TMemoryStream;
|
||||||
|
begin
|
||||||
|
Index := PluginsGlob.LoadPlugin(LibName);
|
||||||
|
if (Index < 0) then
|
||||||
|
Exit(False)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
b := TStringList.Create;
|
||||||
|
try
|
||||||
|
ms := TMemoryStream.Create;
|
||||||
|
|
||||||
|
with PluginsGlob.MPlugins[Index] do
|
||||||
|
for i := 0 to MethodLen - 1 do
|
||||||
|
b.Add(Methods[i].FuncStr + 'forward;');
|
||||||
|
ci := TCodeInsight.Create;
|
||||||
|
with ci do
|
||||||
|
begin
|
||||||
|
OnMessage := @SimbaForm.OnCCMessage;
|
||||||
|
b.SaveToStream(ms);
|
||||||
|
b.SaveToFile('C:\Lazarus\Mufasa Git\libdebug.txt');
|
||||||
|
FileName := LibName;
|
||||||
|
Run(ms, nil, -1, True);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
b.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TSimbaForm.HandleConnectionData;
|
procedure TSimbaForm.HandleConnectionData;
|
||||||
var
|
var
|
||||||
Args : TVariantArray;
|
Args : TVariantArray;
|
||||||
@ -1983,7 +2017,6 @@ begin
|
|||||||
FreeAndNil(ExtManager);
|
FreeAndNil(ExtManager);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure CCFillCore;
|
procedure CCFillCore;
|
||||||
var
|
var
|
||||||
t: TMThread;
|
t: TMThread;
|
||||||
|
@ -1546,6 +1546,10 @@ begin
|
|||||||
FDirectiveParamOrigin := FOrigin + FTokenPos;
|
FDirectiveParamOrigin := FOrigin + FTokenPos;
|
||||||
FTokenPos := Run;
|
FTokenPos := Run;
|
||||||
case KeyHash of
|
case KeyHash of
|
||||||
|
60: if KeyComp('LOADDLL') then
|
||||||
|
fTokenID := tokIncludeDirect
|
||||||
|
else
|
||||||
|
fTokenID := tokBorComment;
|
||||||
68: if KeyComp('INCLUDE') then
|
68: if KeyComp('INCLUDE') then
|
||||||
fTokenID := tokIncludeDirect
|
fTokenID := tokIncludeDirect
|
||||||
else
|
else
|
||||||
|
@ -15,6 +15,7 @@ type
|
|||||||
TCodeInsightArray = array of TCodeInsight;
|
TCodeInsightArray = array of TCodeInsight;
|
||||||
|
|
||||||
TOnFindInclude = function(Sender: TObject; var FileName: string): Boolean of object;
|
TOnFindInclude = function(Sender: TObject; var FileName: string): Boolean of object;
|
||||||
|
TOnLoadLibrary = function(Sender: TObject; var FileName: string; out ci: TCodeInsight): Boolean of object;
|
||||||
|
|
||||||
{ TCodeInsight }
|
{ TCodeInsight }
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ type
|
|||||||
fDeclarationAtPos: TDeclaration;
|
fDeclarationAtPos: TDeclaration;
|
||||||
|
|
||||||
fOnFindInclude: TOnFindInclude;
|
fOnFindInclude: TOnFindInclude;
|
||||||
|
fOnLoadLibrary: TOnLoadLibrary;
|
||||||
fIncludes: TCodeInsightArray;
|
fIncludes: TCodeInsightArray;
|
||||||
|
|
||||||
InFunc: TDeclarationArray;
|
InFunc: TDeclarationArray;
|
||||||
@ -45,6 +47,7 @@ type
|
|||||||
|
|
||||||
function FindInclude(var FileName: string): Boolean;
|
function FindInclude(var FileName: string): Boolean;
|
||||||
procedure ParseInclude(FileName: string);
|
procedure ParseInclude(FileName: string);
|
||||||
|
function LoadLibrary(var LibName: string): Boolean;
|
||||||
procedure OnInclude(Sender: TmwBasePasLex); override;
|
procedure OnInclude(Sender: TmwBasePasLex); override;
|
||||||
|
|
||||||
function GetVarType(s: string; out Decl: TDeclaration; Return: TVarBase): Boolean;
|
function GetVarType(s: string; out Decl: TDeclaration; Return: TVarBase): Boolean;
|
||||||
@ -66,6 +69,7 @@ type
|
|||||||
procedure FillSynCompletionProposal(ItemList, InsertList: TStrings; Prefix: string = '');
|
procedure FillSynCompletionProposal(ItemList, InsertList: TStrings; Prefix: string = '');
|
||||||
|
|
||||||
property OnFindInclude: TOnFindInclude read fOnFindInclude write fOnFindInclude;
|
property OnFindInclude: TOnFindInclude read fOnFindInclude write fOnFindInclude;
|
||||||
|
property OnLoadLibrary: TOnLoadLibrary read fOnLoadLibrary write fOnLoadLibrary;
|
||||||
property FileName: string read fFileName write fFileName;
|
property FileName: string read fFileName write fFileName;
|
||||||
property Position: Integer read fPos write SetPos;
|
property Position: Integer read fPos write SetPos;
|
||||||
property DeclarationAtPos: TDeclaration read fDeclarationAtPos;
|
property DeclarationAtPos: TDeclaration read fDeclarationAtPos;
|
||||||
@ -80,6 +84,9 @@ type
|
|||||||
end;
|
end;
|
||||||
TIncludeBufferArray = array of TIncludeBuffer;
|
TIncludeBufferArray = array of TIncludeBuffer;
|
||||||
|
|
||||||
|
const
|
||||||
|
LibPrefix = 'lib:';
|
||||||
|
|
||||||
var
|
var
|
||||||
CoreBuffer: TCodeInsightArray;
|
CoreBuffer: TCodeInsightArray;
|
||||||
IncludeBuffer: TIncludeBufferArray;
|
IncludeBuffer: TIncludeBufferArray;
|
||||||
@ -223,22 +230,68 @@ begin
|
|||||||
fIncludes[l] := GetIncludeBuffer(FileName, Self).CodeInsight;
|
fIncludes[l] := GetIncludeBuffer(FileName, Self).CodeInsight;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCodeInsight.LoadLibrary(var LibName: string): Boolean;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
s: string;
|
||||||
|
ci: TCodeInsight;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
for i := High(fIncludes) downto 0 do
|
||||||
|
if (fIncludes[i].FileName = LibPrefix+LibName) then
|
||||||
|
Exit(True);
|
||||||
|
|
||||||
|
for i := High(IncludeBuffer) downto 0 do
|
||||||
|
if (IncludeBuffer[i].Script = LibPrefix+LibName) then
|
||||||
|
begin
|
||||||
|
SetLength(fIncludes, Length(fIncludes) + 1);
|
||||||
|
fIncludes[High(fIncludes)] := IncludeBuffer[i].CodeInsight;
|
||||||
|
|
||||||
|
Exit(True);
|
||||||
|
end;
|
||||||
|
|
||||||
|
s := LibName;
|
||||||
|
if Assigned(OnLoadLibrary) and OnLoadLibrary(Self, s, ci) and (ci <> nil) then
|
||||||
|
begin
|
||||||
|
LibName := s;
|
||||||
|
|
||||||
|
SetLength(fIncludes, Length(fIncludes) + 1);
|
||||||
|
fIncludes[High(fIncludes)] := ci;
|
||||||
|
|
||||||
|
SetLength(IncludeBuffer, Length(IncludeBuffer) + 1);
|
||||||
|
with IncludeBuffer[High(IncludeBuffer)] do
|
||||||
|
begin
|
||||||
|
Script := LibPrefix+LibName;
|
||||||
|
CodeInsight := ci;
|
||||||
|
CodeInsight.FileName := LibPrefix+LibName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Exit(True);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCodeInsight.OnInclude(Sender: TmwBasePasLex);
|
procedure TCodeInsight.OnInclude(Sender: TmwBasePasLex);
|
||||||
var
|
var
|
||||||
Param: string;
|
Param: string;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Param := Sender.DirectiveParamOriginal;
|
Param := Sender.DirectiveParamOriginal;
|
||||||
{$ifdef FPC}
|
{$IFDEF FPC}
|
||||||
param := SetDirSeparators(param);
|
Param := SetDirSeparators(param);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Param := StringReplace(Param, '/', '\', [rfReplaceAll]);
|
Param := StringReplace(Param, '/', '\', [rfReplaceAll]);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
if (not Sender.IsJunk) and (Param <> '') then
|
if (not Sender.IsJunk) and (Param <> '') then
|
||||||
begin
|
begin
|
||||||
if FindInclude(Param) then
|
if (Pos('loaddll', LowerCase(Sender.Token)) <= 3) then
|
||||||
begin
|
begin
|
||||||
if (LowerCase(Sender.Token) = 'include_once') then
|
if LoadLibrary(Param) then
|
||||||
|
Param := '';
|
||||||
|
end
|
||||||
|
else if FindInclude(Param) then
|
||||||
|
begin
|
||||||
|
if (Pos('include_once', LowerCase(Sender.Token)) <= 3) then
|
||||||
for i := High(fIncludes) downto 0 do
|
for i := High(fIncludes) downto 0 do
|
||||||
if (fIncludes[i].FileName = Param) then
|
if (fIncludes[i].FileName = Param) then
|
||||||
begin
|
begin
|
||||||
@ -247,9 +300,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
if (Param <> '') then
|
if (Param <> '') then
|
||||||
|
begin
|
||||||
ParseInclude(Param);
|
ParseInclude(Param);
|
||||||
end
|
Param := '';
|
||||||
else if Assigned(OnMessage) then
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (Param <> '') and Assigned(OnMessage) then
|
||||||
OnMessage(Self, meError, Format(ci_UnknownInclude, [Param]), Sender.PosXY.X, Sender.PosXY.Y);
|
OnMessage(Self, meError, Format(ci_UnknownInclude, [Param]), Sender.PosXY.X, Sender.PosXY.Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -888,8 +945,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCodeInsight.Create(FileName: string = '');
|
constructor TCodeInsight.Create(FileName: string = '');
|
||||||
var
|
|
||||||
StrList : TStringList;
|
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
|
||||||
@ -898,6 +953,7 @@ begin
|
|||||||
Proposal_ItemList := TStringList.Create;
|
Proposal_ItemList := TStringList.Create;
|
||||||
|
|
||||||
fOnFindInclude := nil;
|
fOnFindInclude := nil;
|
||||||
|
fOnLoadLibrary := nil;
|
||||||
fFileName := FileName;
|
fFileName := FileName;
|
||||||
if (fFileName <> '') and (not FileExists(fFileName)) then
|
if (fFileName <> '') and (not FileExists(fFileName)) then
|
||||||
fFileName := '';
|
fFileName := '';
|
||||||
@ -909,11 +965,13 @@ begin
|
|||||||
fOwnStream := (fFileName <> '');
|
fOwnStream := (fFileName <> '');
|
||||||
if fOwnStream then
|
if fOwnStream then
|
||||||
begin
|
begin
|
||||||
StrList := TStringList.Create;
|
|
||||||
fMemoryStream := TMemoryStream.Create;
|
fMemoryStream := TMemoryStream.Create;
|
||||||
StrList.LoadFromFile(filename); //Converts the line-endings.
|
with TStringList.Create do
|
||||||
StrList.SaveToStream(fMemoryStream);
|
begin
|
||||||
Strlist.free;
|
LoadFromFile(filename); //Converts the line-endings.
|
||||||
|
SaveToStream(fMemoryStream);
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
fMemoryStream := nil;
|
fMemoryStream := nil;
|
||||||
@ -936,6 +994,7 @@ begin
|
|||||||
with From as TCodeInsight do
|
with From as TCodeInsight do
|
||||||
begin
|
begin
|
||||||
Self.OnFindInclude := OnFindInclude;
|
Self.OnFindInclude := OnFindInclude;
|
||||||
|
Self.OnLoadLibrary := OnLoadLibrary;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
inherited;
|
inherited;
|
||||||
|
Loading…
Reference in New Issue
Block a user