Ejemplo n.º 1
0
        public static DocumentState Create(
            DocumentInfo info,
            ParseOptions options,
            ILanguageServiceProvider language,
            SolutionServices services)
        {
            var textSource = info.TextLoader != null
                ? CreateRecoverableText(info.TextLoader, info.Id, services)
                : CreateStrongText(TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default, info.FilePath));

            var treeSource = CreateLazyFullyParsedTree(
                textSource,
                GetSyntaxTreeFilePath(info),
                options,
                workspaceServices: services.WorkspaceServices,
                languageServices: language);

            // remove any initial loader so we don't keep source alive
            info = info.WithTextLoader(null);

            return new DocumentState(
                languageServices: language,
                solutionServices: services,
                info: info,
                options: options,
                textSource: textSource,
                treeSource: treeSource);
        }
Ejemplo n.º 2
0
 private DocumentState(
     ILanguageServiceProvider languageServices,
     SolutionServices solutionServices,
     DocumentInfo info,
     ParseOptions options,
     ValueSource<TextAndVersion> textSource,
     ValueSource<TreeAndVersion> treeSource)
 {
     this.languageServices = languageServices;
     this.solutionServices = solutionServices;
     this.info = info;
     this.options = options;
     this.textSource = textSource;
     this.treeSource = treeSource;
 }
Ejemplo n.º 3
0
 private ProjectState(
     ProjectInfo projectInfo,
     ILanguageServiceProvider languageServices,
     SolutionServices solutionServices,
     ImmutableList<DocumentId> documentIds,
     ImmutableDictionary<DocumentId, DocumentState> documentStates,
     AsyncLazy<VersionStamp> lazyLatestDocumentVersion,
     AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion)
 {
     this.projectInfo = projectInfo;
     this.solutionServices = solutionServices;
     this.languageServices = languageServices;
     this.documentIds = documentIds;
     this.documentStates = documentStates;
     this.lazyLatestDocumentVersion = lazyLatestDocumentVersion;
     this.lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion;
 }
Ejemplo n.º 4
0
        internal ProjectState(ProjectInfo projectInfo, ILanguageServiceProvider languageServiceProvider, SolutionServices solutionServices)
        {
            Contract.ThrowIfNull(projectInfo);
            Contract.ThrowIfNull(languageServiceProvider);
            Contract.ThrowIfNull(solutionServices);

            this.languageServices = languageServiceProvider;
            this.solutionServices = solutionServices;

            this.projectInfo = FixProjectInfo(projectInfo);

            this.documentIds = this.projectInfo.Documents.Select(d => d.Id).ToImmutableList();

            var docStates = ImmutableDictionary.CreateRange<DocumentId, DocumentState>(
                this.projectInfo.Documents.Select(d =>
                    new KeyValuePair<DocumentId, DocumentState>(d.Id,
                        CreateDocument(this.ProjectInfo, d, languageServiceProvider, solutionServices))));

            this.documentStates = docStates;

            this.lazyLatestDocumentVersion = new AsyncLazy<VersionStamp>(this.ComputeLatestDocumentVersionAsync, cacheResult: true);
            this.lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy<VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, c), cacheResult: true);
        }
Ejemplo n.º 5
0
        private static DocumentState CreateDocument(ProjectInfo projectInfo, DocumentInfo documentInfo, ILanguageServiceProvider languageServices, SolutionServices solutionServices)
        {
            var doc = DocumentState.Create(documentInfo, projectInfo.ParseOptions, languageServices, solutionServices);

            if (doc.SourceCodeKind != documentInfo.SourceCodeKind)
            {
                doc = doc.UpdateSourceCodeKind(documentInfo.SourceCodeKind);
            }

            return doc;
        }
 public CSharpSyntaxTreeFactoryService(ILanguageServiceProvider languageServices) : base(languageServices)
 {
 }
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return new CSharpSyntaxTreeFactoryService(provider);
 }
Ejemplo n.º 8
0
        private static async Task<TreeAndVersion> FullyParseTreeAsync(
            ValueSource<TextAndVersion> newTextSource,
            string filePath,
            ParseOptions options,
            IWorkspaceServiceProvider workspaceServices,
            ILanguageServiceProvider languageServices,
            PreservationMode mode,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FeatureId.DocumentState, FunctionId.DocumentState_FullyParseSyntaxTree, cancellationToken))
            {
                var textAndVersion = await newTextSource.GetValueAsync(cancellationToken).ConfigureAwait(false);
                var text = textAndVersion.Text;

                var treeFactory = languageServices.GetService<ISyntaxTreeFactoryService>();

                var tree = treeFactory.ParseSyntaxTree(filePath, options, text, cancellationToken);

                if (mode == PreservationMode.PreserveValue)
                {
                    var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false);

                    // get a recoverable tree that reparses from the source text if it gets used after being kicked out of memory
                    tree = treeFactory.CreateRecoverableTree(tree.FilePath, tree.Options, newTextSource, root, reparse: true);
                }

                Contract.ThrowIfNull(tree);

                // text version for this document should be unique. use it as a starting point.
                return TreeAndVersion.Create(tree, textAndVersion.Version);
            }
        }
Ejemplo n.º 9
0
 private static ValueSource<TreeAndVersion> CreateLazyFullyParsedTree(
     ValueSource<TextAndVersion> newTextSource,
     string filePath,
     ParseOptions options,
     IWorkspaceServiceProvider workspaceServices,
     ILanguageServiceProvider languageServices,
     PreservationMode mode = PreservationMode.PreserveValue)
 {
     return new AsyncLazy<TreeAndVersion>(
         c => FullyParseTreeAsync(newTextSource, filePath, options, workspaceServices, languageServices, mode, c),
         cacheResult: true);
 }
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return new CSharpCodeGenerationService(provider);
 }
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return new CSharpCodeCleanerService();
 }
 public AbstractSyntaxTreeFactoryService(ILanguageServiceProvider languageServices)
 {
     this.languageServices = languageServices;
 }