Added Goto Definition.

This commit is contained in:
jeffkenton committed 2013-04-08 15:50:11 -04:00
1 parent bef501fda0
commit af9a7f01ab
6 files changed
+153 -1

No files matched your search

@@ -102,6 +102,49 @@ importScripts("thirdparty/requirejs/require.js");
return request;
}
/**
* Get definition location
* @param {string} dir - the directory
* @param {string} file - the file name
* @param {number} offset - the offset into the file for cursor
* @param {string} text - the text of the file
*/
function getJumptoDef(dir, file, offset, text) {
function buildRequest(dir, file, query, offset){
query = {type:query};
query.start = offset;
query.end = offset;
query.file = file;
query.filter = false;
query.sort = false;
query.depths = true;
query.types = true;
query.lineCharPositions = true;
var request = {query:query, files:[], offset:offset};
request.files.push({type:"full", name:file, text:text});
return request;
}
var request = buildRequest(dir, file, "definition", offset);
ternServer.request(request, function(error, data) {
if (error) {
_log("definition error: " + JSON.stringify(data));
self.postMessage({type: HintUtils.TERN_JUMPTODEF_MSG,});
return;
}
// Post a message back to the main thread with the definition
self.postMessage({type: HintUtils.TERN_JUMPTODEF_MSG,
file: data.file,
start: data.start,
end: data.end
});
});
}
/**
* Get the completions for the given offset
@@ -232,9 +275,15 @@ importScripts("thirdparty/requirejs/require.js");
text = request.text;
var pos = request.pos;
handleFunctionType(dir, file, pos, text);
} else if ( type === HintUtils.TERN_JUMPTODEF_MSG ) {
var file = request.file,
dir = request.dir,
offset = request.offset,
text = request.text;
getJumptoDef(dir, file, offset, text);
} else {
_log("Unknown message: " + JSON.stringify(request));
}
});
}());
}());