//todo:尽在apsx下面才有效,cs文件下无效,不知道为什么 public void ToggleRegions() { IVsHiddenTextSession session = HiddenTextSession; TextSpan[] aspan = new TextSpan[1]; aspan[0] = new VSTextView(VSTextView.ActiveTextView).GetWholeTextSpan(); //获取IVsEnumHiddenRegions IVsEnumHiddenRegions ppenum; session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_ALL_REGIONS, 0, aspan, out ppenum); MessageBox.Show(GetHiddenRegionCount(ppenum).ToString()); //遍历IVsEnumHiddenRegions uint fetched; IVsHiddenRegion[] aregion = new IVsHiddenRegion[1]; while (ppenum.Next(1, aregion, out fetched) == VSConstants.S_OK && fetched == 1) { uint dwState; aregion[0].GetState(out dwState); dwState ^= (uint)HIDDEN_REGION_STATE.hrsExpanded; aregion[0].SetState(dwState, (uint)CHANGE_HIDDEN_REGION_FLAGS.chrDefault); } }
public void CreateHiddenRegion(string bannerText, TextSpan ts) { IVsHiddenTextSession session = HiddenTextSession; if (session != null) { NewHiddenRegion[] NewHiddenRegionArray = new NewHiddenRegion[1]; NewHiddenRegionArray[0].dwBehavior = (uint)HIDDEN_REGION_BEHAVIOR.hrbClientControlled; //NewHiddenRegionArray[0].dwClient = 0x2cff; NewHiddenRegionArray[0].dwState = (uint)HIDDEN_REGION_STATE.hrsDefault; NewHiddenRegionArray[0].iType = (int)HIDDEN_REGION_TYPE.hrtCollapsible; NewHiddenRegionArray[0].pszBanner = bannerText; NewHiddenRegionArray[0].tsHiddenText = ts; int isOk = session.AddHiddenRegions( (uint)CHANGE_HIDDEN_REGION_FLAGS.chrDefault, 1, NewHiddenRegionArray, null); if (isOk != VSConstants.S_OK) { MessageBox.Show("error"); } } }
public IVsEnumHiddenRegions GetEnumHiddenRegions() { IVsHiddenTextSession session = HiddenTextSession; if (session != null) { IVsEnumHiddenRegions ppenum; session.EnumHiddenRegions((uint)FIND_HIDDEN_REGION_FLAGS.FHR_ALL_REGIONS, 0, null, out ppenum); return(ppenum); } return(null); }
private IVsHiddenTextSession GetHiddenTextSession(IVsTextView view) { if (view == null) { return(null); } IVsTextLines txtLine; view.GetBuffer(out txtLine); hiddenTextSession = null; //每个session都与特定的Textbuffer关联,这里默认是当前窗口的buffer HiddenTextManager.GetHiddenTextSession(txtLine, out hiddenTextSession); if (hiddenTextSession == null) { HiddenTextManager.CreateHiddenTextSession(0, txtLine, /* hiddenTextClient */ hiddenTextClient, out hiddenTextSession); } return(hiddenTextSession); }
public static IList <TextSpan> GetAllHiddenRegions(this IVsHiddenTextSession hiddenTextSession, TextSpan searchRange) { var pSearchRange = new TextSpan[1]; pSearchRange[0] = searchRange; IVsEnumHiddenRegions enumHiddenRegions; hiddenTextSession.EnumHiddenRegions( (uint)FIND_HIDDEN_REGION_FLAGS.FHR_ALL_REGIONS, 0, // dwCookie for custom regions, not used here pSearchRange, out enumHiddenRegions ); if (enumHiddenRegions != null) { return(enumHiddenRegions.GetHiddenRegions()); } return(null); }
// Produces tags on the snapshot that the tag consumer asked for. public IEnumerable <ITagSpan <DocumentationTag> > GetTags(NormalizedSnapshotSpanCollection spans) { var documentation = Services.DocumentationFileSerializer.Deserialize(_codyDocsFilename); List <ITagSpan <DocumentationTag> > res = new List <ITagSpan <DocumentationTag> >(); var currentSnapshot = _buffer.CurrentSnapshot; var hiddenTextManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsTextManager)) as IVsHiddenTextManager; var service = ServiceProvider.GlobalProvider.GetService(typeof(SVsTextManager)); var textManager = service as IVsTextManager2; IVsTextView view; int result = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view); IVsHiddenTextSession hiddenSession = null; IVsEnumHiddenRegions[] hiddenRegions = null; int hRetVal = hiddenTextManager.GetHiddenTextSession( _buffer, out hiddenSession); if (hRetVal != 0) { hRetVal = hiddenTextManager.CreateHiddenTextSession( 0, _buffer, null, out hiddenSession); } if (hiddenSession != null) { foreach (var fragment in documentation.Fragments) { int startPos = fragment.Selection.StartPosition; int length = fragment.Selection.EndPosition - fragment.Selection.StartPosition; var snapshotSpan = new SnapshotSpan( currentSnapshot, new Span(startPos, length)); view.GetLineAndColumn(fragment.Selection.StartPosition, out int startLine, out int startIdx); view.GetLineAndColumn(fragment.Selection.EndPosition, out int endLine, out int endIdx); var hidRegion = new NewHiddenRegion() { dwBehavior = (uint)HIDDEN_REGION_BEHAVIOR.hrbClientControlled, dwState = (uint)HIDDEN_REGION_STATE.hrsDefault, iType = (int)HIDDEN_REGION_TYPE.hrtConcealed, pszBanner = fragment.Documentation, tsHiddenText = new TextSpan() { iStartLine = startLine, iStartIndex = startIdx, iEndLine = endLine, iEndIndex = endIdx } }; hiddenSession.AddHiddenRegions(0, 1, new[] { hidRegion }, hiddenRegions); res.Add(new TagSpan <DocumentationTag>(snapshotSpan, new DocumentationTag(fragment.Selection.Text, snapshot.CreateTrackingSpan(startPos, length, SpanTrackingMode.EdgeInclusive), _buffer))); } } return(res); }
// Overriden in source.fs, it calls this base implementation public virtual void Dispose() { #if LANGTRACE Trace.WriteLine("Source::Cleanup"); #endif this.disposed = true; try { if (this.textLinesEvents != null) { this.textLinesEvents.Dispose(); this.textLinesEvents = null; } } finally { try { if (this.userDataEvents != null) { this.userDataEvents.Dispose(); this.userDataEvents = null; } } finally { try { if (this.hiddenTextSession != null) { // We can't throw or exit here because we need to call Dispose on the // other members that need to be disposed. this.hiddenTextSession.UnadviseClient(); // This is causing a debug assert in vs\env\msenv\textmgr\vrlist.cpp // at line 1997 in CVisibleRegionList::Terminate //this.hiddenTextSession.Terminate(); this.hiddenTextSession = null; } } finally { try { if (this.methodData != null) { this.methodData.Dispose(); this.methodData = null; } } finally { try { if (this.completionSet != null) { this.completionSet.Dispose(); this.completionSet = null; } } finally { try { // clear out any remaining tasks for this doc in the task list // tp may not be the same as taskProvider // REVIEW: This should be: if (null != this.taskReporter) // Right now, MSBuild 4.0 can clear out build loggers responsibly, so this.taskReporter will always // be null when we get to this point, so we'll need to create a new taskReporter to clear out the // background tasks TaskReporter tr = this.GetTaskReporter(); // may be our own TR or one from ProjectSite of this file if (null != tr) { tr.ClearBackgroundTasksForFile(this.GetFilePath()); // Refresh the task list tr.OutputTaskList(); } if (null != this.taskReporter) // dispose the one we own (do not dispose one shared by project site!) { this.taskReporter.Dispose(); this.taskReporter = null; this.taskProvider = null; } } finally { try { this.service = null; if (this.colorizer != null) { // The colorizer is owned by the core text editor, so we don't close it, the core text editor // does that for us when it is ready to do so. //colorizer.CloseColorizer(); this.colorizer = null; } } finally { this.colorState = null; try { if (this.expansionProvider != null) { this.expansionProvider.Dispose(); this.expansionProvider = null; } } finally { // Sometimes OnCloseSource is called when language service is changed, (for example // when you save the file with a different file extension) in which case we cannot // null out the site because that will cause a crash inside msenv.dll. // if (this.textLines != null) { // ((IObjectWithSite)this.textLines).SetSite(null); // } if (this.textLines != null) { this.textLines = null; Marshal.Release(pUnkTextLines); } } } } } } } } } }
public IVsHiddenTextSession GetHiddenTextSession() { if (this.hiddenTextSession == null) { IVsHiddenTextManager htextmgr = service.Site.GetService(typeof(SVsTextManager)) as IVsHiddenTextManager; if (htextmgr != null) { IVsHiddenTextSession session = null; int hr = htextmgr.GetHiddenTextSession(textLines, out session); if (hr == NativeMethods.E_FAIL) { // Then there was no hidden text session. NativeMethods.ThrowOnFailure(htextmgr.CreateHiddenTextSession(0, textLines, this, out session)); } this.hiddenTextSession = session; } } return this.hiddenTextSession; }
public VSHiddenTextManager(IVsTextView view, IVsHiddenTextClient client) { hiddenTextSession = GetHiddenTextSession(view); hiddenTextClient = client; }
public VSHiddenTextManager(IVsTextView view) { hiddenTextSession = GetHiddenTextSession(view); }
private IVsHiddenTextSession GetHiddenTextSession(IVsTextView view) { if (view == null) { return null; } IVsTextLines txtLine; view.GetBuffer(out txtLine); hiddenTextSession = null; //每个session都与特定的Textbuffer关联,这里默认是当前窗口的buffer HiddenTextManager.GetHiddenTextSession(txtLine, out hiddenTextSession); if (hiddenTextSession == null) { HiddenTextManager.CreateHiddenTextSession(0, txtLine,/* hiddenTextClient */hiddenTextClient, out hiddenTextSession); } return hiddenTextSession; }
/// <include file='doc\LanguageService.uex' path='docs/doc[@for="Source.Dispose"]/*' /> public virtual void Dispose() { #if LANGTRACE Trace.WriteLine("Source::Cleanup"); #endif try { if (this.textLinesEvents != null) { this.textLinesEvents.Dispose(); this.textLinesEvents = null; } } catch (COMException) { } try { if (this.userDataEvents != null) { this.userDataEvents.Dispose(); this.userDataEvents = null; } } catch (COMException) { } try { if (this.hiddenTextSession != null) { // We can't throw or exit here because we need to call Dispose on the // other members that need to be disposed. this.hiddenTextSession.UnadviseClient(); this.hiddenTextSession = null; } } catch (COMException) { } try { if (this.methodData != null) { this.methodData.Dispose(); this.methodData = null; } } catch (COMException) { } try { if (this.completionSet != null) { this.completionSet.Dispose(); this.completionSet = null; } } catch (COMException) { } try { if (this.taskProvider != null) { this.taskProvider.Dispose(); this.taskProvider = null; } } catch (COMException) { } try { this.service = null; if (this.colorizer != null) { // The colorizer is owned by the core text editor, so we don't close it, the core text editor // does that for us when it is ready to do so. //colorizer.CloseColorizer(); this.colorizer = null; } } catch (COMException) { } try { if (this.colorState != null) { this.colorState = null; } } catch (COMException) { } try { if (this.expansionProvider != null) { this.expansionProvider.Dispose(); this.expansionProvider = null; } } catch (COMException) { } try { // Sometimes OnCloseSource is called when language service is changed, (for example // when you save the file with a different file extension) in which case we cannot // null out the site because that will cause a crash inside msenv.dll. // if (this.textLines != null) { // ((IObjectWithSite)this.textLines).SetSite(null); // } if (this.textLines != null) { this.textLines = null; //rely on GC rather control lifetime through ReleaseCOMObject Marshal.Release(pUnkTextLines); } } catch (COMException) { } }
private TextViewSelection GetSelection(IServiceProvider serviceProvider) { var service = serviceProvider.GetService(typeof(SVsTextManager)); var textManager = service as IVsTextManager2; IVsTextView view; int result = textManager.GetActiveView2(1, null, (uint)_VIEWFRAMETYPE.vftCodeWindow, out view); view.GetSelection(out int startLine, out int startColumn, out int endLine, out int endColumn);//end could be before beginning var hiddenTextManager = serviceProvider.GetService(typeof(SVsTextManager)) as IVsHiddenTextManager; IVsHiddenTextSession hiddenSession = null; IVsTextLines lines = null; IVsEnumHiddenRegions[] hiddenRegions = null; view.GetBuffer(out lines); int hRetVal = hiddenTextManager.GetHiddenTextSession( lines, out hiddenSession); if (hRetVal != 0) { hRetVal = hiddenTextManager.CreateHiddenTextSession( 0, lines, null, out hiddenSession); //if (hRetVal != 0) // return null; } if (hiddenSession != null) { var hidRegion = new NewHiddenRegion() { dwBehavior = (uint)HIDDEN_REGION_BEHAVIOR.hrbClientControlled, dwState = (uint)HIDDEN_REGION_STATE.hrsDefault, iType = (int)HIDDEN_REGION_TYPE.hrtConcealed, pszBanner = "Testing!!", tsHiddenText = new TextSpan() { iStartLine = startLine, iStartIndex = startColumn, iEndLine = endLine, iEndIndex = endColumn } }; hiddenSession.AddHiddenRegions(0, 1, new[] { hidRegion }, hiddenRegions); } int ok = view.GetNearestPosition(startLine, startColumn, out int position1, out int piVirtualSpaces); ok = view.GetNearestPosition(endLine, endColumn, out int position2, out piVirtualSpaces); var startPosition = Math.Min(position1, position2); var endPosition = Math.Max(position1, position2); view.GetSelectedText(out string selectedText); TextViewSelection selection = new TextViewSelection(startPosition, endPosition, selectedText); return(selection); }