test local identifier renaming (DCD#324)

This commit is contained in:
Basile Burg 2016-04-26 03:23:17 +02:00
parent 32d4521e3f
commit 989effb422
4 changed files with 104 additions and 11 deletions

View File

@ -14,6 +14,7 @@ uses
type type
TIntOpenArray = array of integer;
(** (**
* Wrap the dcd-server and dcd-client processes. * Wrap the dcd-server and dcd-client processes.
@ -64,6 +65,7 @@ type
procedure getCallTip(out tips: string); procedure getCallTip(out tips: string);
procedure getDdocFromCursor(out aComment: string); procedure getDdocFromCursor(out aComment: string);
procedure getDeclFromCursor(out aFilename: string; out aPosition: Integer); procedure getDeclFromCursor(out aFilename: string; out aPosition: Integer);
procedure getLocalSymbolUsageFromCursor(var locs: TIntOpenArray);
// //
property available: boolean read fAvailable; property available: boolean read fAvailable;
end; end;
@ -540,6 +542,40 @@ begin
aPosition := strToIntDef(loc, -1); aPosition := strToIntDef(loc, -1);
end; end;
end; end;
procedure TCEDcdWrapper.getLocalSymbolUsageFromCursor(var locs: TIntOpenArray);
var
i: Integer;
str: string;
begin
if not fAvailable then exit;
if not fServerListening then exit;
if fDoc = nil then exit;
//
terminateClient;
//
fClient.Parameters.Clear;
fClient.Parameters.Add('-u');
fClient.Parameters.Add('-c');
fClient.Parameters.Add(intToStr(fDoc.SelStart - 1));
fClient.Execute;
writeSourceToInput;
//
setLength(locs, 0);
fTempLines.LoadFromStream(fClient.Output);
if fTempLines.Count < 2 then
exit;
str := fTempLines[0];
// symbol is not in current module, too complex for now
if str.length < 6 then
exit;
if str[1..5] <> 'stdin' then
exit;
//
setLength(locs, fTempLines.count-1);
for i:= 1 to fTempLines.count-1 do
locs[i-1] := StrToIntDef(fTempLines[i], -1);
end;
{$ENDREGION} {$ENDREGION}
initialization initialization

View File

@ -97,17 +97,21 @@ inherited CEEditorWidget: TCEEditorWidget
object MenuItem7: TMenuItem object MenuItem7: TMenuItem
Caption = '-' Caption = '-'
end end
object mneEdComm: TMenuItem object mnuedComm: TMenuItem
Caption = 'Comment' Caption = 'Comment'
OnClick = mneEdCommClick OnClick = mnuedCommClick
end end
object mnEdInvAllNone: TMenuItem object mnuedInvAllNone: TMenuItem
Caption = 'Invert version all none' Caption = 'Invert version all none'
OnClick = mnEdInvAllNoneClick OnClick = mnuedInvAllNoneClick
end end
object MenuItem1: TMenuItem object MenuItem1: TMenuItem
Caption = '-' Caption = '-'
end end
object mnuedRename: TMenuItem
Caption = 'Rename identifier'
OnClick = mnuedRenameClick
end
object mnuedJum2Decl: TMenuItem object mnuedJum2Decl: TMenuItem
Caption = 'Jump to declaration' Caption = 'Jump to declaration'
OnClick = mnuedJum2DeclClick OnClick = mnuedJum2DeclClick

View File

@ -20,8 +20,9 @@ type
MenuItem2: TMenuItem; MenuItem2: TMenuItem;
MenuItem3: TMenuItem; MenuItem3: TMenuItem;
MenuItem5: TMenuItem; MenuItem5: TMenuItem;
mnEdInvAllNone: TMenuItem; mnuedRename: TMenuItem;
mneEdComm: TMenuItem; mnuedInvAllNone: TMenuItem;
mnuedComm: TMenuItem;
mnuedPrev: TMenuItem; mnuedPrev: TMenuItem;
mnuedNext: TMenuItem; mnuedNext: TMenuItem;
mnuedCallTip: TMenuItem; mnuedCallTip: TMenuItem;
@ -38,8 +39,9 @@ type
editorStatus: TStatusBar; editorStatus: TStatusBar;
mnuEditor: TPopupMenu; mnuEditor: TPopupMenu;
procedure MenuItem5Click(Sender: TObject); procedure MenuItem5Click(Sender: TObject);
procedure mnEdInvAllNoneClick(Sender: TObject); procedure mnuedRenameClick(Sender: TObject);
procedure mneEdCommClick(Sender: TObject); procedure mnuedInvAllNoneClick(Sender: TObject);
procedure mnuedCommClick(Sender: TObject);
procedure mnuedPrevClick(Sender: TObject); procedure mnuedPrevClick(Sender: TObject);
procedure mnuedNextClick(Sender: TObject); procedure mnuedNextClick(Sender: TObject);
procedure mnuedCallTipClick(Sender: TObject); procedure mnuedCallTipClick(Sender: TObject);
@ -141,6 +143,7 @@ begin
AssignPng(mnuedCopy.Bitmap, 'copy'); AssignPng(mnuedCopy.Bitmap, 'copy');
AssignPng(mnuedNext.Bitmap, 'go_next'); AssignPng(mnuedNext.Bitmap, 'go_next');
AssignPng(mnuedPrev.Bitmap, 'go_previous'); AssignPng(mnuedPrev.Bitmap, 'go_previous');
AssignPng(mnuedRename.Bitmap, 'pencil');
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.addSingleService(self); EntitiesConnector.addSingleService(self);
@ -577,7 +580,7 @@ begin
fDoc.showCallTips; fDoc.showCallTips;
end; end;
procedure TCEEditorWidget.mneEdCommClick(Sender: TObject); procedure TCEEditorWidget.mnuedCommClick(Sender: TObject);
begin begin
if fDoc.isNotNil then if fDoc.isNotNil then
fDoc.CommandProcessor(ecCommentSelection, '', nil); fDoc.CommandProcessor(ecCommentSelection, '', nil);
@ -595,7 +598,7 @@ begin
fDoc.CommandProcessor(ecNextLocation, '', nil); fDoc.CommandProcessor(ecNextLocation, '', nil);
end; end;
procedure TCEEditorWidget.mnEdInvAllNoneClick(Sender: TObject); procedure TCEEditorWidget.mnuedInvAllNoneClick(Sender: TObject);
begin begin
if fDoc.isNotNil then if fDoc.isNotNil then
fDoc.CommandProcessor(ecSwapVersionAllNone, '', nil); fDoc.CommandProcessor(ecSwapVersionAllNone, '', nil);
@ -619,6 +622,12 @@ begin
end; end;
end; end;
procedure TCEEditorWidget.mnuedRenameClick(Sender: TObject);
begin
if fDoc.isNotNil then
fDoc.CommandProcessor(ecRenameIdentifier, '', nil);
end;
procedure TCEEditorWidget.mnuedCutClick(Sender: TObject); procedure TCEEditorWidget.mnuedCutClick(Sender: TObject);
begin begin
if fDoc.isNotNil then if fDoc.isNotNil then

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc, Classes, SysUtils, controls,lcltype, Forms, graphics, ExtCtrls, crc,
SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText, SynEdit, SynPluginSyncroEdit, SynCompletion, SynEditKeyCmds, LazSynEditText,
SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView, SynHighlighterLFM, SynEditHighlighter, SynEditMouseCmds, SynEditFoldedView,
SynEditMarks, SynEditTypes, SynHighlighterJScript, SynEditMarks, SynEditTypes, SynHighlighterJScript, dialogs,
ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs, ce_common, ce_observer, ce_writableComponent, ce_d2syn, ce_txtsyn, ce_dialogs,
ce_sharedres, ce_dlang; ce_sharedres, ce_dlang;
@ -195,6 +195,7 @@ type
procedure save; procedure save;
procedure saveTempFile; procedure saveTempFile;
// //
procedure renameIdentifier;
procedure invertVersionAllNone; procedure invertVersionAllNone;
procedure showCallTips(findOpenParen: boolean = true); procedure showCallTips(findOpenParen: boolean = true);
procedure hideCallTips; procedure hideCallTips;
@ -245,6 +246,7 @@ const
ecCurlyBraceClose = ecUserFirst + 9; ecCurlyBraceClose = ecUserFirst + 9;
ecCommentSelection = ecUserFirst + 10; ecCommentSelection = ecUserFirst + 10;
ecSwapVersionAllNone = ecUserFirst + 11; ecSwapVersionAllNone = ecUserFirst + 11;
ecRenameIdentifier = ecUserFirst + 12;
var var
D2Syn: TSynD2Syn; // used as model to set the options when no editor exists. D2Syn: TSynD2Syn; // used as model to set the options when no editor exists.
@ -732,6 +734,7 @@ begin
AddKey(ecCurlyBraceClose, 0, [], 0, []); AddKey(ecCurlyBraceClose, 0, [], 0, []);
AddKey(ecCommentSelection, ord('/'), [ssCtrl], 0, []); AddKey(ecCommentSelection, ord('/'), [ssCtrl], 0, []);
AddKey(ecSwapVersionAllNone, 0, [], 0, []); AddKey(ecSwapVersionAllNone, 0, [], 0, []);
AddKey(ecRenameIdentifier, VK_F2, [ssCtrl], 0, []);
end; end;
end; end;
@ -749,6 +752,7 @@ begin
'ecCurlyBraceClose': begin Int := ecCurlyBraceClose; exit(true); end; 'ecCurlyBraceClose': begin Int := ecCurlyBraceClose; exit(true); end;
'ecCommentSelection': begin Int := ecCommentSelection; exit(true); end; 'ecCommentSelection': begin Int := ecCommentSelection; exit(true); end;
'ecSwapVersionAllNone': begin Int := ecSwapVersionAllNone; exit(true); end; 'ecSwapVersionAllNone': begin Int := ecSwapVersionAllNone; exit(true); end;
'ecRenameIdentifier': begin Int := ecRenameIdentifier; exit(true); end;
else exit(false); else exit(false);
end; end;
end; end;
@ -767,6 +771,7 @@ begin
ecCurlyBraceClose: begin Ident := 'ecCurlyBraceClose'; exit(true); end; ecCurlyBraceClose: begin Ident := 'ecCurlyBraceClose'; exit(true); end;
ecCommentSelection: begin Ident := 'ecCommentSelection'; exit(true); end; ecCommentSelection: begin Ident := 'ecCommentSelection'; exit(true); end;
ecSwapVersionAllNone: begin Ident := 'ecSwapVersionAllNone'; exit(true); end; ecSwapVersionAllNone: begin Ident := 'ecSwapVersionAllNone'; exit(true); end;
ecRenameIdentifier: begin Ident := 'ecRenameIdentifier'; exit(true); end;
else exit(false); else exit(false);
end; end;
end; end;
@ -936,6 +941,8 @@ begin
commentSelection(self); commentSelection(self);
ecSwapVersionAllNone: ecSwapVersionAllNone:
invertVersionAllNone; invertVersionAllNone;
ecRenameIdentifier:
renameIdentifier;
end; end;
if fOverrideColMode and not SelAvail then if fOverrideColMode and not SelAvail then
begin begin
@ -1004,6 +1011,43 @@ begin
end; end;
CaretXY := cp; CaretXY := cp;
end; end;
procedure TCESynMemo.renameIdentifier;
var
locs: TIntOpenArray = nil;
old, idt: string;
i, j, loc: integer;
c: char;
begin
if not DcdWrapper.available then
exit;
old := GetWordAtRowCol(LogicalCaretXY);
DcdWrapper.getLocalSymbolUsageFromCursor(locs);
if length(locs) = 0 then
begin
dlgOkInfo('Unknown, ambiguous or non-local symbol for "'+ old +'"');
exit;
end;
//
idt := 'new identifier for "' + old + '"';
idt := InputBox('Local identifier renaming', idt, '');
if idt.isEmpty or idt.isBlank then
exit;
//
for i:= high(locs) downto 0 do
begin
loc := locs[i];
if loc = -1 then
continue;
BeginUndoBlock;
SelStart := loc + 1;
for j in [0..old.length-1] do
ExecuteCommand(ecDeleteChar, '', nil);
for c in idt do
ExecuteCommand(ecChar, c, nil);
EndUndoBlock;
end;
end;
{$ENDREGION} {$ENDREGION}
{$REGION DDoc & CallTip --------------------------------------------------------} {$REGION DDoc & CallTip --------------------------------------------------------}