From 5768dec3a7653c44cee0bafe1ec5347042401b31 Mon Sep 17 00:00:00 2001 From: niteskum Date: Fri, 24 Aug 2018 16:11:50 +0530 Subject: [PATCH 1/2] jsRefactor Rename Realtice Path issue fixed --- .../JavaScriptRefactoring/RenameIdentifier.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js b/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js index 13448e9e6bb..8d7b1be61e8 100644 --- a/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js +++ b/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js @@ -29,7 +29,8 @@ define(function (require, exports, module) { Session = brackets.getModule("JSUtils/Session"), MessageIds = brackets.getModule("JSUtils/MessageIds"), TokenUtils = brackets.getModule("utils/TokenUtils"), - Strings = brackets.getModule("strings"); + Strings = brackets.getModule("strings"), + ProjectManager = brackets.getModule("project/ProjectManager"); var session = null, // object that encapsulates the current session state keywords = ["define", "alert", "exports", "require", "module", "arguments"]; @@ -98,7 +99,17 @@ define(function (require, exports, module) { function isInSameFile(obj, refsResp) { // In case of unsaved files, After renameing once Tern is returning filename without forward slash - return (obj && (obj.file === refsResp.file || obj.file === refsResp.file.slice(1, refsResp.file.length))); + var projectDir = ProjectManager.getProjectRoot().fullPath, + fileName = ""; + + // get the relative path of File as Tern can also return + // references with file name as a relative path wrt projectRoot + // so refernce file will be compared with both relative and Absolute path ti check if it is same file + if (projectDir && refsResp && refsResp.file && refsResp.file.indexOf(projectDir) === 0) { + fileName = refsResp.file.slice(projectDir.length); + } + return (obj && (obj.file === refsResp.file || obj.file === fileName + || obj.file === refsResp.file.slice(1, refsResp.file.length))); } /** From d693d1c2f57c15956fd22d946d557f4d7a77be93 Mon Sep 17 00:00:00 2001 From: niteskum Date: Mon, 27 Aug 2018 18:57:58 +0530 Subject: [PATCH 2/2] Addressed review comments --- .../default/JavaScriptRefactoring/RenameIdentifier.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js b/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js index 8d7b1be61e8..6fa53b5f48e 100644 --- a/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js +++ b/src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js @@ -98,16 +98,20 @@ define(function (require, exports, module) { var result = new $.Deferred(); function isInSameFile(obj, refsResp) { - // In case of unsaved files, After renameing once Tern is returning filename without forward slash - var projectDir = ProjectManager.getProjectRoot().fullPath, + var projectRoot = ProjectManager.getProjectRoot(), + projectDir, fileName = ""; + if (projectRoot) { + projectDir = projectRoot.fullPath; + } // get the relative path of File as Tern can also return // references with file name as a relative path wrt projectRoot - // so refernce file will be compared with both relative and Absolute path ti check if it is same file + // so refernce file name will be compared with both relative and absolute path to check if it is same file if (projectDir && refsResp && refsResp.file && refsResp.file.indexOf(projectDir) === 0) { fileName = refsResp.file.slice(projectDir.length); } + // In case of unsaved files, After renameing once Tern is returning filename without forward slash return (obj && (obj.file === refsResp.file || obj.file === fileName || obj.file === refsResp.file.slice(1, refsResp.file.length))); }