Merge branch 'master' into html-script-hinting

Fixup branch so it will merge cleanly again.

Conflicts:
	src/extensions/default/JavaScriptCodeHints/unittests.js
This commit is contained in:
Erik Tierney committed 2013-05-03 14:50:57 -04:00
commit 84c239cf39
17 files changed
+427 -27

No files matched your search

@@ -41,7 +41,8 @@ define(function (require, exports, module) {
LanguageManager = brackets.getModule("language/LanguageManager"),
HintUtils = require("HintUtils"),
ScopeManager = require("ScopeManager"),
Session = require("Session");
Session = require("Session"),
Acorn = require("thirdparty/acorn/acorn");
var KeyboardPrefs = JSON.parse(require("text!keyboard.json"));
@@ -54,7 +55,6 @@ define(function (require, exports, module) {
cachedToken = null, // the token used in the current hinting session
matcher = null; // string matcher for hints
/**
* Get the value of current session.
* Used for unit testing.
@@ -395,8 +395,46 @@ define(function (require, exports, module) {
// if we were displaying a function type
return false;
}
if (session.getType().property) {
// if we're inserting a property name, we need to make sure the
// hint is a valid property name.
// to check this, run the hint through Acorns tokenizer
// it should result in one token, and that token should either be
// a 'name' or a 'keyword', as javascript allows keywords as property names
var tokenizer = Acorn.tokenize(completion);
var currentToken = tokenizer(),
invalidPropertyName = false;
// the name is invalid if the hint is not a 'name' or 'keyword' token
if (currentToken.type !== Acorn.tokTypes.name && !currentToken.type.keyword) {
invalidPropertyName = true;
} else {
// check for a second token - if there is one (other than 'eof')
// then the hint isn't a valid property name either
currentToken = tokenizer();
if (currentToken.type !== Acorn.tokTypes.eof) {
invalidPropertyName = true;
}
}
if (invalidPropertyName) {
// need to walk back to the '.' and replace
// with '["<hint>"]
var dotCursor = session.findPreviousDot();
if (dotCursor) {
completion = "[\"" + completion + "\"]";
start.line = dotCursor.line;
start.ch = dotCursor.ch - 1;
}
}
}
// Replace the current token with the completion
session.editor.document.replaceRange(completion, start, end);
// HACK (tracking adobe/brackets#1688): We talk to the private CodeMirror instance
// directly to replace the range instead of using the Document, as we should. The
// reason is due to a flaw in our current document synchronization architecture when
// inline editors are open.
session.editor._codeMirror.replaceRange(completion, start, end);
// Return false to indicate that another hinting session is not needed
return false;
@@ -411,11 +449,17 @@ define(function (require, exports, module) {
* information, and reject any pending deferred requests.
*
* @param {Editor} editor - editor context to be initialized.
* @param {boolean} primePump - true if the pump should be primed.
*/
function initializeSession(editor) {
function initializeSession(editor, primePump) {
ScopeManager.handleEditorChange(editor.document);
session = new Session(editor);
cachedHints = null;
// prime pump for hints so the first user request is fast
if (primePump) {
ScopeManager.requestHints(session, session.editor.document, 0);
}
}
/*
@@ -431,7 +475,7 @@ define(function (require, exports, module) {
cachedType = null;
if (editor && editor.getLanguageForSelection().getId() === HintUtils.LANGUAGE_ID) {
initializeSession(editor);
initializeSession(editor, true);
$(editor)
.on(HintUtils.eventName("change"), function () {
ScopeManager.handleFileChange(editor.document);