mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Hook up initial requirejs support.
Sync to new version of tern, which has support for simplified common JS modules, which brackets uses. Enable the requirejs tern plugin. Had to modify how we deal with file paths a bit - we were leaving in the leading '/', which made things look like an absolute path, and then tern would view '/test.js' as a different file than 'test.js'. Some cleanup - add logging for errors from tern, delete some old commented out code.
This commit is contained in:
1 parent
7d52361aa7
commit
87de92de12
4 files changed
+26
-13
No files matched your search
@@ -95,7 +95,7 @@ define(function (require, exports, module) {
|
||||
function splitPath(path) {
|
||||
var index = path.lastIndexOf("/"),
|
||||
dir = path.substring(0, index),
|
||||
file = path.substring(index, path.length);
|
||||
file = path.substring(index+1, path.length);
|
||||
|
||||
return {dir: dir, file: file };
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ define(function (require, exports, module) {
|
||||
files : files,
|
||||
env : ternEnvironment
|
||||
});
|
||||
rootTernDir = dir;
|
||||
rootTernDir = dir + "/";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -381,6 +381,15 @@ define(function (require, exports, module) {
|
||||
file:name,
|
||||
text:document.getText()
|
||||
});
|
||||
})
|
||||
.fail(function(){
|
||||
// Need to send something back to tern - it will wait
|
||||
// until all the files have been retrieved before doing its calculations
|
||||
ternWorker.postMessage({
|
||||
type:HintUtils.TERN_GET_FILE_MSG,
|
||||
file:name,
|
||||
text:""
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Submodule src/extensions/default/JavaScriptCodeHints/tern updated: 27f31a9a72...77006d7186.
@@ -31,7 +31,7 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
|
||||
var HintUtils;
|
||||
var Tern;
|
||||
require(["./HintUtils", "./tern/tern"], function(hintUtils, tern) {
|
||||
require(["./HintUtils", "./tern/tern", "./tern/plugin/requirejs"], function(hintUtils, tern, requirejs) {
|
||||
HintUtils = hintUtils;
|
||||
Tern = tern;
|
||||
} );
|
||||
@@ -75,7 +75,8 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
var ternOptions = {
|
||||
defs:env,
|
||||
async:true,
|
||||
getFile: getFile
|
||||
getFile: getFile,
|
||||
plugins: {requirejs: {}}
|
||||
};
|
||||
ternServer = new Tern.Server(ternOptions);
|
||||
|
||||
@@ -141,13 +142,14 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
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);
|
||||
//_log("completions = " + data.completions.length);
|
||||
if (error) {
|
||||
_log("Error: " + error);
|
||||
return;
|
||||
}
|
||||
var completions = [];
|
||||
for (var i = 0; i < data.completions.length; ++i) {
|
||||
var completion = data.completions[i];//, className = typeToIcon(completion.type);
|
||||
//if (data.guess) className += " Tern-completion-guess";
|
||||
completions.push({value: completion.name, depth: completion.depth, guess: completion.guess});
|
||||
var completion = data.completions[i];
|
||||
completions.push({value: completion.name, type: completion.type, depth: completion.depth, guess: completion.guess});
|
||||
}
|
||||
|
||||
// Post a message back to the main thread with the completions
|
||||
@@ -171,12 +173,14 @@ importScripts("thirdparty/requirejs/require.js");
|
||||
var request = buildRequest(dir, file, "properties", undefined, text);
|
||||
//_log("request " + request.type + dir + " " + file);
|
||||
ternServer.request(request, function(error, data) {
|
||||
//if (error) return displayError(error);
|
||||
if (error) {
|
||||
_log("Error: " + error);
|
||||
return;
|
||||
}
|
||||
//_log("completions = " + data.completions.length);
|
||||
var properties = [];
|
||||
for (var i = 0; i < data.completions.length; ++i) {
|
||||
var property = data.completions[i];//, className = typeToIcon(completion.type);
|
||||
//if (data.guess) className += " Tern-completion-guess";
|
||||
var property = data.completions[i];
|
||||
properties.push({value: property, guess: true});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user