1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-08-13 16:53:59 -04:00

Added support for DLLs to code completion.

This commit is contained in:
Niels 2010-05-18 14:14:22 +02:00
parent 48eba95926
commit ac693b663c
5 changed files with 114 additions and 14 deletions

View File

@ -246,9 +246,10 @@ begin
FillThread := TFillThread.Create(true);
FillThread.FunctionList := @Self.FunctionList;
FillThread.Analyzer := TCodeInsight.Create;
with FillThread,FillThread.Analyzer do
with FillThread,FillThread.Analyzer do
begin
OnFindInclude := @SimbaForm.OnCCFindInclude;
OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
FileName := SimbaForm.CurrScript.ScriptFile;
MS := TMemoryStream.Create;
MS.Write(Script[1],length(script));

View File

@ -173,6 +173,7 @@ begin
mp.FileName := ScriptFile;
mp.OnMessage := @SimbaForm.OnCCMessage;
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
mp.OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
ms := TMemoryStream.Create;
SynEdit.Lines.SaveToStream(ms);
@ -349,6 +350,7 @@ begin
mp.FileName := ScriptFile;
mp.OnMessage := @SimbaForm.OnCCMessage;
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
mp.OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
ms := TMemoryStream.Create;
ItemList := TStringList.Create;
@ -396,6 +398,7 @@ begin
mp := TCodeInsight.Create;
mp.OnMessage := @SimbaForm.OnCCMessage;
mp.OnFindInclude := @SimbaForm.OnCCFindInclude;
mp.OnLoadLibrary := @SimbaForm.OnCCLoadLibrary;
ms := TMemoryStream.Create;
synedit.Lines.SaveToStream(ms);

View File

@ -335,6 +335,7 @@ type
procedure OnCCMessage(Sender: TObject; const Typ: TMessageEventType; const Msg: string; X, Y: Integer);
procedure OnCompleteCode(Str: string);
function OnCCFindInclude(Sender: TObject; var FileName: string): Boolean;
function OnCCLoadLibrary(Sender: TObject; var LibName: string; out ci: TCodeInsight): Boolean;
private
PopupTab : integer;
RecentFileItems : array of TMenuItem;
@ -532,6 +533,39 @@ begin
result := false;
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;
var
Args : TVariantArray;
@ -1983,7 +2017,6 @@ begin
FreeAndNil(ExtManager);
end;
procedure CCFillCore;
var
t: TMThread;

View File

@ -1546,6 +1546,10 @@ begin
FDirectiveParamOrigin := FOrigin + FTokenPos;
FTokenPos := Run;
case KeyHash of
60: if KeyComp('LOADDLL') then
fTokenID := tokIncludeDirect
else
fTokenID := tokBorComment;
68: if KeyComp('INCLUDE') then
fTokenID := tokIncludeDirect
else

View File

@ -15,6 +15,7 @@ type
TCodeInsightArray = array of TCodeInsight;
TOnFindInclude = function(Sender: TObject; var FileName: string): Boolean of object;
TOnLoadLibrary = function(Sender: TObject; var FileName: string; out ci: TCodeInsight): Boolean of object;
{ TCodeInsight }
@ -28,6 +29,7 @@ type
fDeclarationAtPos: TDeclaration;
fOnFindInclude: TOnFindInclude;
fOnLoadLibrary: TOnLoadLibrary;
fIncludes: TCodeInsightArray;
InFunc: TDeclarationArray;
@ -45,6 +47,7 @@ type
function FindInclude(var FileName: string): Boolean;
procedure ParseInclude(FileName: string);
function LoadLibrary(var LibName: string): Boolean;
procedure OnInclude(Sender: TmwBasePasLex); override;
function GetVarType(s: string; out Decl: TDeclaration; Return: TVarBase): Boolean;
@ -66,6 +69,7 @@ type
procedure FillSynCompletionProposal(ItemList, InsertList: TStrings; Prefix: string = '');
property OnFindInclude: TOnFindInclude read fOnFindInclude write fOnFindInclude;
property OnLoadLibrary: TOnLoadLibrary read fOnLoadLibrary write fOnLoadLibrary;
property FileName: string read fFileName write fFileName;
property Position: Integer read fPos write SetPos;
property DeclarationAtPos: TDeclaration read fDeclarationAtPos;
@ -80,6 +84,9 @@ type
end;
TIncludeBufferArray = array of TIncludeBuffer;
const
LibPrefix = 'lib:';
var
CoreBuffer: TCodeInsightArray;
IncludeBuffer: TIncludeBufferArray;
@ -223,22 +230,68 @@ begin
fIncludes[l] := GetIncludeBuffer(FileName, Self).CodeInsight;
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);
var
Param: string;
i: Integer;
begin
Param := Sender.DirectiveParamOriginal;
{$ifdef FPC}
param := SetDirSeparators(param);
{$IFDEF FPC}
Param := SetDirSeparators(param);
{$ELSE}
Param := StringReplace(Param, '/', '\', [rfReplaceAll]);
{$ENDIF}
if (not Sender.IsJunk) and (Param <> '') then
begin
if FindInclude(Param) then
if (Pos('loaddll', LowerCase(Sender.Token)) <= 3) then
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
if (fIncludes[i].FileName = Param) then
begin
@ -247,9 +300,13 @@ begin
end;
if (Param <> '') then
begin
ParseInclude(Param);
end
else if Assigned(OnMessage) then
Param := '';
end;
end;
if (Param <> '') and Assigned(OnMessage) then
OnMessage(Self, meError, Format(ci_UnknownInclude, [Param]), Sender.PosXY.X, Sender.PosXY.Y);
end;
@ -888,8 +945,6 @@ begin
end;
constructor TCodeInsight.Create(FileName: string = '');
var
StrList : TStringList;
begin
inherited Create;
@ -898,6 +953,7 @@ begin
Proposal_ItemList := TStringList.Create;
fOnFindInclude := nil;
fOnLoadLibrary := nil;
fFileName := FileName;
if (fFileName <> '') and (not FileExists(fFileName)) then
fFileName := '';
@ -909,11 +965,13 @@ begin
fOwnStream := (fFileName <> '');
if fOwnStream then
begin
StrList := TStringList.Create;
fMemoryStream := TMemoryStream.Create;
StrList.LoadFromFile(filename); //Converts the line-endings.
StrList.SaveToStream(fMemoryStream);
Strlist.free;
with TStringList.Create do
begin
LoadFromFile(filename); //Converts the line-endings.
SaveToStream(fMemoryStream);
Free;
end;
end
else
fMemoryStream := nil;
@ -936,6 +994,7 @@ begin
with From as TCodeInsight do
begin
Self.OnFindInclude := OnFindInclude;
Self.OnLoadLibrary := OnLoadLibrary;
end;
inherited;