void IHelpService.AddContextAttribute(string name, string value, HelpKeywordType keywordType) { if (_ServiceProvider != null) { IVsUserContext userContext = GetUserContext(); if (userContext != null) { VSUSERCONTEXTATTRIBUTEUSAGE usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; switch (keywordType) { case HelpKeywordType.F1Keyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; break; case HelpKeywordType.GeneralKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup; break; case HelpKeywordType.FilterKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter; break; } NativeMethods.ThrowOnFailure(userContext.AddAttribute(usage, name, value)); NotifyContextChange(userContext); } } }
/// <include file='doc\Task.uex' path='docs/doc[@for="Task.GetUserContext"]/*' /> public int GetUserContext(out IVsUserContext ppctx) { int hr = NativeMethods.S_OK; if (context == null) { // Create an empty context IVsMonitorUserContext monitorContext = owner.GetService(typeof(SVsMonitorUserContext)) as IVsMonitorUserContext; NativeMethods.ThrowOnFailure(monitorContext.CreateEmptyContext(out context)); // Add the required information to the context hr = context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1, contextNameKeyword, this.HelpKeyword); } ppctx = context; return(hr); }
// Help for functions and keywords. Initiated by pressing F1. public override void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context) { string searchingKeyword = null; // Search keyword as the function that presented where cursor stays or just before it Source source = (Source)this.GetSource(buffer); Debug.Assert(ptsSelection.Length > 0); int line = ptsSelection[0].iStartLine; int endPosition = ptsSelection[0].iEndIndex; var colorState = new DaxEditor.DaxFormatter.DummyColorState(); TokenInfo[] lineInfos = source.GetColorizer().GetLineInfo(buffer, line, colorState); foreach (var tokenInfo in lineInfos) { if (!(tokenInfo.Type == TokenType.Identifier || tokenInfo.Type == TokenType.Keyword)) { continue; } var span = new TextSpan(); span.iStartLine = line; span.iEndLine = line; span.iStartIndex = tokenInfo.StartIndex; span.iEndIndex = tokenInfo.EndIndex + 1; searchingKeyword = source.GetText(span); if (span.iEndIndex >= endPosition) { break; } } if (!string.IsNullOrEmpty(searchingKeyword)) { ErrorHandler.ThrowOnFailure(context.RemoveAttribute(null, null)); ErrorHandler.ThrowOnFailure(context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup, "keyword", "SQL11.AS.DAXREF." + searchingKeyword + ".F1")); } }
public int GetUserContext(out IVsUserContext ppctx) { // Common.Trace("Task.GetUserContext"); // set the user context if (userContext == null && helpKeyword != null && helpKeyword.Length > 0) { IVsMonitorUserContext monitor = Common.GetService(typeof(SVsMonitorUserContext)) as IVsMonitorUserContext; if (monitor != null) { int hr = monitor.CreateEmptyContext(out userContext); if (hr == 0 && userContext != null) { hr = userContext.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1, "keyword", helpKeyword); } if (hr != 0) { userContext = null; } } } ppctx = userContext; return(0); }
/// <include file='doc\HelpService.uex' path='docs/doc[@for="HelpService.AddContextAttribute"]/*' /> /// <devdoc> /// Adds a context attribute to the document. Context attributes are used /// to provide context-sensitive help to users. The designer host will /// automatically add context attributes from available help attributes /// on selected components and properties. This method allows you to /// further customize the context-sensitive help. /// </devdoc> public virtual void AddContextAttribute(string name, string value, HelpKeywordType keywordType) { if (provider == null) { return; } // First, get our context and update the attribute. // IVsUserContext cxt = GetUserContext(); if (cxt != null) { tagVsUserContextAttributeUsage usage = tagVsUserContextAttributeUsage.VSUC_Usage_LookupF1; switch (keywordType) { case HelpKeywordType.F1Keyword: usage = tagVsUserContextAttributeUsage.VSUC_Usage_LookupF1; break; case HelpKeywordType.GeneralKeyword: usage = tagVsUserContextAttributeUsage.VSUC_Usage_Lookup; break; case HelpKeywordType.FilterKeyword: usage = tagVsUserContextAttributeUsage.VSUC_Usage_Filter; break; } cxt.AddAttribute(usage, name, value); // Then notify the shell that it has been updated. // NotifyContextChange(cxt); } }
/// <devdoc> /// Adds a context attribute to the document. Context attributes are used /// to provide context-sensitive help to users. The designer host will /// automatically add context attributes from available help attributes /// on selected components and properties. This method allows you to /// further customize the context-sensitive help. /// </devdoc> void IHelpService.AddContextAttribute(string name, string value, HelpKeywordType keywordType) { if (provider == null) { return; } // First, get our context and update the attribute. // IVsUserContext cxt = GetUserContext(); if (cxt != null) { VSUSERCONTEXTATTRIBUTEUSAGE usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; switch (keywordType) { case HelpKeywordType.F1Keyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1; break; case HelpKeywordType.GeneralKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Lookup; break; case HelpKeywordType.FilterKeyword: usage = VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter; break; } NativeMethods.ThrowOnFailure(cxt.AddAttribute(usage, name, value)); // Then notify the shell that it has been updated. // NotifyContextChange(cxt); } }
internal virtual int UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context) { // From the docs: Any failure code: means the implementer is "passing" on this opportunity to provide context and the text editor will fall back to other mechanisms. if (ptsSelection == null || ptsSelection.Length != 1) return NativeMethods.E_FAIL; context.RemoveAttribute(null, null); TextSpan span = ptsSelection[0]; IVsTextLines lastActiveBuffer; IVsTextView lastAciveView = this.LastActiveTextView; if (lastActiveView == null) return NativeMethods.E_FAIL; NativeMethods.ThrowOnFailure(lastActiveView.GetBuffer(out lastActiveBuffer)); if (lastActiveBuffer != buffer) return NativeMethods.E_FAIL; ISource source = GetSource(buffer); if (source == null) return NativeMethods.E_FAIL; var req = source.BeginBackgroundRequest(span.iStartLine, span.iStartIndex, new TokenInfo(), BackgroundRequestReason.FullTypeCheck, lastActiveView, RequireFreshResults.No, new BackgroundRequestResultHandler(this.HandleUpdateLanguageContextResponse)); if (req == null || req.Result == null) return NativeMethods.E_FAIL; if ((req.IsSynchronous || ((req.Result != null) && req.Result.TryWaitForBackgroundRequestCompletion(1000)))) { if (req.IsAborted) return NativeMethods.E_FAIL; if (req.ResultScope != null) { req.ResultScope.GetF1KeywordString(span, context); return NativeMethods.S_OK; } } else // result is asynchronous and have not completed within 1000 ms { context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_Filter, "devlang", "fsharp"); context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1_CaseSensitive, "keyword", "fsharp.typechecking.incomplete"); return NativeMethods.S_OK; } return NativeMethods.E_FAIL; }