Esempio 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));
        }
Esempio n. 2
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);
        }
Esempio n. 3
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));
            }
        }
Esempio n. 4
0
 public StaticProviderHack(ILanguageServiceProvider languageServiceProvider)
 {
     if (languageServiceProvider == null)
     {
         throw new ArgumentNullException(nameof(languageServiceProvider));
     }
     StaticInstanceForILanguageServiceProvider.SetInstance(languageServiceProvider);
 }
 /// <summary>
 /// Create a new instance of <see cref="DefaultTranslationAccessor"/>.
 /// </summary>
 /// <param name="textProvider"></param>
 /// <param name="languageServiceProvider"></param>
 /// <param name="currentLanguageTagFactory"></param>
 public DefaultTranslationAccessor(
     ITextProvider textProvider,
     ILanguageServiceProvider languageServiceProvider,
     ICoreScopedLanguageTagFactory currentLanguageTagFactory)
 {
     _textProvider            = textProvider ?? throw new ArgumentNullException(nameof(textProvider));
     _languageServiceProvider = languageServiceProvider ?? throw new ArgumentNullException(nameof(languageServiceProvider));
     _currentLanguageTag      = (currentLanguageTagFactory ?? throw new ArgumentNullException(nameof(currentLanguageTagFactory))).Get();
 }
        public static IEnumerable <Lazy <T, TMetadata> > SelectMatchingExtensions <T, TMetadata>(
            this ILanguageServiceProvider serviceProvider,
            IEnumerable <Lazy <T, TMetadata> > items)
            where TMetadata : ILanguageMetadata
        {
            if (items == null)
            {
                return(SpecializedCollections.EmptyEnumerable <Lazy <T, TMetadata> >());
            }

            return(items.Where(lazy => lazy.Metadata.Language == serviceProvider.Language));
        }
Esempio n. 7
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 static ICompletionService GetCompletionService(this ILanguageServiceProvider provider)
        {
            var serviceType = typeof(ILanguageService);

            var methodInfo = provider.GetMethodInfo(x => x.GetService <ILanguageService>());
            var genericMethodDefinition = methodInfo.GetGenericMethodDefinition();

            var typeName      = string.Format("{0}.{1}", serviceType.Namespace, typeof(ICompletionService).Name);
            var genericMethod = genericMethodDefinition.MakeGenericMethod(serviceType.Assembly.GetType(typeName));

            var service = genericMethod.Invoke(provider, null) as ILanguageService;

            return(new CompletionService(service));
        }
Esempio n. 9
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;
 }
Esempio n. 10
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;
 }
Esempio n. 11
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;
 }
Esempio n. 12
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;
 }
Esempio n. 13
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);
        }
Esempio n. 14
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);
        }
Esempio n. 15
0
 public AbstractSyntaxTreeFactoryService(ILanguageServiceProvider languageServices)
 {
     this.languageServices = languageServices;
 }
Esempio n. 16
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;
        }
Esempio n. 17
0
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return(new CSharpSyntaxTreeFactoryService(provider));
 }
Esempio n. 18
0
 public CSharpSyntaxTreeFactoryService(ILanguageServiceProvider languageServices) : base(languageServices)
 {
 }
 public CSharpSyntaxTreeFactoryService(ILanguageServiceProvider languageServices) : base(languageServices)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Sets instance
 /// </summary>
 /// <param name="languageServiceProvider"></param>
 public static void SetInstance(ILanguageServiceProvider languageServiceProvider)
 {
     _instance = languageServiceProvider ?? throw new ArgumentNullException(nameof(languageServiceProvider));
 }
Esempio n. 21
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 ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return new CSharpSyntaxTreeFactoryService(provider);
 }
Esempio n. 23
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);
            }
        }
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return(new CSharpCodeCleanerService());
 }
Esempio n. 25
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);
 }
Esempio n. 26
0
 public static ICompletionService GetCompletionService(this ILanguageServiceProvider provider)
 {
     return(new CompletionServiceWrapper(GetCompletionServiceMethod.Invoke <ILanguageService>(provider)));
 }
Esempio n. 27
0
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return(new CSharpCodeGenerationService(provider));
 }
 public AbstractSyntaxTreeFactoryService(ILanguageServiceProvider languageServices)
 {
     this.languageServices = languageServices;
 }
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return new CSharpCodeGenerationService(provider);
 }
 public ILanguageService CreateLanguageService(ILanguageServiceProvider provider)
 {
     return new CSharpCodeCleanerService();
 }
Esempio n. 31
0
 public CSharpCodeGenerationService(ILanguageServiceProvider languageServices)
     : base(languageServices.GetService <ISymbolDeclarationService>())
 {
 }