mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Add support for hinting function types.
When in a function call, display the function type instead of the normal hints. This only happens when nothing has been entered by the user - if the user starts typing, then we switch back to the normal hints based on what the user has typed. This also requires a new version of CodeMirror that brackets has not updated to. The old hints continue to work without the new version, but the function types will only work once codemirror is updated.
This commit is contained in:
1 parent
08f356c649
commit
63c89f4d62
5 files changed
+201
-40
No files matched your search
@@ -85,6 +85,23 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
}
|
||||
|
||||
function buildRequest(dir, file, query, offset, text){
|
||||
query = {type:query};
|
||||
query.start = offset;
|
||||
query.end = offset;
|
||||
query.file = file;
|
||||
query.filter = false;
|
||||
query.sort = false;
|
||||
query.depths = true;
|
||||
query.types = true;
|
||||
|
||||
var request = {query:query, files:[], offset:offset};
|
||||
request.files.push({type:"full", name:file, text:text});
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the completions for the given offset
|
||||
* @param {string} dir - the directory
|
||||
@@ -94,23 +111,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
*/
|
||||
function getTernHints(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;
|
||||
|
||||
var request = {query:query, files:[], offset:offset};
|
||||
request.files.push({type:"full", name:file, text:text});
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
var request = buildRequest(dir, file, "completions", offset);
|
||||
var request = buildRequest(dir, file, "completions", offset, text);
|
||||
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
|
||||
ternServer.request(request, function(error, data) {
|
||||
//if (error) return displayError(error);
|
||||
@@ -131,6 +132,33 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function type for the given offset
|
||||
* @param {string} dir - the directory
|
||||
* @param {string} file - the file name
|
||||
* @param {number} offset - the offset into the file where we want completions for
|
||||
* @param {string} text - the text of the file
|
||||
*/
|
||||
function handleFunctionType(dir, file, pos, text) {
|
||||
|
||||
var request = buildRequest(dir, file, "type", pos, text);
|
||||
|
||||
request.preferFunction = true;
|
||||
|
||||
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
|
||||
ternServer.request(request, function(error, data) {
|
||||
//if (error) return displayError(error);
|
||||
var fnType = data.type;
|
||||
|
||||
// Post a message back to the main thread with the completions
|
||||
self.postMessage({type: HintUtils.TERN_CALLED_FUNC_TYPE_MSG,
|
||||
dir: dir,
|
||||
file: file,
|
||||
fnType: fnType
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a log message back from the worker to the main thread
|
||||
@@ -163,6 +191,12 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
var file = request.file,
|
||||
text = request.text;
|
||||
handleGetFile(file, text);
|
||||
} else if ( type === HintUtils.TERN_CALLED_FUNC_TYPE_MSG ) {
|
||||
var file = request.file,
|
||||
text = request.text,
|
||||
dir = request.dir,
|
||||
pos = request.pos;
|
||||
handleFunctionType(dir, file, pos, text);
|
||||
} else {
|
||||
_log("Unknown message: " + JSON.stringify(request));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user