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

Commit

Permalink
jsRefactor Rename Relative Path issue fixed (#14520)
Browse files Browse the repository at this point in the history
* jsRefactor Rename Realtice Path issue fixed

* Addressed review comments
  • Loading branch information
niteskum authored and boopeshmahendran committed Aug 27, 2018
1 parent fa00beb commit 8f5be98
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/extensions/default/JavaScriptRefactoring/RenameIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -97,8 +98,22 @@ define(function (require, exports, module) {
var result = new $.Deferred();

function isInSameFile(obj, refsResp) {
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 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 === refsResp.file.slice(1, refsResp.file.length)));
return (obj && (obj.file === refsResp.file || obj.file === fileName
|| obj.file === refsResp.file.slice(1, refsResp.file.length)));
}

/**
Expand Down

0 comments on commit 8f5be98

Please sign in to comment.