public MemberTarget(SourceTextContainer textContainer, ISymbol memberIdentifier, Project project, Solution solution) { _textContainer = textContainer; _memberIdentifier = memberIdentifier; _project = project; _solution = solution; }
private void UpdateBuffer(TextDocument document, SpanChange spanSource, out SourceTextContainer container, out TextDocument documentBackedByTextBuffer) { if (_previewWorkspace != null) { var currentDocument = _previewWorkspace.CurrentSolution.GetTextDocument(_currentDocument); var currentDocumentText = currentDocument.GetTextAsync().Result; _previewWorkspace.CloseDocument(currentDocument, currentDocumentText); // Put the new document into the current preview solution. var updatedSolution = _previewWorkspace.CurrentSolution.WithTextDocumentText(document.Id, document.GetTextAsync().Result); var updatedDocument = updatedSolution.GetTextDocument(document.Id); ApplyDocumentToBuffer(updatedDocument, spanSource, out container, out documentBackedByTextBuffer); _previewWorkspace.TryApplyChanges(documentBackedByTextBuffer.Project.Solution); _previewWorkspace.OpenDocument(document.Id); _currentDocument = document.Id; } else { _currentDocument = document.Id; ApplyDocumentToBuffer(document, spanSource, out container, out documentBackedByTextBuffer); _previewWorkspace = new PreviewDialogWorkspace(documentBackedByTextBuffer.Project.Solution); _previewWorkspace.OpenDocument(document.Id); } }
public void SetDocument(SourceTextContainer textContainer) { var currentSolution = _workspace.CurrentSolution; var project = CreateSubmissionProject(currentSolution); var currentDocument = SetSubmissionDocument(textContainer, project); _currentDocumenId = currentDocument.Id; }
private Document SetSubmissionDocument(SourceTextContainer textContainer, Project project) { var id = DocumentId.CreateNewId(project.Id); var solution = project.Solution.AddDocument(id, project.Name, textContainer.CurrentText); _workspace.SetCurrentSolution(solution); _workspace.OpenDocument(id, textContainer); return solution.GetDocument(id); }
/// <summary> /// Creates a TextLoader from a SourceTextContainer and version. /// /// The text obtained from the loader will be the current text of the container at the time /// the loader is accessed. /// </summary> public static TextLoader From(SourceTextContainer container, VersionStamp version, string filePath = null) { if (container == null) { throw new ArgumentNullException("container"); } return new TextContainerLoader(container, version, filePath); }
/// <summary> /// Unregister a correspondence between a text container and a workspace. /// </summary> protected void UnregisterText(SourceTextContainer textContainer) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } GetWorkspaceRegistration(textContainer).SetWorkspaceAndRaiseEvents(null); }
internal TextTracker( Workspace workspace, DocumentId documentId, SourceTextContainer textContainer) { this.workspace = workspace; this.documentId = documentId; this.TextContainer = textContainer; }
/// <summary> /// Returns a <see cref="WorkspaceRegistration" /> for a given text container. /// </summary> public static WorkspaceRegistration GetWorkspaceRegistration(SourceTextContainer textContainer) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } return s_bufferToWorkspaceRegistrationMap.GetValue(textContainer, s_createRegistration); }
protected SourceText(ImmutableArray<byte> sha1Checksum = default(ImmutableArray<byte>), SourceTextContainer container = null) { if (!sha1Checksum.IsDefault && sha1Checksum.Length != CryptographicHashProvider.Sha1HashSize) { throw new ArgumentException(CodeAnalysisResources.InvalidSHA1Hash, "sha1Checksum"); } this.lazySha1Checksum = sha1Checksum; this.lazyContainer = container; }
/// <summary> /// Gets the workspace associated with the specific text container. /// </summary> public static bool TryGetWorkspace(SourceTextContainer textContainer, out Workspace workspace) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } var registration = GetWorkspaceRegistration(textContainer); workspace = registration.Workspace; return workspace != null; }
public DocumentActiveContextChangedEventArgs(Solution solution, SourceTextContainer sourceTextContainer, DocumentId oldActiveContextDocumentId, DocumentId newActiveContextDocumentId) { Contract.ThrowIfNull(solution); Contract.ThrowIfNull(sourceTextContainer); Contract.ThrowIfNull(oldActiveContextDocumentId); Contract.ThrowIfNull(newActiveContextDocumentId); this.Solution = solution; this.SourceTextContainer = sourceTextContainer; this.OldActiveContextDocumentId = oldActiveContextDocumentId; this.NewActiveContextDocumentId = newActiveContextDocumentId; }
protected SourceText(ImmutableArray<byte> checksum = default(ImmutableArray<byte>), SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1, SourceTextContainer container = null) { ValidateChecksumAlgorithm(checksumAlgorithm); if (!checksum.IsDefault && checksum.Length != CryptographicHashProvider.GetHashSize(checksumAlgorithm)) { throw new ArgumentException(CodeAnalysisResources.InvalidHash, nameof(checksum)); } _checksumAlgorithm = checksumAlgorithm; _lazyChecksum = checksum; _lazyContainer = container; }
/// <summary> /// Register a correspondence between a text container and a workspace. /// </summary> protected void RegisterText(SourceTextContainer textContainer) { if (textContainer == null) { throw new ArgumentNullException(nameof(textContainer)); } var registration = GetWorkspaceRegistration(textContainer); registration.SetWorkspace(this); this.ScheduleTask(() => { registration.RaiseEvents(); }, "Workspace.RegisterText"); }
internal TextTracker( Workspace workspace, DocumentId documentId, SourceTextContainer textContainer, Action<Workspace, DocumentId, SourceText, PreservationMode> onChangedHandler) { _workspace = workspace; _documentId = documentId; this.TextContainer = textContainer; _onChangedHandler = onChangedHandler; // use weak event so TextContainer cannot accidentally keep workspace alive. _weakOnTextChanged = WeakEventHandler<TextChangeEventArgs>.Create(this, (target, sender, args) => target.OnTextChanged(sender, args)); }
private void ApplyDocumentToBuffer(TextDocument document, SpanChange spanSource, out SourceTextContainer container, out TextDocument documentBackedByTextBuffer) { var contentTypeService = document.Project.LanguageServices.GetService<IContentTypeLanguageService>(); var contentType = contentTypeService.GetDefaultContentType(); TextView.TextBuffer.ChangeContentType(contentType, null); var documentText = document.GetTextAsync().Result.ToString(); SpanToShow = spanSource.GetSpan(); using (var edit = TextView.TextBuffer.CreateEdit()) { edit.Replace(new Span(0, TextView.TextBuffer.CurrentSnapshot.Length), documentText); edit.Apply(); } container = TextView.TextBuffer.AsTextContainer(); documentBackedByTextBuffer = document.WithText(container.CurrentText); }
internal TextContainerLoader(SourceTextContainer container, VersionStamp version, string filePath) { _container = container; _version = version; _filePath = filePath; }
internal new void UnregisterText(SourceTextContainer textContainer) { base.UnregisterText(textContainer); }
public void OpenDocument(DocumentId documentId, SourceTextContainer textContainer) { //_openTextContainer = textContainer; _openDocumentId = documentId; OnDocumentOpened(documentId, textContainer); }
public void OpenDocument(DocumentId documentId, SourceTextContainer textContainer) { OpenDocumentId = documentId; OnDocumentOpened(documentId, textContainer); OnDocumentContextUpdated(documentId); }
public TypeTarget(SourceTextContainer textContainer, ISymbol typeIdentifier, Solution solution) { _textContainer = textContainer; _typeIdentifier = typeIdentifier; _solution = solution; }
public async Task Initialize(SourceTextContainer sourceTextContainer, Action<DiagnosticsUpdatedArgs> onDiagnosticsUpdated, Action<SourceText> onTextUpdated) { var roslynHost = MainViewModel.RoslynHost; // ReSharper disable once AssignNullToNotNullAttribute DocumentId = roslynHost.AddDocument(sourceTextContainer, _workingDirectory, onDiagnosticsUpdated, onTextUpdated); await _executionHost.ResetAsync().ConfigureAwait(false); }
protected Task RaiseDocumentActiveContextChangedEventAsync(SourceTextContainer sourceTextContainer, DocumentId oldActiveContextDocumentId, DocumentId newActiveContextDocumentId) { var ev = _eventMap.GetEventHandlers<EventHandler<DocumentActiveContextChangedEventArgs>>(DocumentActiveContextChangedName); if (ev.HasHandlers && sourceTextContainer != null && oldActiveContextDocumentId != null && newActiveContextDocumentId != null) { // Capture the current solution snapshot (inside the _serializationLock of OnDocumentContextUpdated) var currentSolution = this.CurrentSolution; return this.ScheduleTask(() => { var args = new DocumentActiveContextChangedEventArgs(currentSolution, sourceTextContainer, oldActiveContextDocumentId, newActiveContextDocumentId); ev.RaiseEvent(handler => handler(this, args)); }, "Workspace.WorkspaceChanged"); } else { return SpecializedTasks.EmptyTask; } }
protected SourceText(SourceTextContainer container = null) { this.container = container; }
public void UnregisterTextContainer(SourceTextContainer container) { }
private static WorkspaceRegistration CreateRegistration(SourceTextContainer container) { return new WorkspaceRegistration(); }
internal TextContainerLoader(SourceTextContainer container, VersionStamp version, string filePath) { this.container = container; this.version = version; this.filePath = filePath; }
private static Workspace GetWorkspace(SourceTextContainer textContainer) { Workspace workspace; Workspace.TryGetWorkspace(textContainer, out workspace); return workspace; }
public void OpenDocument(DocumentId documentId, SourceTextContainer textContainer) { this.OnDocumentOpened(documentId, textContainer); }
protected SourceText(ImmutableArray <byte> checksum = default(ImmutableArray <byte>), SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1, SourceTextContainer container = null) { ValidateChecksumAlgorithm(checksumAlgorithm); if (!checksum.IsDefault && checksum.Length != CryptographicHashProvider.GetHashSize(checksumAlgorithm)) { throw new ArgumentException(CodeAnalysisResources.InvalidHash, nameof(checksum)); } _checksumAlgorithm = checksumAlgorithm; _lazyChecksum = checksum; _lazyContainer = container; }