public CodeModelState( IServiceProvider serviceProvider, HostLanguageServices languageServices, VisualStudioWorkspace workspace) { Debug.Assert(serviceProvider != null); Debug.Assert(languageServices != null); Debug.Assert(workspace != null); this.ServiceProvider = serviceProvider; this.CodeModelService = languageServices.GetService<ICodeModelService>(); this.SyntaxFactsService = languageServices.GetService<ISyntaxFactsService>(); this.CodeGenerator = languageServices.GetService<ICodeGenerationService>(); this.Workspace = workspace; }
public VsLanguageDebugInfo( Guid languageId, TLanguageService languageService, HostLanguageServices languageServiceProvider, IWaitIndicator waitIndicator) { Contract.ThrowIfNull(languageService); Contract.ThrowIfNull(languageServiceProvider); _languageId = languageId; _languageService = languageService; _languageDebugInfo = languageServiceProvider.GetService <ILanguageDebugInfoService>(); _breakpointService = languageServiceProvider.GetService <IBreakpointResolutionService>(); _proximityExpressionsService = languageServiceProvider.GetService <IProximityExpressionsService>(); _waitIndicator = waitIndicator; }
private static ParseOptions GetParseOptionsWorker(XElement projectElement, string language, HostLanguageServices languageServices) { ParseOptions parseOptions; var preprocessorSymbolsAttribute = projectElement.Attribute(PreprocessorSymbolsAttributeName); if (preprocessorSymbolsAttribute != null) { parseOptions = GetPreProcessorParseOptions(language, preprocessorSymbolsAttribute); } else { parseOptions = languageServices.GetService <ISyntaxTreeFactoryService>().GetDefaultParseOptions(); } var languageVersionAttribute = projectElement.Attribute(LanguageVersionAttributeName); if (languageVersionAttribute != null) { parseOptions = GetParseOptionsWithLanguageVersion(language, parseOptions, languageVersionAttribute); } var documentationMode = GetDocumentationMode(projectElement); if (documentationMode != null) { parseOptions = parseOptions.WithDocumentationMode(documentationMode.Value); } return(parseOptions); }
private static TreeAndVersion CreateTreeAndVersion( ValueSource <TextAndVersion> newTextSource, ProjectId cacheKey, string filePath, ParseOptions options, HostLanguageServices languageServices, PreservationMode mode, TextAndVersion textAndVersion, CancellationToken cancellationToken) { var text = textAndVersion.Text; var treeFactory = languageServices.GetService <ISyntaxTreeFactoryService>(); var tree = treeFactory.ParseSyntaxTree(filePath, options, text, cancellationToken); var root = tree.GetRoot(cancellationToken); if (mode == PreservationMode.PreserveValue && treeFactory.CanCreateRecoverableTree(root)) { tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, text.Encoding, root); } Contract.ThrowIfNull(tree); // text version for this document should be unique. use it as a starting point. return(TreeAndVersion.Create(tree, textAndVersion.Version)); }
private static async Task <TreeAndVersion> FullyParseTreeAsync( ValueSource <TextAndVersion> newTextSource, string filePath, ParseOptions options, HostLanguageServices 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)); } }
private static async Task <TreeAndVersion> FullyParseTreeAsync( ValueSource <TextAndVersion> newTextSource, ProjectId cacheKey, string filePath, ParseOptions options, HostLanguageServices languageServices, SolutionServices solutionServices, PreservationMode mode, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.Workspace_Document_State_FullyParseSyntaxTree, s_fullParseLog, filePath, mode, 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); var root = tree.GetRoot(cancellationToken); if (mode == PreservationMode.PreserveValue && treeFactory.CanCreateRecoverableTree(root)) { tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, text.Encoding, root); } Contract.ThrowIfNull(tree); // text version for this document should be unique. use it as a starting point. return(TreeAndVersion.Create(tree, textAndVersion.Version)); } }
internal static TestHostDocument CreateDocument( XElement documentElement, ExportProvider exportProvider, HostLanguageServices languageServiceProvider, ImmutableArray <string> roles) { string markupCode = documentElement.NormalizedValue(); var folders = GetFolders(documentElement); var optionsElement = documentElement.Element(ParseOptionsElementName); var codeKind = SourceCodeKind.Regular; if (optionsElement != null) { var attr = optionsElement.Attribute(KindAttributeName); codeKind = attr == null ? SourceCodeKind.Regular : (SourceCodeKind)Enum.Parse(typeof(SourceCodeKind), attr.Value); } MarkupTestFile.GetPositionAndSpans(markupCode, out var code, out var cursorPosition, out IDictionary <string, ImmutableArray <TextSpan> > spans); var documentServiceProvider = GetDocumentServiceProvider(documentElement); var contentTypeLanguageService = languageServiceProvider.GetService <IContentTypeLanguageService>(); var contentType = contentTypeLanguageService.GetDefaultContentType(); var textBuffer = EditorFactory.CreateBuffer(contentType.TypeName, exportProvider, code); return(new TestHostDocument( exportProvider, languageServiceProvider, textBuffer, filePath: string.Empty, cursorPosition, spans, codeKind, folders, isLinkFile: false, documentServiceProvider, roles: roles)); }
public VsLanguageDebugInfo( Guid languageId, TLanguageService languageService, HostLanguageServices languageServiceProvider, IUIThreadOperationExecutor uiThreadOperationExecutor) { Contract.ThrowIfNull(languageService); Contract.ThrowIfNull(languageServiceProvider); _languageId = languageId; _languageService = languageService; _languageDebugInfo = languageServiceProvider.GetService <ILanguageDebugInfoService>(); _breakpointService = languageServiceProvider.GetService <IBreakpointResolutionService>(); _proximityExpressionsService = languageServiceProvider.GetService <IProximityExpressionsService>(); _uiThreadOperationExecutor = uiThreadOperationExecutor; }
internal void SetProject(TestHostProject project) { _project = project; if (this.Id == null) { _id = DocumentId.CreateNewId(project.Id, this.Name); } else { Contract.ThrowIfFalse(project.Id == this.Id.ProjectId); } if (_languageServiceProvider == null) { _languageServiceProvider = project.LanguageServiceProvider; } if (this.TextBuffer == null) { var contentTypeService = _languageServiceProvider.GetService <IContentTypeLanguageService>(); var contentType = contentTypeService.GetDefaultContentType(); this.TextBuffer = _exportProvider.GetExportedValue <ITextBufferFactoryService>().CreateTextBuffer(_initialText, contentType); this.InitialTextSnapshot = this.TextBuffer.CurrentSnapshot; } }
public CodeModelState( IThreadingContext threadingContext, IServiceProvider serviceProvider, HostLanguageServices languageServices, VisualStudioWorkspace workspace) { Debug.Assert(threadingContext != null); Debug.Assert(serviceProvider != null); Debug.Assert(languageServices != null); Debug.Assert(workspace != null); this.ThreadingContext = threadingContext; this.ServiceProvider = serviceProvider; this.CodeModelService = languageServices.GetService <ICodeModelService>(); this.SyntaxFactsService = languageServices.GetService <ISyntaxFactsService>(); this.CodeGenerator = languageServices.GetService <ICodeGenerationService>(); this.Workspace = workspace; }
internal DocumentState UpdateTree(SyntaxNode newRoot, PreservationMode mode) { if (newRoot == null) { throw new ArgumentNullException(nameof(newRoot)); } var newTextVersion = this.GetNewerVersion(); var newTreeVersion = GetNewTreeVersionForUpdatedTree(newRoot, newTextVersion, mode); // determine encoding Encoding encoding; ImmutableDictionary <string, ReportDiagnostic> treeDiagnosticReportingOptions = null; if (this.TryGetSyntaxTree(out var priorTree)) { // this is most likely available since UpdateTree is normally called after modifying the existing tree. encoding = priorTree.Encoding; treeDiagnosticReportingOptions = priorTree.DiagnosticOptions; } else if (this.TryGetText(out var priorText)) { encoding = priorText.Encoding; } else { // the existing encoding was never observed so is unknown. encoding = null; } var syntaxTreeFactory = _languageServices.GetService <ISyntaxTreeFactoryService>(); var filePath = GetSyntaxTreeFilePath(this.Attributes); if (treeDiagnosticReportingOptions == null && filePath != null) { // Ideally we'd pass a cancellation token here but we don't have one to pass as the operation previously didn't take a cancellation token. // In practice, I don't suspect it will matter: GetValue will only do work if we haven't already computed the AnalyzerConfigSet for this project, // which would only happen if no tree was observed for any file in this project. Arbitrarily replacing trees without ever looking at the // original one is possible but unlikely. treeDiagnosticReportingOptions = _analyzerConfigSetSource.GetValue(CancellationToken.None).GetOptionsForSourcePath(filePath).TreeOptions; } var result = CreateRecoverableTextAndTree(newRoot, filePath, newTextVersion, newTreeVersion, encoding, this.Attributes, _options, treeDiagnosticReportingOptions, syntaxTreeFactory, mode); return(new DocumentState( this.LanguageServices, this.solutionServices, this.Services, this.Attributes, _options, _analyzerConfigSetSource, sourceTextOpt: null, textSource: result.Item1, treeSource: new ConstantValueSource <TreeAndVersion>(result.Item2))); }
protected ImmutableArray <IEmbeddedLanguage> GetLanguageProviders(HostLanguageServices?languageServices) { if (_languageProviders.IsDefault) { var languagesProvider = languageServices?.GetService <IEmbeddedLanguagesProvider>(); ImmutableInterlocked.InterlockedInitialize(ref _languageProviders, languagesProvider?.Languages ?? ImmutableArray <IEmbeddedLanguage> .Empty); } return(_languageProviders); }
public CodeModelState( IThreadingContext threadingContext, IServiceProvider serviceProvider, HostLanguageServices languageServices, VisualStudioWorkspace workspace, ProjectCodeModelFactory projectCodeModelFactory) { Debug.Assert(threadingContext != null); Debug.Assert(serviceProvider != null); Debug.Assert(languageServices != null); Debug.Assert(workspace != null); // ⚠ This code runs on the main thread. Language services accessed here should be preloaded in // ProjectCodemodelFactory to avoid blocking MEF operations. this.ThreadingContext = threadingContext; this.ServiceProvider = serviceProvider; this.CodeModelService = languageServices.GetService <ICodeModelService>(); this.SyntaxFactsService = languageServices.GetService <ISyntaxFactsService>(); this.CodeGenerator = languageServices.GetService <ICodeGenerationService>(); this.ProjectCodeModelFactory = projectCodeModelFactory; this.Workspace = workspace; }
private ProjectInfo FixProjectInfo(ProjectInfo projectInfo) { if (projectInfo.CompilationOptions == null) { var compilationFactory = _languageServices.GetService <ICompilationFactoryService>(); if (compilationFactory != null) { projectInfo = projectInfo.WithCompilationOptions(compilationFactory.GetDefaultCompilationOptions()); } } if (projectInfo.ParseOptions == null) { var syntaxTreeFactory = _languageServices.GetService <ISyntaxTreeFactoryService>(); if (syntaxTreeFactory != null) { projectInfo = projectInfo.WithParseOptions(syntaxTreeFactory.GetDefaultParseOptions()); } } return(projectInfo); }
public static IdeAnalyzerOptions GetIdeAnalyzerOptions(this IGlobalOptionService globalOptions, HostLanguageServices languageServices) { var language = languageServices.Language; var supportsCleanupOptions = languageServices.GetService <ISyntaxFormattingOptionsStorage>() != null; return(new( CrashOnAnalyzerException : globalOptions.GetOption(CrashOnAnalyzerException), FadeOutUnusedImports : globalOptions.GetOption(FadeOutUnusedImports, language), FadeOutUnreachableCode : globalOptions.GetOption(FadeOutUnreachableCode, language), ReportInvalidPlaceholdersInStringDotFormatCalls : globalOptions.GetOption(ReportInvalidPlaceholdersInStringDotFormatCalls, language), ReportInvalidRegexPatterns : globalOptions.GetOption(ReportInvalidRegexPatterns, language), ReportInvalidJsonPatterns : globalOptions.GetOption(ReportInvalidJsonPatterns, language), DetectAndOfferEditorFeaturesForProbableJsonStrings : globalOptions.GetOption(DetectAndOfferEditorFeaturesForProbableJsonStrings, language), CleanupOptions : supportsCleanupOptions ? globalOptions.GetCodeCleanupOptions(languageServices) : null)); }
public static IdeAnalyzerOptions GetIdeAnalyzerOptions(this IGlobalOptionService globalOptions, HostLanguageServices languageServices) { var language = languageServices.Language; var supportsLanguageSpecificOptions = languageServices.GetService <ISyntaxFormattingOptionsStorage>() != null; return(new() { CrashOnAnalyzerException = globalOptions.GetOption(CrashOnAnalyzerException), ReportInvalidPlaceholdersInStringDotFormatCalls = globalOptions.GetOption(ReportInvalidPlaceholdersInStringDotFormatCalls, language), ReportInvalidRegexPatterns = globalOptions.GetOption(ReportInvalidRegexPatterns, language), ReportInvalidJsonPatterns = globalOptions.GetOption(ReportInvalidJsonPatterns, language), DetectAndOfferEditorFeaturesForProbableJsonStrings = globalOptions.GetOption(DetectAndOfferEditorFeaturesForProbableJsonStrings, language), PreferSystemHashCode = globalOptions.GetOption(CodeStyleOptions2.PreferSystemHashCode, language), CleanCodeGenerationOptions = supportsLanguageSpecificOptions ? globalOptions.GetCleanCodeGenerationOptions(languageServices) : null, CodeStyleOptions = supportsLanguageSpecificOptions ? globalOptions.GetCodeStyleOptions(languageServices) : null, }); }
internal DocumentState UpdateTree(SyntaxNode newRoot, PreservationMode mode) { if (newRoot == null) { throw new ArgumentNullException(nameof(newRoot)); } var newTextVersion = this.GetNewerVersion(); var newTreeVersion = GetNewTreeVersionForUpdatedTree(newRoot, newTextVersion, mode); // determine encoding Encoding encoding; SyntaxTree priorTree; SourceText priorText; if (this.TryGetSyntaxTree(out priorTree)) { // this is most likely available since UpdateTree is normally called after modifying the existing tree. encoding = priorTree.Encoding; } else if (this.TryGetText(out priorText)) { encoding = priorText.Encoding; } else { // the existing encoding was never observed so is unknown. encoding = null; } var syntaxTreeFactory = _languageServices.GetService <ISyntaxTreeFactoryService>(); var result = CreateRecoverableTextAndTree(newRoot, newTextVersion, newTreeVersion, encoding, this.info, _options, syntaxTreeFactory, mode, this.solutionServices); return(new DocumentState( this.LanguageServices, this.solutionServices, this.info, _options, sourceTextOpt: null, textSource: result.Item1, treeSource: new ConstantValueSource <TreeAndVersion>(result.Item2), lazyChecksums: null)); }
public CSharpSyntaxClassificationService(HostLanguageServices languageServices) { var syntaxClassifiers = ImmutableArray <ISyntaxClassifier> .Empty; var embeddedLanguagesProvider = languageServices.GetService <IEmbeddedLanguagesProvider>(); if (embeddedLanguagesProvider != null) { syntaxClassifiers = syntaxClassifiers.Add(new EmbeddedLanguagesClassifier(embeddedLanguagesProvider)); } s_defaultSyntaxClassifiers = syntaxClassifiers.AddRange( new ISyntaxClassifier[] { new NameSyntaxClassifier(), new OperatorOverloadSyntaxClassifier(), new SyntaxTokenClassifier(), new UsingDirectiveSyntaxClassifier() }); }
private IEnumerable <ITagSpan <IClassificationTag> > GetTags( NormalizedSnapshotSpanCollection spans, HostLanguageServices languageServices) { var classificationService = languageServices.GetService <IClassificationService>(); if (classificationService == null) { return(null); } var classifiedSpans = ClassificationUtilities.GetOrCreateClassifiedSpanList(); foreach (var span in spans) { AddClassifiedSpans(classificationService, span, classifiedSpans); } return(ClassificationUtilities.ConvertAndReturnList( _typeMap, spans[0].Snapshot, classifiedSpans)); }
internal DocumentState UpdateTree(SyntaxNode newRoot, PreservationMode mode) { if (newRoot == null) { throw new ArgumentNullException("newRoot"); } var newTextVersion = this.GetNewerVersion(); var newTreeVersion = GetNewTreeVersionForUpdatedTree(newRoot, newTextVersion, mode); var syntaxTreeFactory = _languageServices.GetService <ISyntaxTreeFactoryService>(); var result = CreateRecoverableTextAndTree(newRoot, newTextVersion, newTreeVersion, this.info, _options, syntaxTreeFactory, mode, this.solutionServices); return(new DocumentState( this.LanguageServices, this.solutionServices, this.info, _options, textSource: result.Item1, treeSource: new ConstantValueSource <TreeAndVersion>(result.Item2))); }
private static TestHostDocument CreateDocument( TestWorkspace workspace, XElement workspaceElement, XElement documentElement, string language, ExportProvider exportProvider, HostLanguageServices languageServiceProvider, Dictionary <string, ITextBuffer> filePathToTextBufferMap, IDocumentServiceProvider documentServiceProvider, ref int documentId) { string markupCode; string filePath; var isLinkFileAttribute = documentElement.Attribute(IsLinkFileAttributeName); var isLinkFile = isLinkFileAttribute != null && ((bool?)isLinkFileAttribute).HasValue && ((bool?)isLinkFileAttribute).Value; if (isLinkFile) { // This is a linked file. Use the filePath and markup from the referenced document. var originalAssemblyName = documentElement.Attribute(LinkAssemblyNameAttributeName)?.Value; var originalProjectName = documentElement.Attribute(LinkProjectNameAttributeName)?.Value; if (originalAssemblyName == null && originalProjectName == null) { throw new ArgumentException($"Linked files must specify either a {LinkAssemblyNameAttributeName} or {LinkProjectNameAttributeName}"); } var originalProject = workspaceElement.Elements(ProjectElementName).FirstOrDefault(p => { if (originalAssemblyName != null) { return(p.Attribute(AssemblyNameAttributeName)?.Value == originalAssemblyName); } else { return(p.Attribute(ProjectNameAttribute)?.Value == originalProjectName); } }); if (originalProject == null) { if (originalProjectName != null) { throw new ArgumentException($"Linked file's {LinkProjectNameAttributeName} '{originalProjectName}' project not found."); } else { throw new ArgumentException($"Linked file's {LinkAssemblyNameAttributeName} '{originalAssemblyName}' project not found."); } } var originalDocumentPath = documentElement.Attribute(LinkFilePathAttributeName)?.Value; if (originalDocumentPath == null) { throw new ArgumentException($"Linked files must specify a {LinkFilePathAttributeName}"); } documentElement = originalProject.Elements(DocumentElementName).FirstOrDefault(d => { return(d.Attribute(FilePathAttributeName)?.Value == originalDocumentPath); }); if (documentElement == null) { throw new ArgumentException($"Linked file's LinkFilePath '{originalDocumentPath}' file not found."); } } markupCode = documentElement.NormalizedValue(); filePath = GetFilePath(workspace, documentElement, ref documentId); var folders = GetFolders(documentElement); var optionsElement = documentElement.Element(ParseOptionsElementName); // TODO: Allow these to be specified. var codeKind = SourceCodeKind.Regular; if (optionsElement != null) { var attr = optionsElement.Attribute(KindAttributeName); codeKind = attr == null ? SourceCodeKind.Regular : (SourceCodeKind)Enum.Parse(typeof(SourceCodeKind), attr.Value); } var contentTypeLanguageService = languageServiceProvider.GetService <IContentTypeLanguageService>(); var contentType = contentTypeLanguageService.GetDefaultContentType(); MarkupTestFile.GetPositionAndSpans(markupCode, out var code, out var cursorPosition, out IDictionary <string, ImmutableArray <TextSpan> > spans); var testDocumentServiceProvider = GetDocumentServiceProvider(documentElement); if (documentServiceProvider == null) { documentServiceProvider = testDocumentServiceProvider; } else if (testDocumentServiceProvider != null) { AssertEx.Fail($"The document attributes on file {filePath} conflicted"); } return(new TestHostDocument( exportProvider, languageServiceProvider, code, filePath, cursorPosition, spans, codeKind, folders, isLinkFile, documentServiceProvider)); }
public CSharpSyntaxTriviaService(HostLanguageServices provider) : base(provider.GetService<ISyntaxFactsService>(), (int)SyntaxKind.EndOfLineTrivia) { }
public ILanguageService CreateLanguageService(HostLanguageServices provider) { // This interface is implemented by the ICodeModelService as well, so just grab the other one and return it return provider.GetService<ICodeModelService>(); }
private static TreeAndVersion CreateTreeAndVersion( ValueSource<TextAndVersion> newTextSource, ProjectId cacheKey, string filePath, ParseOptions options, HostLanguageServices languageServices, PreservationMode mode, TextAndVersion textAndVersion, CancellationToken cancellationToken) { var text = textAndVersion.Text; var treeFactory = languageServices.GetService<ISyntaxTreeFactoryService>(); var tree = treeFactory.ParseSyntaxTree(filePath, options, text, cancellationToken); var root = tree.GetRoot(cancellationToken); if (mode == PreservationMode.PreserveValue && treeFactory.CanCreateRecoverableTree(root)) { tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, text.Encoding, root); } Contract.ThrowIfNull(tree); // text version for this document should be unique. use it as a starting point. return TreeAndVersion.Create(tree, textAndVersion.Version); }
internal static ImmutableArray <AbstractFormattingRule> GetDefaultFormattingRules(HostLanguageServices languageServices) => languageServices.GetService <ISyntaxFormattingService>()?.GetDefaultFormattingRules() ?? ImmutableArray <AbstractFormattingRule> .Empty;
public CSharpSyntaxTriviaService(HostLanguageServices provider) : base(provider.GetService <ISyntaxFactsService>(), (int)SyntaxKind.EndOfLineTrivia) { }
public CSharpMetadataAsSourceService(HostLanguageServices languageServices) : base(languageServices.GetService<ICodeGenerationService>()) { }
public ILanguageService CreateLanguageService(HostLanguageServices provider) { // This interface is implemented by the ICodeModelService as well, so just grab the other one and return it return(provider.GetService <ICodeModelService>()); }
private static ParseOptions GetParseOptionsWorker(XElement projectElement, string language, HostLanguageServices languageServices) { ParseOptions parseOptions; var preprocessorSymbolsAttribute = projectElement.Attribute(PreprocessorSymbolsAttributeName); if (preprocessorSymbolsAttribute != null) { parseOptions = GetPreProcessorParseOptions(language, preprocessorSymbolsAttribute); } else { parseOptions = languageServices.GetService<ISyntaxTreeFactoryService>().GetDefaultParseOptions(); } var languageVersionAttribute = projectElement.Attribute(LanguageVersionAttributeName); if (languageVersionAttribute != null) { parseOptions = GetParseOptionsWithLanguageVersion(language, parseOptions, languageVersionAttribute); } var documentationMode = GetDocumentationMode(projectElement); if (documentationMode != null) { parseOptions = parseOptions.WithDocumentationMode(documentationMode.Value); } return parseOptions; }
private static TestHostDocument CreateDocument( TestWorkspace workspace, XElement workspaceElement, XElement documentElement, string language, ExportProvider exportProvider, HostLanguageServices languageServiceProvider, Dictionary<string, ITextBuffer> filePathToTextBufferMap, ref int documentId) { string markupCode; string filePath; var isLinkFileAttribute = documentElement.Attribute(IsLinkFileAttributeName); bool isLinkFile = isLinkFileAttribute != null && ((bool?)isLinkFileAttribute).HasValue && ((bool?)isLinkFileAttribute).Value; if (isLinkFile) { // This is a linked file. Use the filePath and markup from the referenced document. var originalProjectName = documentElement.Attribute(LinkAssemblyNameAttributeName); var originalDocumentPath = documentElement.Attribute(LinkFilePathAttributeName); if (originalProjectName == null || originalDocumentPath == null) { throw new ArgumentException("Linked file specified without LinkAssemblyName or LinkFilePath."); } var originalProjectNameStr = originalProjectName.Value; var originalDocumentPathStr = originalDocumentPath.Value; var originalProject = workspaceElement.Elements(ProjectElementName).First(p => { var assemblyName = p.Attribute(AssemblyNameAttributeName); return assemblyName != null && assemblyName.Value == originalProjectNameStr; }); if (originalProject == null) { throw new ArgumentException("Linked file's LinkAssemblyName '{0}' project not found.", originalProjectNameStr); } var originalDocument = originalProject.Elements(DocumentElementName).First(d => { var documentPath = d.Attribute(FilePathAttributeName); return documentPath != null && documentPath.Value == originalDocumentPathStr; }); if (originalDocument == null) { throw new ArgumentException("Linked file's LinkFilePath '{0}' file not found.", originalDocumentPathStr); } markupCode = originalDocument.NormalizedValue(); filePath = GetFilePath(workspace, originalDocument, ref documentId); } else { markupCode = documentElement.NormalizedValue(); filePath = GetFilePath(workspace, documentElement, ref documentId); } var folders = GetFolders(documentElement); var optionsElement = documentElement.Element(ParseOptionsElementName); // TODO: Allow these to be specified. var codeKind = SourceCodeKind.Regular; if (optionsElement != null) { var attr = optionsElement.Attribute(KindAttributeName); codeKind = attr == null ? SourceCodeKind.Regular : (SourceCodeKind)Enum.Parse(typeof(SourceCodeKind), attr.Value); } var contentTypeLanguageService = languageServiceProvider.GetService<IContentTypeLanguageService>(); var contentType = contentTypeLanguageService.GetDefaultContentType(); string code; int? cursorPosition; IDictionary<string, IList<TextSpan>> spans; MarkupTestFile.GetPositionAndSpans(markupCode, out code, out cursorPosition, out spans); // For linked files, use the same ITextBuffer for all linked documents ITextBuffer textBuffer; if (!filePathToTextBufferMap.TryGetValue(filePath, out textBuffer)) { textBuffer = EditorFactory.CreateBuffer(contentType.TypeName, exportProvider, code); filePathToTextBufferMap.Add(filePath, textBuffer); } return new TestHostDocument(exportProvider, languageServiceProvider, textBuffer, filePath, cursorPosition, spans, codeKind, folders, isLinkFile); }
private static async Task<TreeAndVersion> FullyParseTreeAsync( ValueSource<TextAndVersion> newTextSource, string filePath, ParseOptions options, HostLanguageServices 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 CSharpSymbolDisplayService(HostLanguageServices provider) : base(provider.GetService<IAnonymousTypeDisplayService>()) { }
public CSharpSymbolDisplayService(HostLanguageServices provider) : base(provider.GetService <IAnonymousTypeDisplayService>()) { }
public CSharpMetadataAsSourceService(HostLanguageServices languageServices) : base(languageServices.GetService <ICodeGenerationService>()) { }
private static async Task<TreeAndVersion> FullyParseTreeAsync( ValueSource<TextAndVersion> newTextSource, ProjectId cacheKey, string filePath, ParseOptions options, HostLanguageServices languageServices, SolutionServices solutionServices, PreservationMode mode, CancellationToken cancellationToken) { using (Logger.LogBlock(FunctionId.Workspace_Document_State_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 && solutionServices.SupportsCachingRecoverableObjects) { var root = await tree.GetRootAsync(cancellationToken).ConfigureAwait(false); tree = treeFactory.CreateRecoverableTree(cacheKey, tree.FilePath, tree.Options, newTextSource, root); } Contract.ThrowIfNull(tree); // text version for this document should be unique. use it as a starting point. return TreeAndVersion.Create(tree, textAndVersion.Version); } }
protected AbstractSymbolDisplayService(HostLanguageServices services) { Services = services; AnonymousTypeDisplayService = services.GetService <IStructuralTypeDisplayService>(); }
private static TestHostDocument CreateDocument( TestWorkspace workspace, XElement workspaceElement, XElement documentElement, string language, ExportProvider exportProvider, HostLanguageServices languageServiceProvider, Dictionary <string, ITextBuffer> filePathToTextBufferMap, ref int documentId) { string markupCode; string filePath; var isLinkFileAttribute = documentElement.Attribute(IsLinkFileAttributeName); bool isLinkFile = isLinkFileAttribute != null && ((bool?)isLinkFileAttribute).HasValue && ((bool?)isLinkFileAttribute).Value; if (isLinkFile) { // This is a linked file. Use the filePath and markup from the referenced document. var originalProjectName = documentElement.Attribute(LinkAssemblyNameAttributeName); var originalDocumentPath = documentElement.Attribute(LinkFilePathAttributeName); if (originalProjectName == null || originalDocumentPath == null) { throw new ArgumentException("Linked file specified without LinkAssemblyName or LinkFilePath."); } var originalProjectNameStr = originalProjectName.Value; var originalDocumentPathStr = originalDocumentPath.Value; var originalProject = workspaceElement.Elements(ProjectElementName).First(p => { var assemblyName = p.Attribute(AssemblyNameAttributeName); return(assemblyName != null && assemblyName.Value == originalProjectNameStr); }); if (originalProject == null) { throw new ArgumentException("Linked file's LinkAssemblyName '{0}' project not found.", originalProjectNameStr); } var originalDocument = originalProject.Elements(DocumentElementName).First(d => { var documentPath = d.Attribute(FilePathAttributeName); return(documentPath != null && documentPath.Value == originalDocumentPathStr); }); if (originalDocument == null) { throw new ArgumentException("Linked file's LinkFilePath '{0}' file not found.", originalDocumentPathStr); } markupCode = originalDocument.NormalizedValue(); filePath = GetFilePath(workspace, originalDocument, ref documentId); } else { markupCode = documentElement.NormalizedValue(); filePath = GetFilePath(workspace, documentElement, ref documentId); } var folders = GetFolders(documentElement); var optionsElement = documentElement.Element(ParseOptionsElementName); // TODO: Allow these to be specified. var codeKind = SourceCodeKind.Regular; if (optionsElement != null) { var attr = optionsElement.Attribute(KindAttributeName); codeKind = attr == null ? SourceCodeKind.Regular : (SourceCodeKind)Enum.Parse(typeof(SourceCodeKind), attr.Value); } var contentTypeLanguageService = languageServiceProvider.GetService <IContentTypeLanguageService>(); var contentType = contentTypeLanguageService.GetDefaultContentType(); string code; int? cursorPosition; IDictionary <string, IList <TextSpan> > spans; MarkupTestFile.GetPositionAndSpans(markupCode, out code, out cursorPosition, out spans); // For linked files, use the same ITextBuffer for all linked documents ITextBuffer textBuffer; if (!filePathToTextBufferMap.TryGetValue(filePath, out textBuffer)) { textBuffer = EditorFactory.CreateBuffer(contentType.TypeName, exportProvider, code); filePathToTextBufferMap.Add(filePath, textBuffer); } return(new TestHostDocument(exportProvider, languageServiceProvider, textBuffer, filePath, cursorPosition, spans, codeKind, folders, isLinkFile)); }
public CSharpCodeGenerationService(HostLanguageServices languageServices) : base(languageServices.GetService <ISymbolDeclarationService>(), languageServices.WorkspaceServices.Workspace) { }
#pragma warning disable CS0618 // Type or member is obsolete public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(new ProxyService(languageServices.GetService <IEditorClassificationService>())); }