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

jsRefactor Rename Relative Path issue fixed #14520

Merged
merged 2 commits into from
Aug 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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