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 1 commit
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
15 changes: 13 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 @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if ProjectManager.getProjectRoot() returns null

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fix typos

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)));
}

/**
Expand Down