public virtual int GetColorizer(IVsTextLines buffer, out IVsColorizer colorizer) { Contract.Requires<ArgumentNullException>(buffer != null, "buffer"); colorizer = null; return VSConstants.E_FAIL; }
/// <summary> /// Default ctor /// </summary> protected XmlViewModel(IXmlStore xmlStore, IXmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer) { if (xmlModel == null) throw new ArgumentNullException("xmlModel"); if (xmlStore == null) throw new ArgumentNullException("xmlStore"); if (provider == null) throw new ArgumentNullException("provider"); if (buffer == null) throw new ArgumentNullException("buffer"); BufferDirty = false; DesignerDirty = false; serviceProvider = provider; this.buffer = buffer; textBufferSerializer = new TextBufferSerializer(buffer); this.xmlStore = xmlStore; // OnUnderlyingEditCompleted editingScopeCompletedHandler = OnUnderlyingEditCompleted; this.xmlStore.EditingScopeCompleted += editingScopeCompletedHandler; // OnUndoRedoCompleted undoRedoCompletedHandler = OnUndoRedoCompleted; this.xmlStore.UndoRedoCompleted += undoRedoCompletedHandler; this.xmlModel = xmlModel; // BufferReloaded bufferReloadedHandler += BufferReloaded; this.xmlModel.BufferReloaded += bufferReloadedHandler; }
private static bool IsCSharpOrCppOrC(IVsTextLines textLines) { Guid languageServiceId; textLines.GetLanguageServiceID(out languageServiceId); //return GuidList.CSHARP_LANGUAGE_GUID.Equals(languageServiceId); return true; }
/// <summary> /// Create and return instantiation of a parser represented by RegularExpressionScanner object. /// </summary> /// <param name="buffer">An <see cref="IVsTextLines"/> represents lines of source to parse.</param> /// <returns>Returns a RegularExpressionScanner object</returns> public override IScanner GetScanner(IVsTextLines buffer) { SpecFlowProject specFlowProject = DteProjectReader.LoadSpecFlowProjectFromDteProject(CurrentProject); scanner = new RegularExpressionScanner(specFlowProject.Configuration.GeneratorConfiguration.FeatureLanguage); return scanner; }
public override IScanner GetScanner(IVsTextLines buffer) { if (scanner == null) this.scanner = new LineScanner(); return this.scanner; }
public AvaloniaDesignerPane(IVsCodeWindow vsCodeWindow, IVsTextLines textBuffer, string fileName, IAvaloniaDesignerSettings designerSettings) { _vsCodeWindow = vsCodeWindow; _textBuffer = textBuffer.GetTextBuffer(); _fileName = fileName; _designerSettings = designerSettings; }
public XSharpSource( XSharpLanguageService service, IVsTextLines textLines, Colorizer colorizer) : base(service, textLines, colorizer) { }
public CodeDomFileCodeModel(DTE dte, IVsTextLines buffer, CodeDomProvider provider, string moniker) : base(dte, moniker) { this.textBuffer = buffer; this.provider = provider as IMergableProvider; if (provider == null) throw new ArgumentException("provider must implement IMergeableProvider interface"); }
public override IScanner GetScanner(IVsTextLines buffer) { if (this.scanner == null) this.scanner = new LightScanner(grammar); return this.scanner; }
public TextView(IVsTextView view) { if (view == null) throw new ArgumentNullException("view"); try { _view = view; _buffer = view.GetBuffer(); _viewEvents = new TextViewEventAdapter(view); _textStreamEvents = new TextStreamEventAdapter(Buffer); _viewEvents.ScrollChanged += ScrollChangedHandler; _viewEvents.GotFocus += new EventHandler<ViewFocusEventArgs>(GotFocusHandler); _screenUpdater = new ScreenUpdateManager(this); CreateWindow(); selectionSearcher = new MarkSearcher(-1, this); freezer1 = new MarkSearcher(1, this); freezer2 = new MarkSearcher(2, this); freezer3 = new MarkSearcher(3, this); freezers = new List<MarkSearcher>(); freezers.Add(freezer1); freezers.Add(freezer2); freezers.Add(freezer3); } catch (Exception ex) { Log.Error("Failed to create TextView", ex); } }
/// <summary> /// Constructor that calls the Microsoft.VisualStudio.Shell.WindowPane constructor then /// our initialization functions. /// </summary> /// <param name="package">Our Package instance.</param> public EditorPane(ServiceDesignerPackage package, string fileName, IVsTextLines textBuffer) : base(null) { _thisPackage = package; _fileName = fileName; _textBuffer = textBuffer; }
public ViewModel(XmlStore xmlStore, XmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer) { if (xmlModel == null) throw new ArgumentNullException("xmlModel"); if (xmlStore == null) throw new ArgumentNullException("xmlStore"); if (provider == null) throw new ArgumentNullException("provider"); if (buffer == null) throw new ArgumentNullException("buffer"); this.BufferDirty = false; this.DesignerDirty = false; this._serviceProvider = provider; this._buffer = buffer; this._xmlStore = xmlStore; // OnUnderlyingEditCompleted _editingScopeCompletedHandler = new EventHandler<XmlEditingScopeEventArgs>(OnUnderlyingEditCompleted); this._xmlStore.EditingScopeCompleted += _editingScopeCompletedHandler; // OnUndoRedoCompleted _undoRedoCompletedHandler = new EventHandler<XmlEditingScopeEventArgs>(OnUndoRedoCompleted); this._xmlStore.UndoRedoCompleted += _undoRedoCompletedHandler; this._xmlModel = xmlModel; // BufferReloaded _bufferReloadedHandler += new EventHandler(BufferReloaded); this._xmlModel.BufferReloaded += _bufferReloadedHandler; LoadModelFromXmlModel(); }
protected override void InitializeLanguageService(IVsTextLines textLines) { var userData = textLines as IVsUserData; if (userData == null) return; var langSid = typeof(PowerShellLanguageInfo).GUID; if (langSid == Guid.Empty) return; var vsCoreSid = new Guid("{8239bec4-ee87-11d0-8c98-00c04fc2ab22}"); Guid currentSid; ErrorHandler.ThrowOnFailure(textLines.GetLanguageServiceID(out currentSid)); // If the language service is set to the default SID, then // set it to our language if (currentSid == vsCoreSid) { ErrorHandler.ThrowOnFailure(textLines.SetLanguageServiceID(ref langSid)); } else if (currentSid != langSid) { // Some other language service has it, so return VS_E_INCOMPATIBLEDOCDATA throw new COMException("Incompatible doc data", VSConstants.VS_E_INCOMPATIBLEDOCDATA); } var bufferDetectLang = VSConstants.VsTextBufferUserDataGuid.VsBufferDetectLangSID_guid; ErrorHandler.ThrowOnFailure(userData.SetData(ref bufferDetectLang, false)); }
// private IScanner scanner; // private IVsTextLines buffer; // private List<TokenInfo>[] tokenList; // private string savedSqlText; public MySqlColorizer(LanguageService service, IVsTextLines buffer, IScanner scanner) : base(service, buffer, scanner) { (scanner as MySqlScanner).Colorizer = this; // this.scanner = scanner; // this.buffer = buffer; }
public override Source CreateSource(IVsTextLines buffer) { var filePath = FilePathUtilities.GetFilePath(buffer); if (GlobalServices.GetProjectManagerForFile(filePath) == null) return base.CreateSource(buffer); return new BooSource(this, filePath, buffer, GetColorizer(buffer)) {LastParseTime = 0}; }
internal TextBufferMerger(IVsTextLines buffer) { if (null == buffer) { throw new ArgumentNullException("buffer"); } this.textBuffer = buffer; }
public ISource GetSource(IVsTextLines textBuffer) { var src = languageService.GetSource(textBuffer); if (src == null) return null; return new Source(src); }
internal static string Line(IVsTextLines vsTextLines, int index) { int length; vsTextLines.GetLengthOfLine(index, out length); string result; vsTextLines.GetLineText(index, 0, index, length, out result); return result; }
public List<TokenInfo> ParseLine(IVsTextLines textLines, int line, int maxTokens, out string lineOut) { int maxColumn; textLines.GetLengthOfLine(line, out maxColumn); textLines.GetLineText(line, 0, line, maxColumn, out lineOut); return Parse(lineOut, maxTokens); }
public override IScanner GetScanner(IVsTextLines buffer) { if (m_scanner == null) { m_scanner = new CQLScanner(buffer); } return m_scanner; }
/// <summary> /// Constructor that calls the Microsoft.VisualStudio.Shell.WindowPane constructor then /// our initialization functions. /// </summary> /// <param name="package">Our Package instance.</param> public EditorPane(ServiceProvider service, VSNDK_PackagePackage package, string fileName, IVsTextLines textBuffer) : base(null) { _thisPackage = package; _fileName = fileName; _textBuffer = textBuffer; _service = service; }
/// <summary> /// Builds a new enumerator from a text buffer. /// </summary> public CodeBlocksEnumerator(IVsTextLines buffer) { if (null == buffer) { throw new ArgumentNullException("buffer"); } blocks = new List<TextSpanAndCookie>(); SearchForCodeBlocks(buffer); }
/// <summary> /// Returns a single instantiation of a parser. /// </summary> /// <returns> /// If successful, returns an <see cref="T:Microsoft.VisualStudio.Package.IScanner"/> object; otherwise, returns a null value. /// </returns> /// <param name="buffer">[in] An <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextLines"/> representing the lines of source to parse. /// </param> public override IScanner GetScanner(IVsTextLines buffer) { if (scanner == null) { scanner = new DotLessScanner(); } return scanner; }
public AnkhColorizer(AnkhLanguage language, IVsTextLines lines) : base(language) { if (lines == null) throw new ArgumentNullException("lines"); _lines = lines; }
/// <summary> /// Default ctor /// </summary> internal XmlEditorPane(Dot42Package package, IXmlEditorPaneContext context, string fileName, IVsTextLines textBuffer) : base(null) { thisPackage = package; this.context = context; _fileName = fileName; this.textBuffer = textBuffer; }
/// <summary> /// Creates a new TextBufferStream on top of a text buffer. /// The optional text marker can be used to let the stream set read only the /// text that it writes on the buffer. /// </summary> public TextBufferStream(IVsTextLines lines) { if (null == lines) { throw new ArgumentNullException("lines"); } textLines = lines; byteBuffer = new byte[bufferSize]; }
internal VisualStudioDocument(IVsWindowFrame frame, IVsTextLines buffer, IOleServiceProvider docViewService) { this.textEditorBuffer = buffer; this.currentWindowFrame = frame; if (GetSource(docViewService)) { LoadDocument(); } }
public void Dispose() { if ((null != _connectionPoint) && (0 != _connectionCookie)) { _connectionPoint.Unadvise(_connectionCookie); } _connectionCookie = 0; _connectionPoint = null; _buffer = null; _fileId = null; }
protected XmlModelDocumentTask( IServiceProvider site, IVsTextLines buffer, MARKERTYPE markerType, TextSpan span, string document, uint itemID, string errorMessage, IVsHierarchy hierarchy) : base(site, buffer, markerType, span, document) { _serviceProvider = site; _itemID = itemID; Text = errorMessage; HierarchyItem = hierarchy; }
internal ExternalEditManager(IVimBuffer buffer, IVsTextLines vsTextLines, IViewTagAggregatorFactoryService tagAggregatorFactoryService) { _vsTextLines = vsTextLines; _tagAggregator = tagAggregatorFactoryService.CreateTagAggregator<ITag>(buffer.TextView); _buffer = buffer; _buffer.TextView.LayoutChanged += OnLayoutChanged; _buffer.SwitchedMode += OnSwitchedMode; _externalEditorAdapters.Add(new SnippetExternalEditorAdapter()); _externalEditorAdapters.Add(new ResharperExternalEditorAdapter()); }
public override Colorizer GetColorizer(IVsTextLines buffer) { return(new SoalLanguageColorizer(this, buffer, this.GetScanner(buffer))); }
public int SetBuffer(IVsTextLines pBuffer) => editor.codeWindow.SetBuffer(pBuffer);
public SoalLanguageColorizer(LanguageService svc, IVsTextLines buffer, IScanner scanner) : base(svc, buffer, scanner) { }
public int FormatSpan(IVsTextLines pBuffer, TextSpan[] ts) { return(VSConstants.S_OK); }
public int FormatSpan(IVsTextLines pBuffer, VsTextSpan[] tsInSurfaceBuffer) { // Formatting a snippet isn't cancellable. var cancellationToken = CancellationToken.None; // At this point, the $selection$ token has been replaced with the selected text and // declarations have been replaced with their default text. We need to format the // inserted snippet text while carefully handling $end$ position (where the caret goes // after Return is pressed). The IVsExpansionSession keeps a tracking point for this // position but we do the tracking ourselves to properly deal with virtual space. To // ensure the end location is correct, we take three extra steps: // 1. Insert an empty comment ("/**/" or "'") at the current $end$ position (prior // to formatting), and keep a tracking span for the comment. // 2. After formatting the new snippet text, find and delete the empty multiline // comment (via the tracking span) and notify the IVsExpansionSession of the new // $end$ location. If the line then contains only whitespace (due to the formatter // putting the empty comment on its own line), then delete the white space and // remember the indentation depth for that line. // 3. When the snippet is finally completed (via Return), and PositionCaretForEditing() // is called, check to see if the end location was on a line containing only white // space in the previous step. If so, and if that line is still empty, then position // the caret in virtual space. // This technique ensures that a snippet like "if($condition$) { $end$ }" will end up // as: // if ($condition$) // { // $end$ // } if (!TryGetSubjectBufferSpan(tsInSurfaceBuffer[0], out var snippetSpan)) { return(VSConstants.S_OK); } // Insert empty comment and track end position var snippetTrackingSpan = snippetSpan.CreateTrackingSpan(SpanTrackingMode.EdgeInclusive); var fullSnippetSpan = new VsTextSpan[1]; ExpansionSession.GetSnippetSpan(fullSnippetSpan); var isFullSnippetFormat = fullSnippetSpan[0].iStartLine == tsInSurfaceBuffer[0].iStartLine && fullSnippetSpan[0].iStartIndex == tsInSurfaceBuffer[0].iStartIndex && fullSnippetSpan[0].iEndLine == tsInSurfaceBuffer[0].iEndLine && fullSnippetSpan[0].iEndIndex == tsInSurfaceBuffer[0].iEndIndex; var endPositionTrackingSpan = isFullSnippetFormat ? InsertEmptyCommentAndGetEndPositionTrackingSpan() : null; var formattingSpan = CommonFormattingHelpers.GetFormattingSpan(SubjectBuffer.CurrentSnapshot, snippetTrackingSpan.GetSpan(SubjectBuffer.CurrentSnapshot)); SubjectBuffer.CurrentSnapshot.FormatAndApplyToBuffer(formattingSpan, CancellationToken.None); if (isFullSnippetFormat) { CleanUpEndLocation(endPositionTrackingSpan); // Unfortunately, this is the only place we can safely add references and imports // specified in the snippet xml. In OnBeforeInsertion we have no guarantee that the // snippet xml will be available, and changing the buffer during OnAfterInsertion can // cause the underlying tracking spans to get out of sync. var currentStartPosition = snippetTrackingSpan.GetStartPoint(SubjectBuffer.CurrentSnapshot).Position; AddReferencesAndImports( ExpansionSession, currentStartPosition, cancellationToken); SetNewEndPosition(endPositionTrackingSpan); } return(VSConstants.S_OK); }
/// <summary> /// GetColorizer is not implemented because we implement colorization using the new managed APIs. /// </summary> public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer) { ppColorizer = null; return(VSConstants.E_FAIL); }
/// <summary> /// This is used to get the content of a specific topic file if it is open in an editor so that the /// current content is displayed for it in the topic previewer control. /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void ucTopicPreviewer_TopicContentNeeded(object sender, TopicContentNeededEventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); IVsHierarchy hier; IVsPersistDocData persistDocData; IVsTextStream srpStream; IntPtr docData = IntPtr.Zero; uint itemid, cookie = 0; int hr = VSConstants.E_FAIL; IVsRunningDocumentTable rdt = Utility.GetServiceFromPackage <IVsRunningDocumentTable, SVsRunningDocumentTable>(true); if (rdt == null) { return; } try { // Getting a read lock on the document. This must be released later. hr = rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, e.TopicFilename, out hier, out itemid, out docData, out cookie); if (ErrorHandler.Failed(hr) || docData == IntPtr.Zero) { return; } persistDocData = Marshal.GetObjectForIUnknown(docData) as IVsPersistDocData; // Try to get the Text lines IVsTextLines srpTextLines = persistDocData as IVsTextLines; if (srpTextLines == null) { // Try getting a text buffer provider first IVsTextBufferProvider srpTextBufferProvider = persistDocData as IVsTextBufferProvider; if (srpTextBufferProvider != null) { hr = srpTextBufferProvider.GetTextBuffer(out srpTextLines); } } if (ErrorHandler.Succeeded(hr)) { srpStream = srpTextLines as IVsTextStream; if (srpStream != null) { IVsBatchUpdate srpBatchUpdate = srpStream as IVsBatchUpdate; if (srpBatchUpdate != null) { ErrorHandler.ThrowOnFailure(srpBatchUpdate.FlushPendingUpdates(0)); } int lBufferSize = 0; hr = srpStream.GetSize(out lBufferSize); if (ErrorHandler.Succeeded(hr)) { IntPtr dest = IntPtr.Zero; try { // GetStream() returns Unicode data so we need to double the buffer size dest = Marshal.AllocCoTaskMem((lBufferSize + 1) * 2); ErrorHandler.ThrowOnFailure(srpStream.GetStream(0, lBufferSize, dest)); // Get the contents e.TopicContent = Marshal.PtrToStringUni(dest); } finally { if (dest != IntPtr.Zero) { Marshal.FreeCoTaskMem(dest); } } } } } } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } if (cookie != 0) { ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, cookie)); } } }
public int FormatSpan(IVsTextLines pBuffer, TextSpan[] ts) { XElement header, snippet; int hr = TryGetXmlNodes(_session, out header, out snippet); if (ErrorHandler.Failed(hr)) { return(hr); } var ns = header.Name.NamespaceName; bool surroundsWith = header .Elements(XName.Get("SnippetTypes", ns)) .Elements(XName.Get("SnippetType", ns)) .Any(n => n.Value == SurroundsWith); bool surroundsWithStatement = header .Elements(XName.Get("SnippetTypes", ns)) .Elements(XName.Get("SnippetType", ns)) .Any(n => n.Value == SurroundsWithStatement); ns = snippet.Name.NamespaceName; var declList = snippet .Element(XName.Get("Declarations", ns))? .Elements() .Elements(XName.Get("ID", ns)) .Select(n => n.Value) .Where(n => !string.IsNullOrEmpty(n)) .ToList() ?? new List <string>(); var importList = snippet .Element(XName.Get("Imports", ns))? .Elements(XName.Get("Import", ns)) .Elements(XName.Get("Namespace", ns)) .Select(n => n.Value) .Where(n => !string.IsNullOrEmpty(n)) .ToList() ?? new List <string>(); var codeText = snippet .Element(XName.Get("Code", ns))? .Value ?? string.Empty; // get the indentation of where we're inserting the code... string baseIndentation = GetBaseIndentation(ts); int startPosition; pBuffer.GetPositionOfLineIndex(ts[0].iStartLine, ts[0].iStartIndex, out startPosition); var insertTrackingPoint = _textView.TextBuffer.CurrentSnapshot.CreateTrackingPoint(startPosition, PointTrackingMode.Positive); TextSpan?endSpan = null; using (var edit = _textView.TextBuffer.CreateEdit()) { if (surroundsWith || surroundsWithStatement) { // this is super annoyning... Most languages can do a surround with and $selected$ can be // an empty string and everything's the same. But in Python we can't just have something like // "while True: " without a pass statement. So if we start off with an empty selection we // need to insert a pass statement. This is the purpose of the "SurroundsWithStatement" // snippet type. // // But, to make things even more complicated, we don't have a good indication of what's the // template text vs. what's the selected text. We do have access to the original template, // but all of the values have been replaced with their default values when we get called // here. So we need to go back and re-apply the template, except for the $selected$ part. // // Also, the text has \n, but the inserted text has been replaced with the appropriate newline // character for the buffer. var templateText = codeText.Replace("\n", _textView.Options.GetNewLineCharacter()); foreach (var decl in declList) { string defaultValue; if (ErrorHandler.Succeeded(_session.GetFieldValue(decl, out defaultValue))) { templateText = templateText.Replace("$" + decl + "$", defaultValue); } } templateText = templateText.Replace("$end$", ""); // we can finally figure out where the selected text began witin the original template... int selectedIndex = templateText.IndexOfOrdinal("$selected$", ignoreCase: true); if (selectedIndex != -1) { var selection = _textView.Selection; // now we need to get the indentation of the $selected$ element within the template, // as we'll need to indent the selected code to that level. string indentation = GetTemplateSelectionIndentation(templateText, selectedIndex); var start = _selectionStart.GetPosition(_textView.TextBuffer.CurrentSnapshot); var end = _selectionEnd.GetPosition(_textView.TextBuffer.CurrentSnapshot); if (end < start) { // we didn't actually have a selction, and our negative tracking pushed us // back to the start of the buffer... end = start; } var selectedSpan = Span.FromBounds(start, end); if (surroundsWithStatement && String.IsNullOrWhiteSpace(_textView.TextBuffer.CurrentSnapshot.GetText(selectedSpan))) { // we require a statement here and the user hasn't selected any code to surround, // so we insert a pass statement (and we'll select it after the completion is done) edit.Replace(new Span(startPosition + selectedIndex, end - start), "pass"); // Surround With can be invoked with no selection, but on a line with some text. // In that case we need to inject an extra new line. var endLine = _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(end); var endText = endLine.GetText().Substring(end - endLine.Start); if (!String.IsNullOrWhiteSpace(endText)) { edit.Insert(end, _textView.Options.GetNewLineCharacter()); } // we want to leave the pass statement selected so the user can just // continue typing over it... var startLine = _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(startPosition + selectedIndex); _selectEndSpan = true; endSpan = new TextSpan() { iStartLine = startLine.LineNumber, iEndLine = startLine.LineNumber, iStartIndex = baseIndentation.Length + indentation.Length, iEndIndex = baseIndentation.Length + indentation.Length + 4, }; } IndentSpan( edit, indentation, _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(start).LineNumber + 1, // 1st line is already indented _textView.TextBuffer.CurrentSnapshot.GetLineFromPosition(end).LineNumber ); } } // we now need to update any code which was not selected that we just inserted. IndentSpan(edit, baseIndentation, ts[0].iStartLine + 1, ts[0].iEndLine); edit.Apply(); } if (endSpan != null) { _session.SetEndSpan(endSpan.Value); } // add any missing imports... AddMissingImports( importList, insertTrackingPoint.GetPoint(_textView.TextBuffer.CurrentSnapshot) ); return(hr); }
/// <summary> /// Default ctor /// </summary> public XmlResourceViewModel(IXmlStore xmlStore, IXmlModel xmlModel, IServiceProvider provider, IVsTextLines buffer) : base(xmlStore, xmlModel, provider, buffer) { serializer = new AppResourceSerializer(); }
public int PositionCaretForEditing(IVsTextLines pBuffer, TextSpan[] ts) { return(VSConstants.S_OK); }
public void OnSetBuffer(IVsTextView pView, IVsTextLines pBuffer) { }
public int OnBeforeDocumentWindowShow(uint docCookie, int fFirstShow, IVsWindowFrame pFrame) { #if TEXTCHANGELISTENER // Check if this document is in the list of the documents. if (documents.ContainsKey(docCookie)) { return(VSConstants.S_OK); } // Get the information about this document from the RDT. IVsRunningDocumentTable rdt = provider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (null != rdt) { // Note that here we don't want to throw in case of error. uint flags; uint readLocks; uint writeLoks; string documentMoniker; IVsHierarchy hierarchy; uint itemId; IntPtr unkDocData; int hr = rdt.GetDocumentInfo(docCookie, out flags, out readLocks, out writeLoks, out documentMoniker, out hierarchy, out itemId, out unkDocData); try { if (Microsoft.VisualStudio.ErrorHandler.Failed(hr) || (IntPtr.Zero == unkDocData)) { return(VSConstants.S_OK); } // Check if the hierarchy is one of the hierarchies this service is monitoring. if (!hierarchies.ContainsKey(hierarchy)) { // This hierarchy is not monitored, we can exit now. return(VSConstants.S_OK); } // Check the extension of the file to see if a listener is required. string extension = System.IO.Path.GetExtension(documentMoniker); if (0 != string.Compare(extension, ".prg", StringComparison.OrdinalIgnoreCase)) { return(VSConstants.S_OK); } // Create the module id for this document. XSharpModuleId docId = new XSharpModuleId(hierarchy, itemId); // Try to get the text buffer. IVsTextLines buffer = Marshal.GetObjectForIUnknown(unkDocData) as IVsTextLines; // Create the listener. // So we are informed in case of Buffer change //TextLineEventListener listener = new TextLineEventListener(buffer, documentMoniker, docId); // Set the event handler for the change event. Note that there is no difference // between the AddFile and FileChanged operation, so we can use the same handler. //listener.OnFileChanged += new EventHandler<HierarchyEventArgs>(OnNewFile); // Add the listener to the dictionary, so we will not create it anymore. //documents.Add(docCookie, listener); } finally { if (IntPtr.Zero != unkDocData) { Marshal.Release(unkDocData); } } } // Always return success. #endif return(VSConstants.S_OK); }
public override Source CreateSource(IVsTextLines buffer) { return(new PuppetSource(this, buffer, this.GetColorizer(buffer))); }
public int IsValidKind(IVsTextLines pBuffer, TextSpan[] ts, string bstrKind, out int pfIsValidKind) { pfIsValidKind = 1; return(VSConstants.S_OK); }
/// <summary> /// Add the error/warning to the error list and potentially to the output window. /// </summary> private void AddToErrorList( BuildEventArgs errorEvent, string subcategory, string errorCode, string file, int startLine, int startColumn, int endLine, int endColumn) { if (file == null) { file = String.Empty; } bool isWarning = errorEvent is BuildWarningEventArgs; Shell.TaskPriority priority = isWarning ? Shell.TaskPriority.Normal : Shell.TaskPriority.High; TextSpan span; span.iStartLine = startLine; span.iStartIndex = startColumn; span.iEndLine = endLine < startLine ? span.iStartLine : endLine; span.iEndIndex = (endColumn < startColumn) && (span.iStartLine == span.iEndLine) ? span.iStartIndex : endColumn; if (OutputWindowPane != null && (this.Verbosity != LoggerVerbosity.Quiet || errorEvent is BuildErrorEventArgs)) { // Format error and output it to the output window string message = this.FormatMessage(errorEvent.Message); DefaultCompilerError e = new DefaultCompilerError(file, span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex, errorCode, message); e.IsWarning = isWarning; Output(GetFormattedErrorMessage(e)); } UIThread.Run(delegate() { IVsUIShellOpenDocument openDoc = serviceProvider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument; if (openDoc == null) { return; } IVsWindowFrame frame; IOleServiceProvider sp; IVsUIHierarchy hier; uint itemid; Guid logicalView = VSConstants.LOGVIEWID_Code; IVsTextLines buffer = null; // JAF // Notes about acquiring the buffer: // If the file physically exists then this will open the document in the current project. It doesn't matter if the file is a member of the project. // Also, it doesn't matter if this is an F# file. For example, an error in Microsoft.Common.targets will cause a file to be opened here. // However, opening the document does not mean it will be shown in VS. if (!Microsoft.VisualStudio.ErrorHandler.Failed(openDoc.OpenDocumentViaProject(file, ref logicalView, out sp, out hier, out itemid, out frame)) && frame != null) { object docData; frame.GetProperty((int)__VSFPROPID.VSFPROPID_DocData, out docData); // Get the text lines buffer = docData as IVsTextLines; if (buffer == null) { IVsTextBufferProvider bufferProvider = docData as IVsTextBufferProvider; if (bufferProvider != null) { bufferProvider.GetTextBuffer(out buffer); } } } // Need to adjust line and column indexing for the task window, which assumes zero-based values if (span.iStartLine > 0 && span.iStartIndex > 0) { span.iStartLine -= 1; span.iEndLine -= 1; span.iStartIndex -= 1; span.iEndIndex -= 1; } // Add new document task to task list DocumentTask task = new DocumentTask(serviceProvider, buffer, // May be null // This seems weird. Why would warning status make this a 'compile error'? // The “code sense” errors produce red squiggles, whereas the “compile” errors produce blue squiggles. (This is in line with C#’s pre-VS2008-SP1 behavior.) Swapping these two gives us a look consistent with that of the language service. isWarning ? MARKERTYPE.MARKER_COMPILE_ERROR : MARKERTYPE.MARKER_CODESENSE_ERROR, span, file, subcategory); // Add error to task list task.Text = Microsoft.FSharp.Compiler.ErrorLogger.NewlineifyErrorString(errorEvent.Message); task.Priority = priority; task.ErrorCategory = isWarning ? Shell.TaskErrorCategory.Warning : Shell.TaskErrorCategory.Error; task.Category = Shell.TaskCategory.BuildCompile; task.HierarchyItem = hierarchy; task.Navigate += new EventHandler(NavigateTo); if (null != this.TaskReporter) { this.taskReporter.AddTask(task); } else { this.taskProvider.Tasks.Add(task); } }); }
public int IsValidType(IVsTextLines pBuffer, TextSpan[] ts, string[] rgTypes, int iCountTypes, out int pfIsValidType) { pfIsValidType = 1; return(VSConstants.S_OK); }
int IVsImmediateStatementCompletion2.SetCompletionContext_Deprecated(string filepath, IVsTextLines buffer, TextSpan[] currentStatementSpan, object punkContext) { Debug.Assert(false); return(VSConstants.S_OK); }
public int PositionCaretForEditing(IVsTextLines pBuffer, TextSpan[] ts) => PositionCaretInField(0);
// Let our deriving language services build up an appropriate context. protected abstract AbstractDebuggerIntelliSenseContext CreateContext(IWpfTextView view, IVsTextView vsTextView, IVsTextLines debuggerBuffer, ITextBuffer contextBuffer, Microsoft.VisualStudio.TextManager.Interop.TextSpan[] currentStatementSpan);
public override IScanner GetScanner(IVsTextLines buffer) { return(null); }
public int GetBuffer(out IVsTextLines ppBuffer) => editor.codeWindow.GetBuffer(out ppBuffer);
public int GetColorizer(IVsTextLines pBuffer, out IVsColorizer ppColorizer) { ppColorizer = null; return(failed); }
protected override void InitializeLanguageService(IVsTextLines textLines) { InitializeLanguageService(textLines, typeof(PythonLanguageInfo).GUID); }
public Source(LanguageService service, IVsTextLines textLines, Colorizer colorizer) : base(service, textLines, colorizer) { }
/// <summary> /// Create the appropriate designer control. /// </summary> public IDesignerControl CreateDesigner(IIde ide, IXmlStore store, IXmlModel model, IServiceProvider serviceProvider, IVsTextLines textBuffer) { var viewModel = new XmlMenuViewModel(store, model, serviceProvider, textBuffer); viewModel.Initialize(); return(new XmlMenuDesignerControl(ide, serviceProvider, viewModel)); }
protected virtual bool IsIncompatibleContentType(IVsTextLines textLines) { return(false); }
private ITextBuffer GetTextBufferOnUIThread(bool create) { IVsTextManager textMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); var model = GetService(typeof(SComponentModel)) as IComponentModel; var adapter = model.GetService <IVsEditorAdaptersFactoryService>(); uint itemid; IVsRunningDocumentTable rdt = ProjectMgr.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (rdt != null) { IVsHierarchy hier; IVsPersistDocData persistDocData; uint cookie; bool docInRdt = true; IntPtr docData = IntPtr.Zero; int hr = NativeMethods.E_FAIL; try { //Getting a read lock on the document. Must be released later. hr = rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_ReadLock, GetMkDocument(), out hier, out itemid, out docData, out cookie); if (ErrorHandler.Failed(hr) || docData == IntPtr.Zero) { if (!create) { return(null); } Guid iid = VSConstants.IID_IUnknown; cookie = 0; docInRdt = false; ILocalRegistry localReg = this.ProjectMgr.GetService(typeof(SLocalRegistry)) as ILocalRegistry; ErrorHandler.ThrowOnFailure(localReg.CreateInstance(CLSID_VsTextBuffer, null, ref iid, (uint)CLSCTX.CLSCTX_INPROC_SERVER, out docData)); } persistDocData = Marshal.GetObjectForIUnknown(docData) as IVsPersistDocData; } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } //Try to get the Text lines IVsTextLines srpTextLines = persistDocData as IVsTextLines; if (srpTextLines == null) { // Try getting a text buffer provider first IVsTextBufferProvider srpTextBufferProvider = persistDocData as IVsTextBufferProvider; if (srpTextBufferProvider != null) { hr = srpTextBufferProvider.GetTextBuffer(out srpTextLines); } } // Unlock the document in the RDT if necessary if (docInRdt && rdt != null) { ErrorHandler.ThrowOnFailure(rdt.UnlockDocument((uint)(_VSRDTFLAGS.RDT_ReadLock | _VSRDTFLAGS.RDT_Unlock_NoSave), cookie)); } if (srpTextLines != null) { return(adapter.GetDocumentBuffer(srpTextLines)); } } IWpfTextView view = GetTextView(); return(view.TextBuffer); }
public override IScanner GetScanner(IVsTextLines buffer) { return(new Boo.ASTMapper.Scanner.Scanner(() => GetLanguagePreferences().TabSize)); }
public int CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW) { ppunkDocView = IntPtr.Zero; ppunkDocData = IntPtr.Zero; pguidCmdUI = Guids.PerspexDesignerGeneralPageGuid; pgrfCDW = 0; pbstrEditorCaption = null; // Validate inputs if ((grfCreateDoc & (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0) { return(VSConstants.E_INVALIDARG); } IVsTextLines documentBuffer = null; if (punkDocDataExisting == IntPtr.Zero) { // create an invisible editor var invisibleEditorManager = (IVsInvisibleEditorManager)_serviceProvider.GetService(typeof(IVsInvisibleEditorManager)); IVsInvisibleEditor invisibleEditor; ErrorHandler.ThrowOnFailure(invisibleEditorManager.RegisterInvisibleEditor(pszMkDocument, null, (uint)_EDITORREGFLAGS.RIEF_ENABLECACHING, null, out invisibleEditor)); var docDataPointer = IntPtr.Zero; var guidIVSTextLines = typeof(IVsTextLines).GUID; ErrorHandler.ThrowOnFailure(invisibleEditor.GetDocData(1, ref guidIVSTextLines, out docDataPointer)); documentBuffer = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer); //It is important to site the TextBuffer object var objWSite = documentBuffer as IObjectWithSite; if (objWSite != null) { var oleServiceProvider = (IOleServiceProvider)GetService(typeof(IOleServiceProvider)); objWSite.SetSite(oleServiceProvider); } } else { documentBuffer = Marshal.GetObjectForIUnknown(punkDocDataExisting) as IVsTextLines; if (documentBuffer == null) { return(VSConstants.VS_E_INCOMPATIBLEDOCDATA); } } if (documentBuffer == null) { return(VSConstants.S_FALSE); } // set xml as the language service id ErrorHandler.ThrowOnFailure(documentBuffer.SetLanguageServiceID(ref Guids.XmlLanguageServiceGuid)); var editorPane = GetDocumentView(documentBuffer, pszMkDocument); ppunkDocView = Marshal.GetIUnknownForObject(editorPane); ppunkDocData = Marshal.GetIUnknownForObject(documentBuffer); pbstrEditorCaption = ""; return(VSConstants.S_OK); }
public override Microsoft.VisualStudio.Package.Source CreateSource(IVsTextLines buffer) { return(new SoalLanguageSource(this, buffer, this.GetColorizer(buffer))); }