public void VsTextViewCreated(IVsTextView textViewAdapter) { var view = textViewAdapter.ToITextView(); var filePath = textViewAdapter.GetFilePath(); var project = ProjectInfo.FindProject(filePath); if (project == null) { return; } var engine = project.Engine; if (engine.IsExtensionRegistered(Path.GetExtension(filePath)) || engine.HasSourceChangedSubscribers(Location.GetFileIndex(filePath))) { //Trace.WriteLine("Opened: " + filePath); IVsTextLines vsTextLines = textViewAdapter.GetBuffer(); var langSrv = NemerlePackage.GetGlobalService(typeof(NemerleLanguageService)) as NemerleLanguageService; if (langSrv == null) { return; } var source = (NemerleSource)langSrv.GetOrCreateSource(vsTextLines); project.AddEditableSource(source); view.TextBuffer.Changed += TextBuffer_Changed; view.Closed += view_Closed; } }
public NemerleLanguageService(NemerlePackage package) { Debug.Assert(package != null, "package != null"); Package = package; if (System.Threading.Thread.CurrentThread.Name == null) { System.Threading.Thread.CurrentThread.Name = "UI Thread"; } CompiledUnitAstBrowser.ShowLocation += GotoLocation; AstToolControl.ShowLocation += GotoLocation; if (DefaultEngine == null) { try { DefaultEngine = EngineFactory.Create(EngineCallbackStub.Default, new TraceWriter(), true); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } Hint = new Hint(); Hint.WrapWidth = 900.1; }
void view_Closed(object sender, EventArgs args) { var view = (ITextView)sender; view.TextBuffer.Changed -= TextBuffer_Changed; view.Closed -= view_Closed; IVsTextView vsTextView = view.ToVsTextView(); var filePath = vsTextView.GetFilePath(); // vsTextView.ToIVsTextBuffer().GetFilePath(); //Trace.WriteLine("Closed: " + filePath); var langSrv = NemerlePackage.GetGlobalService(typeof(NemerleLanguageService)) as NemerleLanguageService; if (langSrv == null) { return; } var source = (NemerleSource)langSrv.GetSource(filePath); if (source != null) { source.ReleaseRef(); if (source.RefCount == 0) { langSrv.OnCloseSource(source); source.Dispose(); } } else { } }
IVsSmartTagTipWindow GetSmartTagTipWindow() { NemerlePackage pkg = Package; if (_smartTagWin == null) { Type typeSTagWin = typeof(VsSmartTagTipWindowClass); Guid clsidSTagWin = typeSTagWin.GUID; Guid iidSTagWin = typeof(IVsSmartTagTipWindow).GUID; _smartTagWin = (IVsSmartTagTipWindow)pkg.CreateInstance(ref clsidSTagWin, ref iidSTagWin, typeSTagWin); Debug.Assert(_smartTagWin != null); } return(_smartTagWin); }
public NemerleProjectNode(NemerlePackage pkg) { FileTemplateProcessor = new NemerleTokenProcessor(); CanFileNodesHaveChilds = true; SupportsProjectDesigner = true; OleServiceProvider.AddService(typeof(VSLangProj.VSProject), VSProject, false); // Store the number of images in ProjectNode so we know the offset of the Nemerle icons. // _imageOffset = ImageHandler.ImageList.Images.Count; foreach (Image img in NemerleImageList.Images) ImageHandler.ImageList.Images.Add(img); InitializeCATIDs(); CanProjectDeleteItems = true; }
public NemerleProjectFactory(NemerlePackage package) : base(package) { }
// Считывает содержимое файла из буфера, связанного с документом. // Такой способ позволяет получить еще не сохраненный на диск контент. private string ReadSourceFromBuffer() { IVsRunningDocumentTable rdt = NemerlePackage.GetGlobalService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable; if (rdt != null) { IEnumRunningDocuments documents; rdt.GetRunningDocumentsEnum(out documents); IntPtr documentData = IntPtr.Zero; uint[] docCookie = new uint[1]; uint fetched; while ((Microsoft.VisualStudio.VSConstants.S_OK == documents.Next(1, docCookie, out fetched)) && (1 == fetched)) { uint flags; uint editLocks; uint readLocks; string moniker; IVsHierarchy docHierarchy; uint docId; IntPtr docData = IntPtr.Zero; try { ErrorHandler.ThrowOnFailure(rdt.GetDocumentInfo(docCookie[0], out flags, out readLocks, out editLocks, out moniker, out docHierarchy, out docId, out docData)); // Check if this document is the one we are looking for. if (docId == _id && _hierarchy.Equals(docHierarchy)) { documentData = docData; docData = IntPtr.Zero; break; } } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } } if (documentData != IntPtr.Zero) { object obj = Marshal.GetObjectForIUnknown(documentData); IVsTextLines txtLines = obj as IVsTextLines; int totalLines; ErrorHandler.ThrowOnFailure(txtLines.GetLineCount(out totalLines)); StringBuilder sb = new StringBuilder(); for (int line = 0; line < totalLines; ++line) { int lineLen; ErrorHandler.ThrowOnFailure(txtLines.GetLengthOfLine(line, out lineLen)); string lineText; ErrorHandler.ThrowOnFailure(txtLines.GetLineText(line, 0, line, lineLen, out lineText)); sb.AppendLine(lineText); } return(sb.ToString()); } } return(null); }
IntPtr FindDocDataFromRDT() { // Get a reference to the RDT. // IVsRunningDocumentTable rdt = NemerlePackage.GetGlobalService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable; if (rdt == null) { return(IntPtr.Zero); } // Get the enumeration of the running documents. // IEnumRunningDocuments documents; ErrorHandler.ThrowOnFailure(rdt.GetRunningDocumentsEnum(out documents)); IntPtr documentData = IntPtr.Zero; uint[] docCookie = new uint[1]; uint fetched; while ((VSConstants.S_OK == documents.Next(1, docCookie, out fetched)) && (1 == fetched)) { uint flags; uint editLocks; uint readLocks; string moniker; IVsHierarchy docHierarchy; uint docId; IntPtr docData = IntPtr.Zero; try { ErrorHandler.ThrowOnFailure(rdt.GetDocumentInfo( docCookie[0], out flags, out readLocks, out editLocks, out moniker, out docHierarchy, out docId, out docData)); // Check if this document is the one we are looking for. // if ((docId == _fileId) && (_ownerHierarchy.Equals(docHierarchy))) { documentData = docData; docData = IntPtr.Zero; break; } } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } } return(documentData); }
public NemerleLanguageService(NemerlePackage package) { Debug.Assert(package != null, "package != null"); Package = package; if (System.Threading.Thread.CurrentThread.Name == null) System.Threading.Thread.CurrentThread.Name = "UI Thread"; CompiledUnitAstBrowser.ShowLocation += GotoLocation; AstToolControl.ShowLocation += GotoLocation; if (DefaultEngine == null) { try { DefaultEngine = EngineFactory.Create(EngineCallbackStub.Default, new TraceWriter(), true); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } Hint = new Hint(); Hint.WrapWidth = 900.1; }
public NemerleEditorFactory(NemerlePackage package) { _package = package; }