public MemberTarget(SourceTextContainer textContainer, ISymbol memberIdentifier, Project project, Solution solution)
 {
     _textContainer = textContainer;
     _memberIdentifier = memberIdentifier;
     _project = project;
     _solution = solution;
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 public void SetDocument(SourceTextContainer textContainer)
 {
     var currentSolution = _workspace.CurrentSolution;
     var project = CreateSubmissionProject(currentSolution);
     var currentDocument = SetSubmissionDocument(textContainer, project);
     _currentDocumenId = currentDocument.Id;
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 7
0
 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;
        }
Exemplo n.º 12
0
        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");
        }
Exemplo n.º 14
0
            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));
            }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 internal TextContainerLoader(SourceTextContainer container, VersionStamp version, string filePath)
 {
     _container = container;
     _version = version;
     _filePath = filePath;
 }
Exemplo n.º 17
0
 internal new void UnregisterText(SourceTextContainer textContainer)
 {
     base.UnregisterText(textContainer);
 }
Exemplo n.º 18
0
 public void OpenDocument(DocumentId documentId, SourceTextContainer textContainer)
 {
     //_openTextContainer = textContainer;
     _openDocumentId = documentId;
     OnDocumentOpened(documentId, textContainer);
 }
Exemplo n.º 19
0
 public void OpenDocument(DocumentId documentId, SourceTextContainer textContainer)
 {
     OpenDocumentId = documentId;
     OnDocumentOpened(documentId, textContainer);
     OnDocumentContextUpdated(documentId);
 }
Exemplo n.º 20
0
 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);
 }
Exemplo n.º 22
0
        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;
            }
        }
Exemplo n.º 23
0
 protected SourceText(SourceTextContainer container = null)
 {
     this.container = container;
 }
 public void UnregisterTextContainer(SourceTextContainer container)
 {
 }
 private static WorkspaceRegistration CreateRegistration(SourceTextContainer container)
 {
     return new WorkspaceRegistration();
 }
Exemplo n.º 26
0
 internal TextContainerLoader(SourceTextContainer container, VersionStamp version, string filePath)
 {
     this.container = container;
     this.version = version;
     this.filePath = filePath;
 }
Exemplo n.º 27
0
 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);
 }
Exemplo n.º 29
0
        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;
        }