mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
Function Hints
This commit is contained in:
1 parent
3855dc6757
commit
9e15de2eb7
12 files changed
+995
-138
No files matched your search
@@ -27,24 +27,24 @@
|
||||
define(function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
var CodeHintManager = brackets.getModule("editor/CodeHintManager"),
|
||||
EditorManager = brackets.getModule("editor/EditorManager"),
|
||||
DocumentManager = brackets.getModule("document/DocumentManager"),
|
||||
Commands = brackets.getModule("command/Commands"),
|
||||
CommandManager = brackets.getModule("command/CommandManager"),
|
||||
Menus = brackets.getModule("command/Menus"),
|
||||
Strings = brackets.getModule("strings"),
|
||||
AppInit = brackets.getModule("utils/AppInit"),
|
||||
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
|
||||
PerfUtils = brackets.getModule("utils/PerfUtils"),
|
||||
StringUtils = brackets.getModule("utils/StringUtils"),
|
||||
StringMatch = brackets.getModule("utils/StringMatch"),
|
||||
LanguageManager = brackets.getModule("language/LanguageManager"),
|
||||
ProjectManager = brackets.getModule("project/ProjectManager"),
|
||||
HintUtils = require("HintUtils"),
|
||||
ScopeManager = require("ScopeManager"),
|
||||
Session = require("Session"),
|
||||
Acorn = require("thirdparty/acorn/acorn");
|
||||
var CodeHintManager = brackets.getModule("editor/CodeHintManager"),
|
||||
EditorManager = brackets.getModule("editor/EditorManager"),
|
||||
DocumentManager = brackets.getModule("document/DocumentManager"),
|
||||
Commands = brackets.getModule("command/Commands"),
|
||||
CommandManager = brackets.getModule("command/CommandManager"),
|
||||
Menus = brackets.getModule("command/Menus"),
|
||||
AppInit = brackets.getModule("utils/AppInit"),
|
||||
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
|
||||
PerfUtils = brackets.getModule("utils/PerfUtils"),
|
||||
StringUtils = brackets.getModule("utils/StringUtils"),
|
||||
StringMatch = brackets.getModule("utils/StringMatch"),
|
||||
LanguageManager = brackets.getModule("language/LanguageManager"),
|
||||
ProjectManager = brackets.getModule("project/ProjectManager"),
|
||||
FunctionHintManager = require("FunctionHintManager"),
|
||||
HintUtils = require("HintUtils"),
|
||||
ScopeManager = require("ScopeManager"),
|
||||
Session = require("Session"),
|
||||
Acorn = require("thirdparty/acorn/acorn");
|
||||
|
||||
var session = null, // object that encapsulates the current session state
|
||||
cachedCursor = null, // last cursor of the current hinting session
|
||||
@@ -467,14 +467,9 @@ define(function (require, exports, module) {
|
||||
query = session.getQuery(),
|
||||
start = {line: cursor.line, ch: cursor.ch - query.length},
|
||||
end = {line: cursor.line, ch: cursor.ch},
|
||||
delimiter;
|
||||
invalidPropertyName = false,
|
||||
displayFunctionHint = false;
|
||||
|
||||
if (session.getType().showFunctionType) {
|
||||
// function types show up as hints, so don't insert anything
|
||||
// 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.
|
||||
@@ -482,9 +477,8 @@ define(function (require, exports, module) {
|
||||
// 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;
|
||||
|
||||
var currentToken = tokenizer();
|
||||
|
||||
// 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;
|
||||
@@ -508,6 +502,14 @@ define(function (require, exports, module) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the completion is for a valid function, then append
|
||||
// "()" to the function name.
|
||||
if (!invalidPropertyName && /^fn\(/.test(hint.type)) {
|
||||
completion = completion.concat("()");
|
||||
displayFunctionHint = true;
|
||||
}
|
||||
|
||||
// Replace the current token with the completion
|
||||
// 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
|
||||
@@ -515,11 +517,31 @@ define(function (require, exports, module) {
|
||||
// inline editors are open.
|
||||
session.editor._codeMirror.replaceRange(completion, start, end);
|
||||
|
||||
// If displaying a function hint, move the cursor inside the "()".
|
||||
// Then pop-up a function hint.
|
||||
if (displayFunctionHint) {
|
||||
var pos = {line: start.line, ch: start.ch + completion.length - 1};
|
||||
|
||||
// stop cursor tracking before setting the cursor to avoid bringing
|
||||
// down the current hint.
|
||||
if (FunctionHintManager.isFunctionHintDisplayed()) {
|
||||
FunctionHintManager.stopCursorTracking(session);
|
||||
}
|
||||
|
||||
session.editor._codeMirror.setCursor(pos);
|
||||
|
||||
if (FunctionHintManager.isFunctionHintDisplayed()) {
|
||||
FunctionHintManager.startCursorTracking(session);
|
||||
}
|
||||
|
||||
FunctionHintManager.popUpFunctionHint(FunctionHintManager.PUSH_EXISTING_HINT, hint.type);
|
||||
}
|
||||
|
||||
// Return false to indicate that another hinting session is not needed
|
||||
return false;
|
||||
};
|
||||
|
||||
// load the extension
|
||||
// load the extension
|
||||
AppInit.appReady(function () {
|
||||
|
||||
/*
|
||||
@@ -533,6 +555,7 @@ define(function (require, exports, module) {
|
||||
session = new Session(editor);
|
||||
ScopeManager.handleEditorChange(session, editor.document,
|
||||
previousEditor ? previousEditor.document : null);
|
||||
FunctionHintManager.setSession(session);
|
||||
cachedHints = null;
|
||||
}
|
||||
|
||||
@@ -556,6 +579,8 @@ define(function (require, exports, module) {
|
||||
}
|
||||
ignoreChange = false;
|
||||
});
|
||||
|
||||
FunctionHintManager.installFunctionHintListeners(editor);
|
||||
} else {
|
||||
session = null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user