Skip to content

Commit 505ab4c

Browse files
committed
updated rename lib API
1 parent 91526fb commit 505ab4c

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

haxe_libraries/rename.hxml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxe-rename#19b2667de5d5302e6f3a7e650efcb7771d11082d" into rename/2.3.1/github/19b2667de5d5302e6f3a7e650efcb7771d11082d
2-
-cp ${HAXE_LIBCACHE}/rename/2.3.1/github/19b2667de5d5302e6f3a7e650efcb7771d11082d/src
1+
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxe-rename#7e161397241009b557c4c8e2edfbcd490b561b70" into rename/2.3.1/github/7e161397241009b557c4c8e2edfbcd490b561b70
2+
-cp ${HAXE_LIBCACHE}/rename/2.3.1/github/7e161397241009b557c4c8e2edfbcd490b561b70/src
33
-D rename=2.3.1

src/haxeLanguageServer/features/haxe/RenameFeature.hx

+2-34
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,7 @@ class RenameFeature {
5050
refactorCache.updateSingleFileCache(filePath.toString());
5151

5252
final editList:EditList = new EditList();
53-
refactor.Rename.canRename({
54-
nameMap: usageContext.nameMap,
55-
fileList: usageContext.fileList,
56-
typeList: usageContext.typeList,
57-
what: {
58-
fileName: filePath.toString(),
59-
toName: "",
60-
pos: refactorCache.converter.characterOffsetToByteOffset(doc.content, doc.offsetAt(params.position))
61-
},
62-
verboseLog: function(text:String, ?pos:PosInfos) {
63-
#if debug
64-
trace('[canRename] $text');
65-
#end
66-
},
67-
typer: refactorCache.typer
68-
}).then((result:CanRenameResult) -> {
53+
refactor.Rename.canRename(refactorCache.makeCanRenameContext(doc, filePath, params.position)).then((result:CanRenameResult) -> {
6954
if (result == null) {
7055
reject(ResponseError.internalError("cannot rename identifier"));
7156
}
@@ -95,24 +80,7 @@ class RenameFeature {
9580
refactorCache.updateFileCache();
9681

9782
final editList:EditList = new EditList();
98-
refactor.Rename.rename({
99-
nameMap: refactorCache.nameMap,
100-
fileList: refactorCache.fileList,
101-
typeList: refactorCache.typeList,
102-
what: {
103-
fileName: filePath.toString(),
104-
toName: params.newName,
105-
pos: refactorCache.converter.characterOffsetToByteOffset(doc.content, doc.offsetAt(params.position))
106-
},
107-
forRealExecute: true,
108-
docFactory: (filePath:String) -> new EditDoc(new FsPath(filePath), editList, context, refactorCache.converter),
109-
verboseLog: function(text:String, ?pos:PosInfos) {
110-
#if debug
111-
trace('[rename] $text');
112-
#end
113-
},
114-
typer: refactorCache.typer
115-
}).then((result:RefactorResult) -> {
83+
refactor.Rename.rename(refactorCache.makeRenameContext(doc, filePath, params.position, params.newName, editList)).then((result:RefactorResult) -> {
11684
endProgress();
11785
switch (result) {
11886
case NoChange:

src/haxeLanguageServer/features/haxe/refactoring/RefactorCache.hx

+50-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import refactor.discover.UsageCollector;
1515
import refactor.discover.UsageContext;
1616
import refactor.refactor.CanRefactorContext;
1717
import refactor.refactor.RefactorContext;
18+
import refactor.rename.CanRenameContext;
19+
import refactor.rename.RenameContext;
1820
import tokentree.TokenTree;
1921

2022
using haxeLanguageServer.helper.PathHelper;
@@ -23,8 +25,8 @@ class RefactorCache {
2325
final context:Context;
2426

2527
public final cache:IFileCache;
26-
public final converter:Haxe3DisplayOffsetConverter;
2728
public final typer:LanguageServerTyper;
29+
public final converter:Haxe3DisplayOffsetConverter;
2830
public final usageCollector:UsageCollector;
2931
public final nameMap:NameMap;
3032
public final fileList:FileList;
@@ -35,8 +37,8 @@ class RefactorCache {
3537
this.context = context;
3638

3739
cache = new MemCache();
38-
typer = new LanguageServerTyper(context);
3940
converter = new Haxe3DisplayOffsetConverter();
41+
typer = new LanguageServerTyper(context);
4042
usageCollector = new UsageCollector();
4143
nameMap = new NameMap();
4244
fileList = new FileList();
@@ -151,6 +153,52 @@ class RefactorCache {
151153
};
152154
}
153155

156+
public function makeCanRenameContext(doc:HaxeDocument, filePath:FsPath, position:Position):CanRenameContext {
157+
return {
158+
nameMap: nameMap,
159+
fileList: fileList,
160+
typeList: typeList,
161+
what: {
162+
fileName: filePath.toString(),
163+
toName: "",
164+
pos: converter.characterOffsetToByteOffset(doc.content, doc.offsetAt(position))
165+
},
166+
verboseLog: function(text:String, ?pos:PosInfos) {
167+
#if debug
168+
trace('[canRename] $text');
169+
#end
170+
},
171+
172+
typer: typer,
173+
fileReader: readFile,
174+
converter: converter.byteOffsetToCharacterOffset,
175+
};
176+
}
177+
178+
public function makeRenameContext(doc:HaxeDocument, filePath:FsPath, position:Position, newName:String, editList:EditList):RenameContext {
179+
return {
180+
nameMap: nameMap,
181+
fileList: fileList,
182+
typeList: typeList,
183+
what: {
184+
fileName: filePath.toString(),
185+
toName: newName,
186+
pos: converter.characterOffsetToByteOffset(doc.content, doc.offsetAt(position))
187+
},
188+
forRealExecute: true,
189+
docFactory: (filePath:String) -> new EditDoc(new FsPath(filePath), editList, context, converter),
190+
verboseLog: function(text:String, ?pos:PosInfos) {
191+
#if debug
192+
trace('[rename] $text');
193+
#end
194+
},
195+
196+
typer: typer,
197+
fileReader: readFile,
198+
converter: converter.byteOffsetToCharacterOffset,
199+
};
200+
}
201+
154202
public function makeCanRefactorContext(doc:Null<HaxeDocument>, range:Range):Null<CanRefactorContext> {
155203
if (doc == null) {
156204
return null;

0 commit comments

Comments
 (0)