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:
|
||||
|
|
|
@ -6,19 +6,33 @@ interface
|
|||
uses
|
||||
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.
|
||||
*)
|
||||
procedure addDcdImport(const aFilename: string);
|
||||
|
||||
(**
|
||||
* gets a list of propositions for the identifier at aPosition in aFilename.
|
||||
*)
|
||||
procedure getCompletion(const aFilename: string; aPosition: Integer; const list: TStrings);
|
||||
|
||||
(**
|
||||
* tries to get the DDoc comment for the identifier at aPosition in aFilename.
|
||||
*)
|
||||
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
|
||||
DCD_server: TProcess;
|
||||
DCD_client: TProcess;
|
||||
|
@ -33,6 +47,17 @@ begin
|
|||
DCD_server.Execute;
|
||||
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);
|
||||
begin
|
||||
if not dcdOn then exit;
|
||||
|
@ -100,7 +125,7 @@ begin
|
|||
lazyServerStart;
|
||||
//
|
||||
if DCD_client.Running then exit;
|
||||
|
||||
//
|
||||
DCD_client.Parameters.Clear;
|
||||
DCD_client.Parameters.Add('-c');
|
||||
DCD_client.Parameters.Add(intToStr(aPosition));
|
||||
|
@ -116,6 +141,38 @@ begin
|
|||
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
|
||||
DCD_server := TProcess.Create(nil);
|
||||
|
|
|
@ -48,6 +48,7 @@ type
|
|||
function getEditorCount: NativeInt;
|
||||
function getEditorIndex: NativeInt;
|
||||
procedure getCompletionList;
|
||||
procedure getSymbolLoc;
|
||||
public
|
||||
constructor create(aOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
|
@ -131,12 +132,13 @@ begin
|
|||
completion.Editor := curr;
|
||||
//
|
||||
if pageControl.ActivePageIndex <> -1 then
|
||||
CEMainForm.docFocusedNotify(Self, pageControl.ActivePageIndex);
|
||||
//
|
||||
if (pageControl.ActivePage.Caption = '') then
|
||||
begin
|
||||
fKeyChanged := true;
|
||||
beginUpdateByDelay;
|
||||
CEMainForm.docFocusedNotify(Self, pageControl.ActivePageIndex);
|
||||
if (pageControl.ActivePage.Caption = '') then
|
||||
begin
|
||||
fKeyChanged := true;
|
||||
beginUpdateByDelay;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -148,7 +150,7 @@ end;
|
|||
|
||||
procedure TCEEditorWidget.completionExecute(Sender: TObject);
|
||||
begin
|
||||
getCompletionList
|
||||
getCompletionList;
|
||||
end;
|
||||
|
||||
procedure TCEEditorWidget.completionCodeCompletion(var Value: string;
|
||||
|
@ -205,11 +207,23 @@ begin
|
|||
end;
|
||||
if fKeyChanged then
|
||||
beginUpdateByDelay;
|
||||
//
|
||||
if (Key = VK_UP) and (shift = [ssShift,ssCtrl]) then
|
||||
getSymbolLoc;
|
||||
end;
|
||||
|
||||
procedure TCEEditorWidget.memoKeyPress(Sender: TObject; var Key: char);
|
||||
var
|
||||
pt: Tpoint;
|
||||
curr: TCESynMemo;
|
||||
begin
|
||||
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;
|
||||
end;
|
||||
|
||||
|
@ -244,11 +258,47 @@ begin
|
|||
stopUpdateByDelay;
|
||||
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;
|
||||
var
|
||||
curr: TCESynMemo;
|
||||
str: TMemoryStream;
|
||||
srcpos, i: NativeInt;
|
||||
srcpos: NativeInt;
|
||||
fname: string;
|
||||
begin
|
||||
if not dcdOn then exit;
|
||||
|
@ -263,16 +313,10 @@ begin
|
|||
curr.Lines.SaveToStream(str);
|
||||
str.SaveToFile(fname);
|
||||
try
|
||||
srcpos := 0;
|
||||
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;
|
||||
srcpos := curr.SelStart;
|
||||
completion.ItemList.Clear;
|
||||
ce_dcd.getCompletion(fname, srcpos, completion.ItemList);
|
||||
if curr.GetWordAtRowCol(curr.LogicalCaretXY) <> '' then
|
||||
ce_dcd.getCompletion(fname, srcpos, completion.ItemList);
|
||||
finally
|
||||
DeleteFile(fname);
|
||||
end;
|
||||
|
@ -286,7 +330,7 @@ var
|
|||
curr: TCESynMemo;
|
||||
str: TMemoryStream;
|
||||
lst: TStringList;
|
||||
srcpos, i: NativeInt;
|
||||
srcpos: NativeInt;
|
||||
fname: string;
|
||||
begin
|
||||
result := '';
|
||||
|
@ -302,14 +346,7 @@ begin
|
|||
curr.Lines.SaveToStream(str);
|
||||
try
|
||||
str.SaveToFile(fname);
|
||||
srcpos := 0;
|
||||
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;
|
||||
srcpos := curr.SelStart;
|
||||
if curr.GetWordAtRowCol(curr.LogicalCaretXY) <> '' then
|
||||
ce_dcd.getHint(fname, srcpos, lst);
|
||||
result := lst.Text;
|
||||
|
|
Loading…
Reference in New Issue