public ExpansionClient(ITextView textView, ITextBuffer textBuffer, IVsExpansionManager expansionManager, IExpansionsCache cache) { TextView = textView; TextBuffer = textBuffer; _expansionManager = expansionManager; _cache = cache; }
public static VsExpansion[] EnumerateExpansions(this IVsExpansionManager expansionManager, Guid language) { Contract.Requires(expansionManager != null); Contract.Ensures(Contract.Result <VsExpansion[]>() != null); return(expansionManager.EnumerateExpansions(language, null, false)); }
internal ExpansionsCache(IVsExpansionManager expansionManager) { // Caching language expansion structs requires access to the IVsExpansionManager // service which is valid on the main thread only. So we create cache on the main // thread so we can then access objects from background threads. CacheLanguageExpansionStructs(expansionManager); _instance = this; }
public ExpansionClient(ITextView textView, ITextBuffer textBuffer, IVsExpansionManager expansionManager, IExpansionsCache cache, IServiceContainer services) { TextView = textView; TextBuffer = textBuffer; _expansionManager = expansionManager; _cache = cache; _services = services; }
internal ExpansionsCache(IVsExpansionManager expansionManager, IServiceContainer services) { // Caching language expansion structs requires access to the IVsExpansionManager // service which is valid on the main thread only. So we create cache on the main // thread so we can then access objects from background threads. _instance = this; _services = services; IdleTimeAction.Create(() => CacheLanguageExpansionStructs(expansionManager), 200, typeof(ExpansionsCache), services.GetService <IIdleTimeService>()); }
private void GetSnippets(Guid languageGuid, ref ArrayList expansionsList) { IVsTextManager textManager = (IVsTextManager)Package.GetGlobalService(typeof(SVsTextManager)); if (textManager != null) { IVsTextManager2 textManager2 = (IVsTextManager2)textManager; if (textManager2 != null) { IVsExpansionManager expansionManager = null; textManager2.GetExpansionManager(out expansionManager); if (expansionManager != null) { // Tell the environment to fetch all of our snippets. IVsExpansionEnumeration expansionEnumerator = null; expansionManager.EnumerateExpansions(languageGuid, 0, // return all info null, // return all types 0, // return all types 1, // include snippets without types 0, // do not include duplicates out expansionEnumerator); if (expansionEnumerator != null) { // Cache our expansions in a VsExpansion array uint count = 0; uint fetched = 0; VsExpansion expansionInfo = new VsExpansion(); IntPtr[] pExpansionInfo = new IntPtr[1]; // Allocate enough memory for one VSExpansion structure. This memory is filled in by the Next method. pExpansionInfo[0] = Marshal.AllocCoTaskMem(Marshal.SizeOf(expansionInfo)); expansionEnumerator.GetCount(out count); for (uint i = 0; i < count; i++) { expansionEnumerator.Next(1, pExpansionInfo, out fetched); if (fetched > 0) { // Convert the returned blob of data into a structure that can be read in managed code. expansionInfo = (VsExpansion)Marshal.PtrToStructure(pExpansionInfo[0], typeof(VsExpansion)); if (!String.IsNullOrEmpty(expansionInfo.shortcut)) { expansionsList.Add(expansionInfo); } } } Marshal.FreeCoTaskMem(pExpansionInfo[0]); } } } } }
/// <summary> /// Caches expansions returned by IVsExpansionManager for a given language services. /// </summary> private void CacheLanguageExpansionStructs(IVsExpansionManager expansionManager) { if (_expansions.Keys.Count > 0) { return; } IVsExpansionEnumeration expansionEnumerator = null; int hr = expansionManager.EnumerateExpansions( RGuidList.RLanguageServiceGuid, 0, // return all info null, // return all types 0, // return all types 0, // do not return NULL type 0, // do not return duplicates out expansionEnumerator ); ErrorHandler.ThrowOnFailure(hr); if (expansionEnumerator != null) { VsExpansion expansion = new VsExpansion(); IntPtr[] pExpansionInfo = new IntPtr[1]; try { // Allocate enough memory for one VSExpansion structure. // This memory is filled in by the Next method. pExpansionInfo[0] = Marshal.AllocCoTaskMem(Marshal.SizeOf(expansion)); uint count = 0; expansionEnumerator.GetCount(out count); for (uint i = 0; i < count; i++) { uint fetched = 0; expansionEnumerator.Next(1, pExpansionInfo, out fetched); if (fetched > 0) { // Convert the returned blob of data into a structure. expansion = (VsExpansion)Marshal.PtrToStructure(pExpansionInfo[0], typeof(VsExpansion)); if (!string.IsNullOrEmpty(expansion.shortcut)) { _expansions[expansion.shortcut] = expansion; } } } } finally { if (pExpansionInfo[0] != null) { Marshal.FreeCoTaskMem(pExpansionInfo[0]); } } } }
public ExpansionsTest(IServiceContainer services) { _services = services; _expansionManager = Substitute.For <IVsExpansionManager>(); _cache = Substitute.For <IExpansionsCache>(); _cache.GetExpansion("if").Returns(new VsExpansion { description = "if statement", path = "path", shortcut = "if", title = "if statement" }); }
protected bool TryGetExpansionManager(out IVsExpansionManager expansionManager) { var textManager = (IVsTextManager2)ServiceProvider.GetService(typeof(SVsTextManager)); if (textManager == null) { expansionManager = null; return(false); } textManager.GetExpansionManager(out expansionManager); return(expansionManager != null); }
public ExpansionsTest() { _expansionManager = Substitute.For<IVsExpansionManager>(); _cache = Substitute.For<IExpansionsCache>(); _cache.GetExpansion("if").Returns(new VsExpansion() { description = "if statement", path = "path", shortcut = "if", title = "if statement" }); TextBufferUtilities.AdaptersFactoryService = new VsEditorAdaptersFactoryServiceMock(); }
/// <remarks> /// Changes to the <see cref="IVsExpansionManager.EnumerateExpansions"/> invocation /// should also be made to the IExpansionManager.EnumerateExpansionsAsync /// invocation in <see cref="PopulateSnippetCacheAsync(IExpansionManager)"/>. /// </remarks> private void PopulateSnippetCacheOnForeground(IVsExpansionManager expansionManager) { AssertIsForeground(); expansionManager.EnumerateExpansions( _languageGuidForSnippets, fShortCutOnly: 0, bstrTypes: null, iCountTypes: 0, fIncludeNULLType: 1, fIncludeDuplicates: 1, // Allows snippets with the same title but different shortcuts pEnum: out var expansionEnumerator); PopulateSnippetCacheFromExpansionEnumeration(expansionEnumerator); }
public ExpansionsTest() { _expansionManager = Substitute.For <IVsExpansionManager>(); _cache = Substitute.For <IExpansionsCache>(); _cache.GetExpansion("if").Returns(new VsExpansion() { description = "if statement", path = "path", shortcut = "if", title = "if statement" }); TextBufferUtilities.AdaptersFactoryService = new VsEditorAdaptersFactoryServiceMock(); }
public static VsExpansion[] EnumerateExpansions(this IVsExpansionManager expansionManager, Guid language, string[] snippetTypes, bool shortcutsOnly) { Contract.Requires <ArgumentNullException>(expansionManager != null, "expansionManager"); Contract.Ensures(Contract.Result <VsExpansion[]>() != null); bool includeNullType = false; bool includeDuplicates = false; IVsExpansionEnumeration expEnum = null; if (ErrorHandler.Succeeded(ErrorHandler.CallWithCOMConvention(() => expansionManager.EnumerateExpansions(language, shortcutsOnly ? 1 : 0, snippetTypes, snippetTypes.Length, includeNullType ? 1 : 0, includeDuplicates ? 1 : 0, out expEnum)))) { uint count; ErrorHandler.ThrowOnFailure(expEnum.GetCount(out count)); IntPtr[] raw = new IntPtr[count]; try { for (int i = 0; i < raw.Length; i++) { raw[i] = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VsExpansion))); } uint fetched; ErrorHandler.ThrowOnFailure(expEnum.Next(count, raw, out fetched)); VsExpansion[] results = new VsExpansion[fetched]; for (int i = 0; i < results.Length; i++) { if (raw[i] != IntPtr.Zero) { results[i] = (VsExpansion)Marshal.PtrToStructure(raw[i], typeof(VsExpansion)); } } return(results); } finally { foreach (IntPtr p in raw) { Marshal.FreeCoTaskMem(p); } } } return(new VsExpansion[0]); }
/// <summary>Returns S_OK if match found, S_FALSE if expansion UI is shown, and error otherwise</summary> internal virtual int FindExpansionByShortcut(IVsTextView view, string shortcut, TextSpan span, bool showDisambiguationUI, out string title, out string path) { if (this.expansionActive) { this.EndTemplateEditing(true); } this.view = view; title = path = null; LanguageService svc = this.source.LanguageService; IVsExpansionManager mgr = svc.Site.GetService(typeof(SVsExpansionManager)) as IVsExpansionManager; if (mgr == null) { return(NativeMethods.E_FAIL); } Guid guidLanguage = svc.GetLanguageServiceGuid(); TextSpan[] pts = new TextSpan[1]; pts[0] = span; int hr = mgr.GetExpansionByShortcut(this, guidLanguage, shortcut, this.TextView, pts, showDisambiguationUI ? 1 : 0, out path, out title); return(hr); }
public int GetExpansionManager(out IVsExpansionManager pExpansionManager) { pExpansionManager = this; return(VSConstants.S_OK); }
/// <include file='doc\ViewFilter.uex' path='docs/doc[@for="ViewFilter.RegisterTextViewEventHandlers"]/*' /> public virtual void RegisterExpansionManagerEventHandlers(IVsExpansionManager emgr) { this.expansionEvents = new NativeMethods.ConnectionPointCookie(emgr, this, typeof(IVsExpansionEvents)); }
public int GetExpansionManager(out IVsExpansionManager pExpansionManager) { pExpansionManager = new VsExpansionManagerMock(); return(VSConstants.S_OK); }
public static VsExpansion[] EnumerateExpansions([NotNull] this IVsExpansionManager expansionManager, Guid language) { Debug.Assert(expansionManager != null); return(expansionManager.EnumerateExpansions(language, null, false)); }
public ExpansionsController(ITextView textView, ITextBuffer textBuffer, IVsExpansionManager expansionManager, IExpansionsCache cache) { _textView = textView; _textBuffer = textBuffer; _expansionClient = new ExpansionClient(textView, textBuffer, expansionManager, cache); }
/// <remarks> /// Changes to the <see cref="IVsExpansionManager.EnumerateExpansions"/> invocation /// should also be made to the IExpansionManager.EnumerateExpansionsAsync /// invocation in <see cref="PopulateSnippetCacheAsync(IExpansionManager)"/>. /// </remarks> private void PopulateSnippetCacheOnForeground(IVsExpansionManager expansionManager) { AssertIsForeground(); IVsExpansionEnumeration expansionEnumerator = null; expansionManager.EnumerateExpansions( _languageGuidForSnippets, fShortCutOnly: 0, bstrTypes: null, iCountTypes: 0, fIncludeNULLType: 1, fIncludeDuplicates: 1, // Allows snippets with the same title but different shortcuts pEnum: out expansionEnumerator); PopulateSnippetCacheFromExpansionEnumeration(expansionEnumerator); }
public int GetExpansionManager(out IVsExpansionManager pExpansionManager) { pExpansionManager = new VsExpansionManagerMock(); return VSConstants.S_OK; }
public ExpansionsController(ITextView textView, ITextBuffer textBuffer, IVsExpansionManager expansionManager, IExpansionsCache cache, IServiceContainer services) { _textView = textView; _expansionClient = new ExpansionClient(textView, textBuffer, expansionManager, cache, services); _services = services; }