Example #1
0
        internal TextDocument(Project project, TextDocumentState state)
        {
            Contract.ThrowIfNull(project);
            Contract.ThrowIfNull(state);

            this.Project = project;
            State        = state;
        }
Example #2
0
        public ProjectState AddAdditionalDocument(TextDocumentState document)
        {
            Debug.Assert(!this.AdditionalDocumentStates.ContainsKey(document.Id));

            return(this.With(
                       projectInfo: this.ProjectInfo.WithVersion(this.Version.GetNewerVersion()),
                       additionalDocumentIds: _additionalDocumentIds.Add(document.Id),
                       additionalDocumentStates: _additionalDocumentStates.Add(document.Id, document)));
        }
Example #3
0
 private AsyncLazy <VersionStamp> CreateLazyLatestDocumentTopLevelChangeVersion(
     TextDocumentState newDocument,
     IImmutableDictionary <DocumentId, DocumentState> newDocumentStates,
     IImmutableDictionary <DocumentId, TextDocumentState> newAdditionalDocumentStates)
 {
     if (_lazyLatestDocumentTopLevelChangeVersion.TryGetValue(out var oldVersion))
     {
         return(new AsyncLazy <VersionStamp>(c => ComputeTopLevelChangeTextVersionAsync(oldVersion, newDocument, c), cacheResult: true));
     }
     else
     {
         return(new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(newDocumentStates, newAdditionalDocumentStates, c), cacheResult: true));
     }
 }
Example #4
0
        public ProjectState UpdateAdditionalDocument(TextDocumentState newDocument, bool textChanged, bool recalculateDependentVersions)
        {
            Debug.Assert(this.ContainsAdditionalDocument(newDocument.Id));

            var oldDocument = this.GetAdditionalDocumentState(newDocument.Id);

            if (oldDocument == newDocument)
            {
                return(this);
            }

            var newDocumentStates = _additionalDocumentStates.SetItem(newDocument.Id, newDocument);

            GetLatestDependentVersions(
                _documentStates, newDocumentStates, oldDocument, newDocument, recalculateDependentVersions, textChanged,
                out var dependentDocumentVersion, out var dependentSemanticVersion);

            return(this.With(
                       additionalDocumentStates: newDocumentStates,
                       latestDocumentVersion: dependentDocumentVersion,
                       latestDocumentTopLevelChangeVersion: dependentSemanticVersion));
        }
Example #5
0
        private void GetLatestDependentVersions(
            IImmutableDictionary <DocumentId, DocumentState> newDocumentStates,
            IImmutableDictionary <DocumentId, TextDocumentState> newAdditionalDocumentStates,
            TextDocumentState oldDocument, TextDocumentState newDocument,
            bool recalculateDependentVersions, bool textChanged,
            out AsyncLazy <VersionStamp> dependentDocumentVersion, out AsyncLazy <VersionStamp> dependentSemanticVersion)
        {
            var recalculateDocumentVersion = false;
            var recalculateSemanticVersion = false;

            if (recalculateDependentVersions)
            {
                if (oldDocument.TryGetTextVersion(out var oldVersion))
                {
                    if (!_lazyLatestDocumentVersion.TryGetValue(out var documentVersion) || documentVersion == oldVersion)
                    {
                        recalculateDocumentVersion = true;
                    }

                    if (!_lazyLatestDocumentTopLevelChangeVersion.TryGetValue(out var semanticVersion) || semanticVersion == oldVersion)
                    {
                        recalculateSemanticVersion = true;
                    }
                }
            }

            dependentDocumentVersion = recalculateDocumentVersion ?
                                       new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentVersionAsync(newDocumentStates, newAdditionalDocumentStates, c), cacheResult: true) :
                                       textChanged ?
                                       new AsyncLazy <VersionStamp>(newDocument.GetTextVersionAsync, cacheResult: true) :
                                       _lazyLatestDocumentVersion;

            dependentSemanticVersion = recalculateSemanticVersion ?
                                       new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(newDocumentStates, newAdditionalDocumentStates, c), cacheResult: true) :
                                       textChanged?
                                       CreateLazyLatestDocumentTopLevelChangeVersion(newDocument, newDocumentStates, newAdditionalDocumentStates) :
                                           _lazyLatestDocumentTopLevelChangeVersion;
        }
Example #6
0
        public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices)
        {
            Contract.ThrowIfNull(projectInfo);
            Contract.ThrowIfNull(languageServices);
            Contract.ThrowIfNull(solutionServices);

            _languageServices = languageServices;
            _solutionServices = solutionServices;

            var projectInfoFixed = FixProjectInfo(projectInfo);

            _documentIds           = projectInfoFixed.Documents.Select(d => d.Id).ToImmutableList();
            _additionalDocumentIds = projectInfoFixed.AdditionalDocuments.Select(d => d.Id).ToImmutableList();

            var parseOptions = projectInfoFixed.ParseOptions;
            var docStates    = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                     projectInfoFixed.Documents.Select(d =>
                                                                                                       new KeyValuePair <DocumentId, DocumentState>(d.Id,
                                                                                                                                                    CreateDocument(d, parseOptions, languageServices, solutionServices))));

            _documentStates = docStates;

            var additionalDocStates = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                            projectInfoFixed.AdditionalDocuments.Select(d =>
                                                                                                                        new KeyValuePair <DocumentId, TextDocumentState>(d.Id, TextDocumentState.Create(d, solutionServices))));

            _additionalDocumentStates = additionalDocStates;

            _lazyLatestDocumentVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentVersionAsync(docStates, additionalDocStates, c), cacheResult: true);
            _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, additionalDocStates, c), cacheResult: true);

            // ownership of information on document has moved to project state. clear out documentInfo the state is
            // holding on. otherwise, these information will be held onto unnecesarily by projectInfo even after
            // the info has changed by DocumentState.
            // we hold onto the info so that we don't need to duplicate all information info already has in the state
            _projectInfo = ClearAllDocumentsFromProjectInfo(projectInfoFixed);

            _lazyChecksums = new AsyncLazy <ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true);
        }
Example #7
0
        private static async Task <VersionStamp> ComputeTopLevelChangeTextVersionAsync(VersionStamp oldVersion, TextDocumentState newDocument, CancellationToken cancellationToken)
        {
            var newVersion = await newDocument.GetTopLevelChangeTextVersionAsync(cancellationToken).ConfigureAwait(false);

            return(newVersion.GetNewerVersion(oldVersion));
        }