TextAndVersion GetTextAndVersion (Workspace workspace, DocumentId documentId) { SourceText text; if (workspace.IsDocumentOpen (documentId)) { text = new MonoDevelopSourceText (TextFileProvider.Instance.GetTextEditorData (fileName).CreateDocumentSnapshot ()); } else { text = SourceText.From (MonoDevelop.Core.Text.TextFileUtility.GetText (fileName)); } return TextAndVersion.Create (text, VersionStamp.Create ()); }
async Task<TextAndVersion> GetTextAndVersion (Workspace workspace, DocumentId documentId, CancellationToken cancellationToken) { if (!File.Exists (fileName)) { return TextAndVersion.Create (await ((MonoDevelopWorkspace)workspace).GetDocument (documentId).GetTextAsync (cancellationToken), VersionStamp.Create ()); } SourceText text; if (workspace.IsDocumentOpen (documentId)) { text = new MonoDevelopSourceText (TextFileProvider.Instance.GetTextEditorData (fileName).CreateDocumentSnapshot ()); } else { text = SourceText.From (TextFileUtility.GetText (fileName)); } return TextAndVersion.Create (text, VersionStamp.Create ()); }
private static Document OpenDocument(Workspace workspace, DocumentId documentId, OptionSet options) { options = options ?? workspace.Options; // Always open the document again, even if the document is already open in the // workspace. If a document is already open in a preview tab and it is opened again // in a permanent tab, this allows the document to transition to the new state. if (workspace.CanOpenDocuments) { if (options.GetOption(NavigationOptions.PreferProvisionalTab)) { using (NewDocumentStateScope ndss = new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.Navigation)) { workspace.OpenDocument(documentId); } } else { workspace.OpenDocument(documentId); } } if (!workspace.IsDocumentOpen(documentId)) { return null; } return workspace.CurrentSolution.GetDocument(documentId); }