mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Remember the resolved path we used with tern so that jump to definition across files work. Also clean-up some error conditions when the definition location is not known.
This commit is contained in:
1 parent
aeee6aaa06
commit
ec9a5afa83
2 files changed
+27
-19
No files matched your search
@@ -46,6 +46,7 @@ define(function (require, exports, module) {
|
||||
rootTernDir = null,
|
||||
projectRoot = null,
|
||||
ternPromise = null,
|
||||
resolvedFiles = {}, // file -> resolved file
|
||||
_ternWorker = (function () {
|
||||
var path = module.uri.substring(0, module.uri.lastIndexOf("/") + 1);
|
||||
return new Worker(path + "tern-worker.js");
|
||||
@@ -355,6 +356,14 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} file a relative path
|
||||
* @return {string} returns the path we resolved when we tried to parse the file, or undefined
|
||||
*/
|
||||
function getResolvedPath(file) {
|
||||
return resolvedFiles[file];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a request from the worker for text of a file
|
||||
*
|
||||
@@ -373,12 +382,14 @@ define(function (require, exports, module) {
|
||||
|
||||
var name = request.file;
|
||||
DocumentManager.getDocumentForPath(rootTernDir + name).done(function(document){
|
||||
resolvedFiles[name] = rootTernDir + name;
|
||||
replyWith(name, document.getText());
|
||||
})
|
||||
.fail(function(){
|
||||
if (projectRoot) {
|
||||
// Try relative to project root
|
||||
DocumentManager.getDocumentForPath(projectRoot + name).done(function(document) {
|
||||
resolvedFiles[name] = projectRoot + name;
|
||||
replyWith(name, document.getText());
|
||||
})
|
||||
.fail(function(){
|
||||
@@ -409,6 +420,7 @@ define(function (require, exports, module) {
|
||||
var ternDeferred = $.Deferred();
|
||||
ternPromise = ternDeferred.promise();
|
||||
pendingTernRequests = [];
|
||||
resolvedFiles = {};
|
||||
projectRoot = ProjectManager.getProjectRoot() ? ProjectManager.getProjectRoot().fullPath : null;
|
||||
reader.readEntries(function (entries) {
|
||||
entries.slice(0, MAX_FILES_IN_DIR).forEach(function (entry) {
|
||||
@@ -495,4 +507,5 @@ define(function (require, exports, module) {
|
||||
exports.requestJumptoDef = requestJumptoDef;
|
||||
exports.requestHints = requestHints;
|
||||
exports.getTernHints = getTernHints;
|
||||
exports.getResolvedPath = getResolvedPath;
|
||||
});
|
||||
@@ -396,29 +396,24 @@ define(function (require, exports, module) {
|
||||
if (response.hasOwnProperty("promise")) {
|
||||
response.promise.done(function (jumpResp) {
|
||||
|
||||
if (jumpResp.resultFile && (jumpResp.resultFile !== jumpResp.file)) {
|
||||
|
||||
var doc = DocumentManager.getCurrentDocument();
|
||||
var x = doc.file.fullPath.lastIndexOf("/");
|
||||
var dir;
|
||||
if (x >= 0) {
|
||||
dir = doc.file.fullPath.slice(0, x + 1);
|
||||
if (jumpResp.resultFile) {
|
||||
if (jumpResp.resultFile !== jumpResp.file) {
|
||||
var resolvedPath = ScopeManager.getResolvedPath(jumpResp.resultFile);
|
||||
if (resolvedPath) {
|
||||
CommandManager.execute(Commands.FILE_OPEN, {fullPath: resolvedPath})
|
||||
.done(function() {
|
||||
session.editor.setCursorPos(jumpResp.start);
|
||||
session.editor.setSelection(jumpResp.start, jumpResp.end);
|
||||
session.editor.centerOnCursor();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
dir = "";
|
||||
session.editor.setCursorPos(jumpResp.start);
|
||||
session.editor.setSelection(jumpResp.start, jumpResp.end);
|
||||
session.editor.centerOnCursor();
|
||||
}
|
||||
CommandManager.execute(Commands.FILE_OPEN, { fullPath: dir+jumpResp.resultFile })
|
||||
.done(function() {
|
||||
session.editor.setCursorPos(jumpResp.start);
|
||||
session.editor.setSelection(jumpResp.start, jumpResp.end);
|
||||
session.editor.centerOnCursor();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
session.editor.setCursorPos(jumpResp.start);
|
||||
session.editor.setSelection(jumpResp.start, jumpResp.end);
|
||||
session.editor.centerOnCursor();
|
||||
|
||||
}).fail(function () {
|
||||
response.reject();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user