forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParameterHintsProvider.js
More file actions
1 lines (1 loc) · 3.42 KB
/
Copy pathParameterHintsProvider.js
File metadata and controls
1 lines (1 loc) · 3.42 KB
1
define(function(require,exports,module){var ScopeManager=brackets.getModule("JSUtils/ScopeManager"),OVERWRITE_EXISTING_HINT=!1;function JSParameterHintsProvider(){this.hintState={},this.hintStack=[],this.preserveHintStack=null,this.session=null}JSParameterHintsProvider.prototype.setSession=function(value){this.session=value},JSParameterHintsProvider.prototype.isHintDisplayed=function(){return!0===this.hintState.visible},JSParameterHintsProvider.prototype.pushHintOnStack=function(){this.hintStack.push(this.hintState)},JSParameterHintsProvider.prototype.popHintFromStack=function(){return this.hintStack.length>0&&(this.hintState=this.hintStack.pop(),this.hintState.visible=!1,!0)},JSParameterHintsProvider.prototype.clearFunctionHintStack=function(){this.hintStack=[]},JSParameterHintsProvider.prototype.hasFunctionCallPosChanged=function(functionCallPos){var oldFunctionCallPos=this.hintState.functionCallPos;return void 0===oldFunctionCallPos||oldFunctionCallPos.line!==functionCallPos.line||oldFunctionCallPos.ch!==functionCallPos.ch},JSParameterHintsProvider.prototype.cleanHintState=function(){this.hintState.visible&&(this.preserveHintStack||this.clearFunctionHintStack())},JSParameterHintsProvider.prototype._getParameterHint=function(pushExistingHint,hint,functionInfo){var result=$.Deferred(),pushHint;if(!(functionInfo=functionInfo||this.session.getFunctionInfo()).inFunctionCall)return this.cleanHintState(),result.reject(null);if(this.hasFunctionCallPosChanged(functionInfo.functionCallPos))pushExistingHint&&this.isHintDisplayed()&&(this.pushHintOnStack(),this.preserveHintStack=!0),this.cleanHintState(),this.preserveHintStack=!1;else if(this.isHintDisplayed())return result.reject(null);this.hintState.functionCallPos=functionInfo.functionCallPos;var request=null;hint?(this.session.setFnType(hint),(request=$.Deferred()).resolveWith(null,[hint])):request=ScopeManager.requestParameterHint(this.session,functionInfo.functionCallPos);var self=this;return request.done(function(fnType){var hints=self.session.getParameterHint(functionInfo.functionCallPos);hints.functionCallPos=functionInfo.functionCallPos,result.resolve(hints)}).fail(function(){self.hintState={},result.reject(null)}),result},JSParameterHintsProvider.prototype.hasParameterHints=function(){var functionInfo;return this.session.getFunctionInfo().inFunctionCall},JSParameterHintsProvider.prototype.getParameterHints=function(explicit,onCursorActivity){var functionInfo=this.session.getFunctionInfo(),result=null;if(!onCursorActivity){if(functionInfo.inFunctionCall){var token=this.session.getToken();if(token&&"("===token.string||explicit)return this._getParameterHint()}else this.cleanHintState();return $.Deferred().reject(null)}if(!functionInfo.inFunctionCall)return this.cleanHintState(),$.Deferred().reject(null);if(this.hasFunctionCallPosChanged(functionInfo.functionCallPos))if(this.popHintFromStack()){var poppedFunctionCallPos=this.hintState.functionCallPos,currentFunctionCallPos=this.functionInfo.functionCallPos;if(poppedFunctionCallPos.line===currentFunctionCallPos.line&&poppedFunctionCallPos.ch===currentFunctionCallPos.ch)return this.preserveHintStack=!0,result=this._getParameterHint(!1,this.hintState.fnType,functionInfo),this.preserveHintStack=!1,result}else this.cleanHintState();var hints=this.session.getParameterHint(functionInfo.functionCallPos);return hints.functionCallPos=functionInfo.functionCallPos,$.Deferred().resolve(hints)},exports.JSParameterHintsProvider=JSParameterHintsProvider});