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)); }
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); }
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 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)); }
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)); }
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; }
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; }
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; }
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; }
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); }
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); }
public AbstractSyntaxTreeFactoryService(ILanguageServiceProvider languageServices) { this.languageServices = languageServices; }
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)); }
public CSharpSyntaxTreeFactoryService(ILanguageServiceProvider languageServices) : base(languageServices) { }
/// <summary> /// Sets instance /// </summary> /// <param name="languageServiceProvider"></param> public static void SetInstance(ILanguageServiceProvider languageServiceProvider) { _instance = languageServiceProvider ?? throw new ArgumentNullException(nameof(languageServiceProvider)); }
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); }
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()); }
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) { return(new CompletionServiceWrapper(GetCompletionServiceMethod.Invoke <ILanguageService>(provider))); }
public ILanguageService CreateLanguageService(ILanguageServiceProvider provider) { return(new CSharpCodeGenerationService(provider)); }
public ILanguageService CreateLanguageService(ILanguageServiceProvider provider) { return new CSharpCodeGenerationService(provider); }
public ILanguageService CreateLanguageService(ILanguageServiceProvider provider) { return new CSharpCodeCleanerService(); }
public CSharpCodeGenerationService(ILanguageServiceProvider languageServices) : base(languageServices.GetService <ISymbolDeclarationService>()) { }