diff --git a/src/extensions/default/JavaScriptCodeHints/ScopeManager.js b/src/extensions/default/JavaScriptCodeHints/ScopeManager.js index f99fb5b2a0f..cad70a61da0 100644 --- a/src/extensions/default/JavaScriptCodeHints/ScopeManager.js +++ b/src/extensions/default/JavaScriptCodeHints/ScopeManager.js @@ -152,7 +152,7 @@ define(function (require, exports, module) { dir = split.dir, file = split.file; - var ternPromise = getJumptoDef(dir, file, offset, document.getText()); + var ternPromise = getJumptoDef(dir, file, offset, session.getJavascriptText()); return {promise: ternPromise}; } @@ -286,7 +286,7 @@ define(function (require, exports, module) { * @return {jQuery.Promise} - The promise will not complete until the tern * hints have completed. */ - function requestHints(session, document, offset) { + function requestHints(session, document) { var path = document.file.fullPath, split = HintUtils.splitPath(path), dir = split.dir, @@ -295,12 +295,14 @@ define(function (require, exports, module) { var $deferredHints = $.Deferred(), hintPromise, fnTypePromise, - propsPromise; + propsPromise, + text = session.getJavascriptText(), + offset = session.getOffset(); - hintPromise = getTernHints(dir, file, offset, document.getText()); + hintPromise = getTernHints(dir, file, offset, text); var sessionType = session.getType(); if (sessionType.property) { - propsPromise = getTernProperties(dir, file, offset, document.getText()); + propsPromise = getTernProperties(dir, file, offset, text); } else { var $propsDeferred = $.Deferred(); propsPromise = $propsDeferred.promise(); @@ -309,7 +311,7 @@ define(function (require, exports, module) { if (sessionType.showFunctionType) { // Show function sig - fnTypePromise = getTernFunctionType(dir, file, sessionType.functionCallPos, offset, document.getText()); + fnTypePromise = getTernFunctionType(dir, file, sessionType.functionCallPos, offset, text); } else { var $fnTypeDeferred = $.Deferred(); fnTypePromise = $fnTypeDeferred.promise(); diff --git a/src/extensions/default/JavaScriptCodeHints/Session.js b/src/extensions/default/JavaScriptCodeHints/Session.js index 163094e9db1..c4f43e0619e 100644 --- a/src/extensions/default/JavaScriptCodeHints/Session.js +++ b/src/extensions/default/JavaScriptCodeHints/Session.js @@ -21,13 +21,16 @@ * */ -/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ +/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */ /*global define, brackets, $ */ define(function (require, exports, module) { "use strict"; var StringMatch = brackets.getModule("utils/StringMatch"), + LanguageManager = brackets.getModule("language/LanguageManager"), + HTMLUtils = brackets.getModule("language/HTMLUtils"), + TokenUtils = brackets.getModule("utils/TokenUtils"), HintUtils = require("HintUtils"), ScopeManager = require("ScopeManager"); @@ -273,18 +276,30 @@ define(function (require, exports, module) { * function being called */ Session.prototype.getType = function () { + function getLexicalState(token) { + if (token.state.lexical) { + // in a javascript file this is just in the state field + return token.state.lexical; + } else if (token.state.localState && token.state.localState.lexical) { + // inline javascript in an html file will have this in + // the localState field + return token.state.localState.lexical; + } + } var propertyLookup = false, inFunctionCall = false, showFunctionType = false, context = null, cursor = this.getCursor(), functionCallPos, - token = this.getToken(cursor); + token = this.getToken(cursor), + lexical; if (token) { // if this token is part of a function call, then the tokens lexical info // will be annotated with "call" - if (token.state.lexical.info === "call") { + lexical = getLexicalState(token); + if (lexical.info === "call") { inFunctionCall = true; if (this.getQuery().length > 0) { inFunctionCall = false; @@ -301,7 +316,7 @@ define(function (require, exports, module) { // and it will prevent us from walking back thousands of lines if something went wrong. // there is nothing magical about 9 lines, and it can be adjusted if it doesn't seem to be // working well - var col = token.state.lexical.column, + var col = lexical.column, line, e, found; @@ -471,6 +486,51 @@ define(function (require, exports, module) { } return hints; }; + + /** + * Get the javascript text of the file open in the editor for this Session. + * For a javascript file, this is just the text of the file. For an HTML file, + * this will be only the text in the + + some stuff + + + +