//private bool isHelpContextSet = false; public override void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, Microsoft.VisualStudio.Shell.Interop.IVsUserContext context) { // WOULD HAVE BEEN NICE TO HAVE HELP, BUT SEEMS TO BE A LONG WAY TO CREATE AN HXS HELP FILE //if (isHelpContextSet) //{ // context.RemoveAttribute("keyword", "mov"); // isHelpContextSet = false; //} //else //{ // context.AddAttribute(VSUSERCONTEXTATTRIBUTEUSAGE.VSUC_Usage_LookupF1, "keyword", "mov"); // isHelpContextSet = true; //} }
// 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")); } }
/// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.UpdateLanguageContext"]/*' /> public virtual void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context) { }
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; }
public virtual void UpdateLanguageContext(LanguageContextHint hint, IVsTextLines buffer, TextSpan[] ptsSelection, IVsUserContext context);