mirror of https://gitlab.com/basile.b/dexed.git
support for DCD symbolLocation
This commit is contained in:
parent
edb85ef714
commit
60dda598ed
|
@ -1,4 +1,4 @@
|
||||||
module CoeditPlug;
|
module CoeditPlug;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Under linux:
|
Under linux:
|
||||||
|
|
|
@ -6,19 +6,33 @@ interface
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, process, forms, strutils;
|
Classes, SysUtils, process, forms, strutils;
|
||||||
|
|
||||||
|
|
||||||
|
(**
|
||||||
|
* Stops the server: e.g: to remove some bugy imports from the libman.
|
||||||
|
*)
|
||||||
|
procedure stopServer;
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Adds a folder of d sources for DCD.
|
* Adds a folder of d sources for DCD.
|
||||||
*)
|
*)
|
||||||
procedure addDcdImport(const aFilename: string);
|
procedure addDcdImport(const aFilename: string);
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* gets a list of propositions for the identifier at aPosition in aFilename.
|
* gets a list of propositions for the identifier at aPosition in aFilename.
|
||||||
*)
|
*)
|
||||||
procedure getCompletion(const aFilename: string; aPosition: Integer; const list: TStrings);
|
procedure getCompletion(const aFilename: string; aPosition: Integer; const list: TStrings);
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* tries to get the DDoc comment for the identifier at aPosition in aFilename.
|
* tries to get the DDoc comment for the identifier at aPosition in aFilename.
|
||||||
*)
|
*)
|
||||||
procedure getHint(const aFilename: string; aPosition: Integer; const list: TStrings);
|
procedure getHint(const aFilename: string; aPosition: Integer; const list: TStrings);
|
||||||
|
|
||||||
|
(**
|
||||||
|
* tries to get the symbol location of the identifier at aPosition in aFilename.
|
||||||
|
* after the call aFilename and aPosition contains the location filename and position.
|
||||||
|
*)
|
||||||
|
procedure getSymbolLoc(var aFilename: string; var aPosition: Integer);
|
||||||
|
|
||||||
var
|
var
|
||||||
DCD_server: TProcess;
|
DCD_server: TProcess;
|
||||||
DCD_client: TProcess;
|
DCD_client: TProcess;
|
||||||
|
@ -33,6 +47,17 @@ begin
|
||||||
DCD_server.Execute;
|
DCD_server.Execute;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure stopServer;
|
||||||
|
begin
|
||||||
|
if not DCD_server.Running then
|
||||||
|
exit;
|
||||||
|
while DCD_client.Running do;
|
||||||
|
DCD_client.Parameters.Clear;
|
||||||
|
DCD_client.Parameters.Add(--shutdown);
|
||||||
|
DCD_client.Execute;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//TODO-cfeature:remove import, e.g: when libman entries are modified.
|
||||||
procedure addDcdImport(const aFilename: string);
|
procedure addDcdImport(const aFilename: string);
|
||||||
begin
|
begin
|
||||||
if not dcdOn then exit;
|
if not dcdOn then exit;
|
||||||
|
@ -100,7 +125,7 @@ begin
|
||||||
lazyServerStart;
|
lazyServerStart;
|
||||||
//
|
//
|
||||||
if DCD_client.Running then exit;
|
if DCD_client.Running then exit;
|
||||||
|
//
|
||||||
DCD_client.Parameters.Clear;
|
DCD_client.Parameters.Clear;
|
||||||
DCD_client.Parameters.Add('-c');
|
DCD_client.Parameters.Add('-c');
|
||||||
DCD_client.Parameters.Add(intToStr(aPosition));
|
DCD_client.Parameters.Add(intToStr(aPosition));
|
||||||
|
@ -116,6 +141,38 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure getSymbolLoc(var aFilename: string; var aPosition: Integer);
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
str, loc: string;
|
||||||
|
begin
|
||||||
|
if not dcdOn then exit;
|
||||||
|
lazyServerStart;
|
||||||
|
//
|
||||||
|
if DCD_client.Running then exit;
|
||||||
|
//
|
||||||
|
DCD_client.Parameters.Clear;
|
||||||
|
DCD_client.Parameters.Add('-l');
|
||||||
|
DCD_client.Parameters.Add('-c');
|
||||||
|
DCD_client.Parameters.Add(intToStr(aPosition));
|
||||||
|
DCD_client.Parameters.Add(aFilename);
|
||||||
|
DCD_client.Execute;
|
||||||
|
//
|
||||||
|
str := 'a';
|
||||||
|
setlength(str, 384);
|
||||||
|
i := DCD_client.Output.Read(str[1], 384);
|
||||||
|
setLength(str, i);
|
||||||
|
if str <> '' then
|
||||||
|
begin
|
||||||
|
i := Pos(#9, str);
|
||||||
|
if i = -1 then exit;
|
||||||
|
loc := str[i+1..length(str)];
|
||||||
|
str := str[1..i-1];
|
||||||
|
aFilename := str;
|
||||||
|
loc := ReplaceStr(loc, LineEnding, '');
|
||||||
|
aPosition := strToIntDef(loc, -1);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
DCD_server := TProcess.Create(nil);
|
DCD_server := TProcess.Create(nil);
|
||||||
|
|
|
@ -48,6 +48,7 @@ type
|
||||||
function getEditorCount: NativeInt;
|
function getEditorCount: NativeInt;
|
||||||
function getEditorIndex: NativeInt;
|
function getEditorIndex: NativeInt;
|
||||||
procedure getCompletionList;
|
procedure getCompletionList;
|
||||||
|
procedure getSymbolLoc;
|
||||||
public
|
public
|
||||||
constructor create(aOwner: TComponent); override;
|
constructor create(aOwner: TComponent); override;
|
||||||
destructor destroy; override;
|
destructor destroy; override;
|
||||||
|
@ -131,12 +132,13 @@ begin
|
||||||
completion.Editor := curr;
|
completion.Editor := curr;
|
||||||
//
|
//
|
||||||
if pageControl.ActivePageIndex <> -1 then
|
if pageControl.ActivePageIndex <> -1 then
|
||||||
CEMainForm.docFocusedNotify(Self, pageControl.ActivePageIndex);
|
|
||||||
//
|
|
||||||
if (pageControl.ActivePage.Caption = '') then
|
|
||||||
begin
|
begin
|
||||||
fKeyChanged := true;
|
CEMainForm.docFocusedNotify(Self, pageControl.ActivePageIndex);
|
||||||
beginUpdateByDelay;
|
if (pageControl.ActivePage.Caption = '') then
|
||||||
|
begin
|
||||||
|
fKeyChanged := true;
|
||||||
|
beginUpdateByDelay;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -148,7 +150,7 @@ end;
|
||||||
|
|
||||||
procedure TCEEditorWidget.completionExecute(Sender: TObject);
|
procedure TCEEditorWidget.completionExecute(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
getCompletionList
|
getCompletionList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCEEditorWidget.completionCodeCompletion(var Value: string;
|
procedure TCEEditorWidget.completionCodeCompletion(var Value: string;
|
||||||
|
@ -205,11 +207,23 @@ begin
|
||||||
end;
|
end;
|
||||||
if fKeyChanged then
|
if fKeyChanged then
|
||||||
beginUpdateByDelay;
|
beginUpdateByDelay;
|
||||||
|
//
|
||||||
|
if (Key = VK_UP) and (shift = [ssShift,ssCtrl]) then
|
||||||
|
getSymbolLoc;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCEEditorWidget.memoKeyPress(Sender: TObject; var Key: char);
|
procedure TCEEditorWidget.memoKeyPress(Sender: TObject; var Key: char);
|
||||||
|
var
|
||||||
|
pt: Tpoint;
|
||||||
|
curr: TCESynMemo;
|
||||||
begin
|
begin
|
||||||
fKeyChanged := true;
|
fKeyChanged := true;
|
||||||
|
if Key = '.' then
|
||||||
|
begin
|
||||||
|
curr := TCESynMemo(Sender);
|
||||||
|
pt := ClientToScreen(point(curr.CaretXPix, curr.CaretYPix));
|
||||||
|
completion.Execute(curr.LineText[1..curr.CaretX] + '.', pt);
|
||||||
|
end;
|
||||||
beginUpdateByDelay;
|
beginUpdateByDelay;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -244,11 +258,47 @@ begin
|
||||||
stopUpdateByDelay;
|
stopUpdateByDelay;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCEEditorWidget.getSymbolLoc;
|
||||||
|
var
|
||||||
|
curr: TCESynMemo;
|
||||||
|
str: TMemoryStream;
|
||||||
|
srcpos: NativeInt;
|
||||||
|
ftempname, fname: string;
|
||||||
|
begin
|
||||||
|
if not dcdOn then exit;
|
||||||
|
//
|
||||||
|
curr := getCurrentEditor;
|
||||||
|
if curr = nil then exit;
|
||||||
|
//
|
||||||
|
str := TMemoryStream.Create;
|
||||||
|
try
|
||||||
|
ftempname := GetTempDir(false) + 'temp_' + uniqueObjStr(curr) + '.d';
|
||||||
|
curr.Lines.SaveToStream(str);
|
||||||
|
str.SaveToFile(ftempname);
|
||||||
|
try
|
||||||
|
fname := ftempname;
|
||||||
|
srcpos := curr.SelStart;
|
||||||
|
if curr.GetWordAtRowCol(curr.LogicalCaretXY) <> '' then
|
||||||
|
ce_dcd.getSymbolLoc(fname, srcpos);
|
||||||
|
CEMainForm.MessageWidget.addCeInf(fname);
|
||||||
|
CEMainForm.MessageWidget.addCeInf(intToStr(srcpos));
|
||||||
|
if fname <> ftempname then if fileExists(fname) then
|
||||||
|
CEMainForm.openFile(fname);
|
||||||
|
if srcpos <> -1 then
|
||||||
|
getCurrentEditor.SelStart := srcpos;
|
||||||
|
finally
|
||||||
|
DeleteFile(ftempname);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
str.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCEEditorWidget.getCompletionList;
|
procedure TCEEditorWidget.getCompletionList;
|
||||||
var
|
var
|
||||||
curr: TCESynMemo;
|
curr: TCESynMemo;
|
||||||
str: TMemoryStream;
|
str: TMemoryStream;
|
||||||
srcpos, i: NativeInt;
|
srcpos: NativeInt;
|
||||||
fname: string;
|
fname: string;
|
||||||
begin
|
begin
|
||||||
if not dcdOn then exit;
|
if not dcdOn then exit;
|
||||||
|
@ -263,16 +313,10 @@ begin
|
||||||
curr.Lines.SaveToStream(str);
|
curr.Lines.SaveToStream(str);
|
||||||
str.SaveToFile(fname);
|
str.SaveToFile(fname);
|
||||||
try
|
try
|
||||||
srcpos := 0;
|
srcpos := curr.SelStart;
|
||||||
for i := 0 to curr.LogicalCaretXY.y-2 do
|
|
||||||
begin
|
|
||||||
srcPos += length(curr.Lines.Strings[i]);
|
|
||||||
if curr.LogicalCaretXY.y <> 0 then
|
|
||||||
srcPos += length(LineEnding);
|
|
||||||
end;
|
|
||||||
srcpos += curr.LogicalCaretXY.x -1;
|
|
||||||
completion.ItemList.Clear;
|
completion.ItemList.Clear;
|
||||||
ce_dcd.getCompletion(fname, srcpos, completion.ItemList);
|
if curr.GetWordAtRowCol(curr.LogicalCaretXY) <> '' then
|
||||||
|
ce_dcd.getCompletion(fname, srcpos, completion.ItemList);
|
||||||
finally
|
finally
|
||||||
DeleteFile(fname);
|
DeleteFile(fname);
|
||||||
end;
|
end;
|
||||||
|
@ -286,7 +330,7 @@ var
|
||||||
curr: TCESynMemo;
|
curr: TCESynMemo;
|
||||||
str: TMemoryStream;
|
str: TMemoryStream;
|
||||||
lst: TStringList;
|
lst: TStringList;
|
||||||
srcpos, i: NativeInt;
|
srcpos: NativeInt;
|
||||||
fname: string;
|
fname: string;
|
||||||
begin
|
begin
|
||||||
result := '';
|
result := '';
|
||||||
|
@ -302,14 +346,7 @@ begin
|
||||||
curr.Lines.SaveToStream(str);
|
curr.Lines.SaveToStream(str);
|
||||||
try
|
try
|
||||||
str.SaveToFile(fname);
|
str.SaveToFile(fname);
|
||||||
srcpos := 0;
|
srcpos := curr.SelStart;
|
||||||
for i := 0 to curr.LogicalCaretXY.y-2 do
|
|
||||||
begin
|
|
||||||
srcPos += length(curr.Lines.Strings[i]);
|
|
||||||
if curr.LogicalCaretXY.y <> 0 then
|
|
||||||
srcPos += length(LineEnding);
|
|
||||||
end;
|
|
||||||
srcpos += curr.LogicalCaretXY.x -1;
|
|
||||||
if curr.GetWordAtRowCol(curr.LogicalCaretXY) <> '' then
|
if curr.GetWordAtRowCol(curr.LogicalCaretXY) <> '' then
|
||||||
ce_dcd.getHint(fname, srcpos, lst);
|
ce_dcd.getHint(fname, srcpos, lst);
|
||||||
result := lst.Text;
|
result := lst.Text;
|
||||||
|
|
Loading…
Reference in New Issue