Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 8f5be98

Browse files
niteskumboopeshmahendran
authored andcommitted
jsRefactor Rename Relative Path issue fixed (#14520)
* jsRefactor Rename Realtice Path issue fixed * Addressed review comments
1 parent fa00beb commit 8f5be98

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ define(function (require, exports, module) {
2929
Session = brackets.getModule("JSUtils/Session"),
3030
MessageIds = brackets.getModule("JSUtils/MessageIds"),
3131
TokenUtils = brackets.getModule("utils/TokenUtils"),
32-
Strings = brackets.getModule("strings");
32+
Strings = brackets.getModule("strings"),
33+
ProjectManager = brackets.getModule("project/ProjectManager");
3334

3435
var session = null, // object that encapsulates the current session state
3536
keywords = ["define", "alert", "exports", "require", "module", "arguments"];
@@ -97,8 +98,22 @@ define(function (require, exports, module) {
9798
var result = new $.Deferred();
9899

99100
function isInSameFile(obj, refsResp) {
101+
var projectRoot = ProjectManager.getProjectRoot(),
102+
projectDir,
103+
fileName = "";
104+
if (projectRoot) {
105+
projectDir = projectRoot.fullPath;
106+
}
107+
108+
// get the relative path of File as Tern can also return
109+
// references with file name as a relative path wrt projectRoot
110+
// so refernce file name will be compared with both relative and absolute path to check if it is same file
111+
if (projectDir && refsResp && refsResp.file && refsResp.file.indexOf(projectDir) === 0) {
112+
fileName = refsResp.file.slice(projectDir.length);
113+
}
100114
// In case of unsaved files, After renameing once Tern is returning filename without forward slash
101-
return (obj && (obj.file === refsResp.file || obj.file === refsResp.file.slice(1, refsResp.file.length)));
115+
return (obj && (obj.file === refsResp.file || obj.file === fileName
116+
|| obj.file === refsResp.file.slice(1, refsResp.file.length)));
102117
}
103118

104119
/**

0 commit comments

Comments
 (0)