mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Basic support for code hinting in html files.
For HTML files, we replace the HTML sections with whitespace, leaving only the text of the script tags for Tern to see. This way the offset/cursor positions don't need to be translated, which would be necessary to get jump-to-def to work.
This commit is contained in:
1 parent
f083ad3111
commit
0755c30d58
3 files changed
+119
-9
No files matched your search
@@ -38,6 +38,7 @@ define(function (require, exports, module) {
|
||||
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
|
||||
StringUtils = brackets.getModule("utils/StringUtils"),
|
||||
StringMatch = brackets.getModule("utils/StringMatch"),
|
||||
LanguageManager = brackets.getModule("language/LanguageManager"),
|
||||
HintUtils = require("HintUtils"),
|
||||
ScopeManager = require("ScopeManager"),
|
||||
Session = require("Session");
|
||||
@@ -235,6 +236,18 @@ define(function (require, exports, module) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean} - true if the document is a html file
|
||||
*/
|
||||
function isHTMLFile(document) {
|
||||
var languageID = LanguageManager.getLanguageForPath(document.file.fullPath).getId();
|
||||
return languageID === "html";
|
||||
}
|
||||
|
||||
function isInlineScript(editor) {
|
||||
return editor.getModeForSelection() === "javascript";
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether hints are available for a given editor context
|
||||
*
|
||||
@@ -244,6 +257,12 @@ define(function (require, exports, module) {
|
||||
*/
|
||||
JSHints.prototype.hasHints = function (editor, key) {
|
||||
if (session && HintUtils.hintableKey(key)) {
|
||||
|
||||
if (isHTMLFile(session.editor.document)) {
|
||||
if (!isInlineScript(session.editor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
var cursor = session.getCursor(),
|
||||
token = session.getToken(cursor);
|
||||
|
||||
@@ -293,7 +312,7 @@ define(function (require, exports, module) {
|
||||
// type has changed since the last hint computation
|
||||
if (this.needNewHints(session)) {
|
||||
var offset = session.getOffset(),
|
||||
scopeResponse = ScopeManager.requestHints(session, session.editor.document, offset);
|
||||
scopeResponse = ScopeManager.requestHints(session, session.editor.document);
|
||||
|
||||
if (scopeResponse.hasOwnProperty("promise")) {
|
||||
var $deferredHints = $.Deferred();
|
||||
@@ -497,7 +516,7 @@ define(function (require, exports, module) {
|
||||
installEditorListeners(EditorManager.getActiveEditor());
|
||||
|
||||
var jsHints = new JSHints();
|
||||
CodeHintManager.registerHintProvider(jsHints, [HintUtils.LANGUAGE_ID], 0);
|
||||
CodeHintManager.registerHintProvider(jsHints, [HintUtils.LANGUAGE_ID, "html"], 0);
|
||||
|
||||
// for unit testing
|
||||
exports.getSession = getSession;
|
||||
|
||||
Reference in new issue
Block a user