internal ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices) { Contract.ThrowIfNull(projectInfo); Contract.ThrowIfNull(languageServices); Contract.ThrowIfNull(solutionServices); _languageServices = languageServices; _solutionServices = solutionServices; _projectInfo = FixProjectInfo(projectInfo); _documentIds = _projectInfo.Documents.Select(d => d.Id).ToImmutableArray(); _additionalDocumentIds = this.ProjectInfo.AdditionalDocuments.Select(d => d.Id).ToImmutableArray(); var docStates = ImmutableDictionary.CreateRange<DocumentId, DocumentState>( _projectInfo.Documents.Select(d => new KeyValuePair<DocumentId, DocumentState>(d.Id, CreateDocument(this.ProjectInfo, d, languageServices, solutionServices)))); _documentStates = docStates; var additionalDocStates = ImmutableDictionary.CreateRange<DocumentId, TextDocumentState>( _projectInfo.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); }
public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices) { Contract.ThrowIfNull(projectInfo); Contract.ThrowIfNull(languageServices); Contract.ThrowIfNull(solutionServices); _languageServices = languageServices; _solutionServices = solutionServices; _projectInfo = FixProjectInfo(projectInfo); _documentIds = _projectInfo.Documents.Select(d => d.Id).ToImmutableArray(); _additionalDocumentIds = _projectInfo.AdditionalDocuments.Select(d => d.Id).ToImmutableArray(); var docStates = ImmutableDictionary.CreateRange<DocumentId, DocumentState>( _projectInfo.Documents.Select(d => new KeyValuePair<DocumentId, DocumentState>(d.Id, CreateDocument(_projectInfo, d, languageServices, solutionServices)))); _documentStates = docStates; var additionalDocStates = ImmutableDictionary.CreateRange<DocumentId, TextDocumentState>( _projectInfo.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); // for now, let it re-calculate if anything changed. // TODO: optimize this so that we only re-calcuate checksums that are actually changed _lazyChecksums = new AsyncLazy<ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
public static DocumentState Create( DocumentInfo info, ParseOptions options, HostLanguageServices language, SolutionServices services) { var textSource = info.TextLoader != null ? CreateRecoverableText(info.TextLoader, info.Id, services) : CreateStrongText(TextAndVersion.Create(SourceText.From(string.Empty, Encoding.UTF8), VersionStamp.Default, info.FilePath)); var treeSource = CreateLazyFullyParsedTree( textSource, GetSyntaxTreeFilePath(info), options, 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 ProjectState( ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices, IEnumerable<DocumentId> documentIds, IEnumerable<DocumentId> additionalDocumentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, ImmutableDictionary<DocumentId, TextDocumentState> additionalDocumentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion, ValueSource<ProjectStateChecksums> lazyChecksums) { _projectInfo = projectInfo; _solutionServices = solutionServices; _languageServices = languageServices; _documentIds = documentIds.ToImmutableReadOnlyListOrEmpty(); _additionalDocumentIds = additionalDocumentIds.ToImmutableReadOnlyListOrEmpty(); _documentStates = documentStates; _additionalDocumentStates = additionalDocumentStates; _lazyLatestDocumentVersion = lazyLatestDocumentVersion; _lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; // for now, let it re-calculate if anything changed. // TODO: optimize this so that we only re-calcuate checksums that are actually changed _lazyChecksums = new AsyncLazy<ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
public TestHostSolution( HostLanguageServices languageServiceProvider, CompilationOptions compilationOptions, ParseOptions parseOptions, params MetadataReference[] references) : this(new TestHostProject(languageServiceProvider, compilationOptions, parseOptions, references)) { }
internal CSharpCodeModelService( HostLanguageServices languageServiceProvider, IEditorOptionsFactoryService editorOptionsFactoryService, IEnumerable<IRefactorNotifyService> refactorNotifyServices) : base(languageServiceProvider, editorOptionsFactoryService, refactorNotifyServices, new BlankLineInGeneratedMethodFormattingRule(), new EndRegionFormattingRule()) { }
private static ValueSource<TreeAndVersion> CreateLazyFullyParsedTree( ValueSource<TextAndVersion> newTextSource, string filePath, ParseOptions options, HostLanguageServices languageServices, PreservationMode mode = PreservationMode.PreserveValue) { return new AsyncLazy<TreeAndVersion>( c => FullyParseTreeAsync(newTextSource, filePath, options, languageServices, mode, c), cacheResult: true); }
private DocumentState( HostLanguageServices languageServices, SolutionServices solutionServices, DocumentInfo info, ParseOptions options, ValueSource<TextAndVersion> textSource, ValueSource<TreeAndVersion> treeSource) : base(solutionServices, info, textSource) { _languageServices = languageServices; _options = options; _treeSource = treeSource; }
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; }
private DocumentState( HostLanguageServices 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, HostLanguageServices languageServices, SolutionServices solutionServices, IEnumerable<DocumentId> documentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion) { this.projectInfo = projectInfo; this.solutionServices = solutionServices; this.languageServices = languageServices; this.documentIds = documentIds.ToImmutableReadOnlyListOrEmpty(); this.documentStates = documentStates; this.lazyLatestDocumentVersion = lazyLatestDocumentVersion; this.lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; }
private DocumentState( HostLanguageServices languageServices, SolutionServices solutionServices, DocumentInfo info, ParseOptions options, ValueSource<TextAndVersion> textSource, ValueSource<TreeAndVersion> treeSource) : base(solutionServices, info, textSource) { _languageServices = languageServices; _options = options; // If this is document that doesn't support syntax, then don't even bother holding // onto any tree source. It will never be used to get a tree, and can only hurt us // by possibly holding onto data that might cause a slow memory leak. _treeSource = this.SupportsSyntaxTree ? treeSource : ValueSource<TreeAndVersion>.Empty; }
private ProjectState( ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices, IEnumerable<DocumentId> documentIds, IEnumerable<DocumentId> additionalDocumentIds, ImmutableDictionary<DocumentId, DocumentState> documentStates, ImmutableDictionary<DocumentId, TextDocumentState> additionalDocumentStates, AsyncLazy<VersionStamp> lazyLatestDocumentVersion, AsyncLazy<VersionStamp> lazyLatestDocumentTopLevelChangeVersion) { _projectInfo = projectInfo; _solutionServices = solutionServices; _languageServices = languageServices; _documentIds = documentIds.ToImmutableReadOnlyListOrEmpty(); _additionalDocumentIds = additionalDocumentIds.ToImmutableReadOnlyListOrEmpty(); _documentStates = documentStates; _additionalDocumentStates = additionalDocumentStates; _lazyLatestDocumentVersion = lazyLatestDocumentVersion; _lazyLatestDocumentTopLevelChangeVersion = lazyLatestDocumentTopLevelChangeVersion; _lazyChecksums = new AsyncLazy<ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true); }
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; }
internal CodeModelProjectCache(AbstractProject project, IServiceProvider serviceProvider, HostLanguageServices languageServices, VisualStudioWorkspace workspace) { _project = project; _state = new CodeModelState(serviceProvider, languageServices, workspace); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) => new NoCompilationLanguageService();
public TestHostProject( TestWorkspace workspace, string name = null, string language = null, CompilationOptions compilationOptions = null, ParseOptions parseOptions = null, IEnumerable<TestHostDocument> documents = null, IEnumerable<TestHostDocument> additionalDocuments = null, IEnumerable<TestHostProject> projectReferences = null, IEnumerable<MetadataReference> metadataReferences = null, IEnumerable<AnalyzerReference> analyzerReferences = null, string assemblyName = null) { _name = name ?? "TestProject"; _id = ProjectId.CreateNewId(debugName: this.Name); language = language ?? LanguageNames.CSharp; _languageServices = workspace.Services.GetLanguageServices(language); _compilationOptions = compilationOptions ?? this.LanguageServiceProvider.GetService<ICompilationFactoryService>().GetDefaultCompilationOptions(); _parseOptions = parseOptions ?? this.LanguageServiceProvider.GetService<ISyntaxTreeFactoryService>().GetDefaultParseOptions(); this.Documents = documents ?? SpecializedCollections.EmptyEnumerable<TestHostDocument>(); this.AdditionalDocuments = additionalDocuments ?? SpecializedCollections.EmptyEnumerable<TestHostDocument>(); _projectReferences = projectReferences != null ? projectReferences.Select(p => new ProjectReference(p.Id)) : SpecializedCollections.EmptyEnumerable<ProjectReference>(); _metadataReferences = metadataReferences ?? new MetadataReference[] { TestReferences.NetFx.v4_0_30319.mscorlib }; _analyzerReferences = analyzerReferences ?? SpecializedCollections.EmptyEnumerable<AnalyzerReference>(); _assemblyName = assemblyName ?? "TestProject"; _version = VersionStamp.Create(); _outputFilePath = GetTestOutputFilePath(_filePath); if (documents != null) { foreach (var doc in documents) { doc.SetProject(this); } } if (additionalDocuments != null) { foreach (var doc in additionalDocuments) { doc.SetProject(this); } } }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(languageServices.GetOriginalLanguageService <ISyntaxFactsService>()); }
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); 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 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); // For linked files, use the same ITextBuffer for all linked documents if (!filePathToTextBufferMap.TryGetValue(filePath, out var textBuffer)) { textBuffer = EditorFactory.CreateBuffer(contentType.TypeName, exportProvider, code); filePathToTextBufferMap.Add(filePath, textBuffer); } return(new TestHostDocument( exportProvider, languageServiceProvider, textBuffer, filePath, cursorPosition, spans, codeKind, folders, isLinkFile, documentServiceProvider)); }
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>()); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(languageServices.GetOriginalLanguageService <BlockStructureService>()); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(new DefaultRazorSyntaxFactsService()); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) => CSharpVirtualCharLanguageService.Instance;
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(new DefaultProjectSnapshotWorker( languageServices.WorkspaceServices.GetRequiredService <ForegroundDispatcher>(), languageServices.GetRequiredService <ProjectExtensibilityConfigurationFactory>())); }
public void GenerateForCompilation( Compilation compilation, string projectPath, HostLanguageServices languageServices, OptionSet options ) { var projectVertex = new Graph.LsifProject( kind: GetLanguageKind(compilation.Language), new Uri(projectPath), _idFactory ); _lsifJsonWriter.Write(projectVertex); _lsifJsonWriter.Write( new Event(Event.EventKind.Begin, projectVertex.GetId(), _idFactory) ); var documentIds = new ConcurrentBag <Id <Graph.LsifDocument> >(); // We create a ResultSetTracker to track all top-level symbols in the project. We don't want all writes to immediately go to // the JSON file -- we support parallel processing, so we'll accumulate them and then apply at once to avoid a lot // of contention on shared locks. var topLevelSymbolsWriter = new BatchingLsifJsonWriter(_lsifJsonWriter); var topLevelSymbolsResultSetTracker = new SymbolHoldingResultSetTracker( topLevelSymbolsWriter, compilation, _idFactory ); Parallel.ForEach( compilation.SyntaxTrees, syntaxTree => { var semanticModel = compilation.GetSemanticModel(syntaxTree); // We generate the document contents into an in-memory copy, and then write that out at once at the end. This // allows us to collect everything and avoid a lot of fine-grained contention on the write to the single // LSIF file. Becasue of the rule that vertices must be written before they're used by an edge, we'll flush any top- // level symbol result sets made first, since the document contents will point to that. Parallel calls to CopyAndEmpty // are allowed and might flush other unrelated stuff at the same time, but there's no harm -- the "causality" ordering // is preserved. var documentWriter = new BatchingLsifJsonWriter(_lsifJsonWriter); var documentId = GenerateForDocument( semanticModel, languageServices, options, topLevelSymbolsResultSetTracker, documentWriter, _idFactory ); topLevelSymbolsWriter.FlushToUnderlyingAndEmpty(); documentWriter.FlushToUnderlyingAndEmpty(); documentIds.Add(documentId); } ); _lsifJsonWriter.Write( Edge.Create("contains", projectVertex.GetId(), documentIds.ToArray(), _idFactory) ); _lsifJsonWriter.Write( new Event(Event.EventKind.End, projectVertex.GetId(), _idFactory) ); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { var workspace = languageServices.WorkspaceServices.Workspace; return(new OOPTagHelperResolver(workspace)); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) => new CSharpQuickInfoService(languageServices.WorkspaceServices.Workspace);
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(languageServices.GetOriginalLanguageService <ICommentSelectionService>()); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) => new CSharpDesignerAttributeService(languageServices.WorkspaceServices.Workspace);
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(languageServices.GetOriginalLanguageService <ILineSeparatorService>()); }
private static TestHostDocument CreateDocument( TestWorkspace workspace, XElement workspaceElement, XElement documentElement, ExportProvider exportProvider, HostLanguageServices languageServiceProvider, 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); } TestFileMarkupParser.GetPositionAndSpans(markupCode, out var code, out int?cursorPosition, out ImmutableDictionary <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 CSharpSymbolDisplayService(HostLanguageServices provider) : base(provider.GetService<IAnonymousTypeDisplayService>()) { }
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)); }
/// <summary> /// Generates the LSIF content for a single document. /// </summary> /// <returns>The ID of the outputted Document vertex.</returns> /// <remarks> /// The high level algorithm here is we are going to walk across each token, produce a <see cref="Graph.Range"/> for that token's span, /// bind that token, and then link up the various features. So we'll link that range to the symbols it defines or references, /// will link it to results like Quick Info, and more. This method has a <paramref name="topLevelSymbolsResultSetTracker"/> that /// lets us link symbols across files, and will only talk about "top level" symbols that aren't things like locals that can't /// leak outside a file. /// </remarks> private static Id <Graph.LsifDocument> GenerateForDocument( SemanticModel semanticModel, HostLanguageServices languageServices, OptionSet options, IResultSetTracker topLevelSymbolsResultSetTracker, ILsifJsonWriter lsifJsonWriter, IdFactory idFactory ) { var syntaxTree = semanticModel.SyntaxTree; var sourceText = semanticModel.SyntaxTree.GetText(); var syntaxFactsService = languageServices.GetRequiredService <ISyntaxFactsService>(); var semanticFactsService = languageServices.GetRequiredService <ISemanticFactsService>(); string?contentBase64Encoded = null; // TODO: move to checking the enum member mentioned in https://github.com/dotnet/roslyn/issues/49326 when that // is implemented. In the mean time, we'll use a heuristic of the path being a relative path as a way to indicate // this is a source generated file. if (!PathUtilities.IsAbsolute(syntaxTree.FilePath)) { var text = semanticModel.SyntaxTree.GetText(); // We always use UTF-8 encoding when writing out file contents, as that's expected by LSIF implementations. // TODO: when we move to .NET Core, is there a way to reduce allocatios here? contentBase64Encoded = Convert.ToBase64String( Encoding.UTF8.GetBytes(text.ToString()) ); } var documentVertex = new Graph.LsifDocument( new Uri(syntaxTree.FilePath, UriKind.RelativeOrAbsolute), GetLanguageKind(semanticModel.Language), contentBase64Encoded, idFactory ); lsifJsonWriter.Write(documentVertex); lsifJsonWriter.Write( new Event(Event.EventKind.Begin, documentVertex.GetId(), idFactory) ); // As we are processing this file, we are going to encounter symbols that have a shared resultSet with other documents like types // or methods. We're also going to encounter locals that never leave this document. We don't want those locals being held by // the topLevelSymbolsResultSetTracker, so we'll make another tracker for document local symbols, and then have a delegating // one that picks the correct one of the two. var documentLocalSymbolsResultSetTracker = new SymbolHoldingResultSetTracker( lsifJsonWriter, semanticModel.Compilation, idFactory ); var symbolResultsTracker = new DelegatingResultSetTracker( symbol => { if ( symbol.Kind == SymbolKind.Local || symbol.Kind == SymbolKind.RangeVariable || symbol.Kind == SymbolKind.Label ) { // These symbols can go in the document local one because they can't escape methods return(documentLocalSymbolsResultSetTracker); } else if ( symbol.ContainingType != null && symbol.DeclaredAccessibility == Accessibility.Private && symbol.ContainingType.Locations.Length == 1 ) { // This is a private member in a class that isn't partial, so it can't escape the file return(documentLocalSymbolsResultSetTracker); } else { return(topLevelSymbolsResultSetTracker); } } ); // We will walk the file token-by-token, making a range for each one and then attaching information for it var rangeVertices = new List <Id <Graph.Range> >(); foreach ( var syntaxToken in syntaxTree.GetRoot().DescendantTokens(descendIntoTrivia: true) ) { // We'll only create the Range vertex once it's needed, but any number of bits of code might create it first, // so we'll just make it Lazy. var lazyRangeVertex = new Lazy <Graph.Range>( () => { var rangeVertex = Graph.Range.FromTextSpan( syntaxToken.Span, sourceText, idFactory ); lsifJsonWriter.Write(rangeVertex); rangeVertices.Add(rangeVertex.GetId()); return(rangeVertex); }, LazyThreadSafetyMode.None ); var declaredSymbol = semanticFactsService.GetDeclaredSymbol( semanticModel, syntaxToken, CancellationToken.None ); ISymbol?referencedSymbol = null; if (syntaxFactsService.IsBindableToken(syntaxToken)) { var bindableParent = syntaxFactsService.TryGetBindableParent(syntaxToken); if (bindableParent != null) { var symbolInfo = semanticModel.GetSymbolInfo(bindableParent); if ( symbolInfo.Symbol != null && IncludeSymbolInReferences(symbolInfo.Symbol) ) { referencedSymbol = symbolInfo.Symbol; } } } if (declaredSymbol != null || referencedSymbol != null) { // For now, we will link the range to the original definition, preferring the definition, as this is the symbol // that would be used if we invoke a feature on this range. This is analogous to the logic in // SymbolFinder.FindSymbolAtPositionAsync where if a token is both a reference and definition we'll prefer the // definition. Once we start supporting hover we'll have to remove the "original definition" part of this, since // since we show different contents for different constructed types there. var symbolForLinkedResultSet = (declaredSymbol ?? referencedSymbol) !.OriginalDefinition; var symbolForLinkedResultSetId = symbolResultsTracker.GetResultSetIdForSymbol( symbolForLinkedResultSet ); lsifJsonWriter.Write( Edge.Create( "next", lazyRangeVertex.Value.GetId(), symbolForLinkedResultSetId, idFactory ) ); if (declaredSymbol != null) { var definitionResultsId = symbolResultsTracker.GetResultIdForSymbol( declaredSymbol, Methods.TextDocumentDefinitionName, () => new DefinitionResult(idFactory) ); lsifJsonWriter.Write( new Item( definitionResultsId.As <DefinitionResult, Vertex>(), lazyRangeVertex.Value.GetId(), documentVertex.GetId(), idFactory ) ); } if (referencedSymbol != null) { // Create the link from the references back to this range. Note: this range can be reference to a // symbol but the range can point a different symbol's resultSet. This can happen if the token is // both a definition of a symbol (where we will point to the definition) but also a reference to some // other symbol. var referenceResultsId = symbolResultsTracker.GetResultIdForSymbol( referencedSymbol.OriginalDefinition, Methods.TextDocumentReferencesName, () => new ReferenceResult(idFactory) ); lsifJsonWriter.Write( new Item( referenceResultsId.As <ReferenceResult, Vertex>(), lazyRangeVertex.Value.GetId(), documentVertex.GetId(), idFactory, property: "references" ) ); } } } lsifJsonWriter.Write( Edge.Create("contains", documentVertex.GetId(), rangeVertices, idFactory) ); // Write the folding ranges for the document. var foldingRanges = FoldingRangesHandler.GetFoldingRanges( syntaxTree, languageServices, options, isMetadataAsSource: false, CancellationToken.None ); var foldingRangeResult = new FoldingRangeResult(foldingRanges, idFactory); lsifJsonWriter.Write(foldingRangeResult); lsifJsonWriter.Write( Edge.Create( Methods.TextDocumentFoldingRangeName, documentVertex.GetId(), foldingRangeResult.GetId(), idFactory ) ); lsifJsonWriter.Write(new Event(Event.EventKind.End, documentVertex.GetId(), idFactory)); return(documentVertex.GetId()); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(new NoCompilationLanguageService()); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return new VisualBasicProjectFileLoader(languageServices.WorkspaceServices); }
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; } }
internal TestHostProject( HostLanguageServices languageServices, CompilationOptions compilationOptions, ParseOptions parseOptions, string assemblyName, params MetadataReference[] references) : this(languageServices, compilationOptions, parseOptions, assemblyName, references, SpecializedCollections.EmptyArray<TestHostDocument>()) { }
public ILanguageService CreateLanguageService(HostLanguageServices provider) { return(new CSharpSyntaxTreeFactoryService(provider)); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) => new InteractiveCommandCompletionService(languageServices.WorkspaceServices);
private static DocumentState CreateDocument(ProjectInfo projectInfo, DocumentInfo documentInfo, HostLanguageServices 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(HostLanguageServices languageServices) : base(languageServices) { }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return new InteractiveCommandCompletionService(languageServices.WorkspaceServices.Workspace); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(languageServices.GetOriginalLanguageService <IDocumentDifferenceService>()); }
internal TestHostDocument( ExportProvider exportProvider, HostLanguageServices languageServiceProvider, ITextBuffer textBuffer, string filePath, int? cursorPosition, IDictionary<string, IList<TextSpan>> spans, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular, IReadOnlyList<string> folders = null, bool isLinkFile = false) { Contract.ThrowIfNull(textBuffer); Contract.ThrowIfNull(filePath); _exportProvider = exportProvider; _languageServiceProvider = languageServiceProvider; this.TextBuffer = textBuffer; this.InitialTextSnapshot = textBuffer.CurrentSnapshot; _filePath = filePath; _folders = folders; _name = filePath; this.CursorPosition = cursorPosition; _sourceCodeKind = sourceCodeKind; this.IsLinkFile = isLinkFile; this.SelectedSpans = new List<TextSpan>(); if (spans.ContainsKey(string.Empty)) { this.SelectedSpans = spans[string.Empty]; } this.AnnotatedSpans = new Dictionary<string, IList<TextSpan>>(); foreach (var namedSpanList in spans.Where(s => s.Key != string.Empty)) { this.AnnotatedSpans.Add(namedSpanList); } _loader = new TestDocumentLoader(this); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return(new CSharpCompletionService(languageServices.WorkspaceServices.Workspace)); }
internal TestHostProject( HostLanguageServices languageServices, CompilationOptions compilationOptions, ParseOptions parseOptions, params MetadataReference[] references) : this(languageServices, compilationOptions, parseOptions, "Test", references) { }
public TestHostProject( TestWorkspace workspace, string name = null, string language = null, CompilationOptions compilationOptions = null, ParseOptions parseOptions = null, IEnumerable <TestHostDocument> documents = null, IEnumerable <TestHostDocument> additionalDocuments = null, IEnumerable <TestHostDocument> analyzerConfigDocuments = null, IEnumerable <TestHostProject> projectReferences = null, IEnumerable <MetadataReference> metadataReferences = null, IEnumerable <AnalyzerReference> analyzerReferences = null, string assemblyName = null, string defaultNamespace = null ) { _name = name ?? "TestProject"; _id = ProjectId.CreateNewId(debugName: this.Name); language = language ?? LanguageNames.CSharp; _languageServices = workspace.Services.GetLanguageServices(language); _compilationOptions = compilationOptions ?? this.LanguageServiceProvider .GetService <ICompilationFactoryService>() .GetDefaultCompilationOptions(); _parseOptions = parseOptions ?? this.LanguageServiceProvider .GetService <ISyntaxTreeFactoryService>() .GetDefaultParseOptions(); this.Documents = documents ?? SpecializedCollections.EmptyEnumerable <TestHostDocument>(); this.AdditionalDocuments = additionalDocuments ?? SpecializedCollections.EmptyEnumerable <TestHostDocument>(); this.AnalyzerConfigDocuments = analyzerConfigDocuments ?? SpecializedCollections.EmptyEnumerable <TestHostDocument>(); ProjectReferences = projectReferences != null ? projectReferences.Select(p => new ProjectReference(p.Id)) : SpecializedCollections.EmptyEnumerable <ProjectReference>(); _metadataReferences = metadataReferences ?? new MetadataReference[] { TestMetadata.Net451.mscorlib }; _analyzerReferences = analyzerReferences ?? SpecializedCollections.EmptyEnumerable <AnalyzerReference>(); _assemblyName = assemblyName ?? "TestProject"; _version = VersionStamp.Create(); _outputFilePath = GetTestOutputFilePath(_filePath); _defaultNamespace = defaultNamespace; if (documents != null) { foreach (var doc in documents) { doc.SetProject(this); } } if (additionalDocuments != null) { foreach (var doc in additionalDocuments) { doc.SetProject(this); } } if (analyzerConfigDocuments != null) { foreach (var doc in analyzerConfigDocuments) { doc.SetProject(this); } } }
internal TestHostProject( HostLanguageServices languageServices, CompilationOptions compilationOptions, ParseOptions parseOptions, string assemblyName, IList<MetadataReference> references, IList<TestHostDocument> documents, IList<TestHostDocument> additionalDocuments = null, Type hostObjectType = null, bool isSubmission = false, string filePath = null, IList<AnalyzerReference> analyzerReferences = null) { _assemblyName = assemblyName; _name = assemblyName; _id = ProjectId.CreateNewId(debugName: this.AssemblyName); _languageServices = languageServices; _compilationOptions = compilationOptions; _parseOptions = parseOptions; _metadataReferences = references; _analyzerReferences = analyzerReferences ?? SpecializedCollections.EmptyEnumerable<AnalyzerReference>(); this.Documents = documents; this.AdditionalDocuments = additionalDocuments ?? SpecializedCollections.EmptyEnumerable<TestHostDocument>(); _projectReferences = SpecializedCollections.EmptyEnumerable<ProjectReference>(); _isSubmission = isSubmission; _hostObjectType = hostObjectType; _version = VersionStamp.Create(); _filePath = filePath; _outputFilePath = GetTestOutputFilePath(filePath); }
public CSharpDecompiledSourceService(HostLanguageServices provider) => this.provider = provider;
private static ParseOptions GetParseOptions(XElement projectElement, string language, HostLanguageServices languageServices) { return language == LanguageNames.CSharp || language == LanguageNames.VisualBasic ? GetParseOptionsWorker(projectElement, language, languageServices) : null; }
internal CodeModelProjectCache(IThreadingContext threadingContext, ProjectId projectId, ICodeModelInstanceFactory codeModelInstanceFactory, ProjectCodeModelFactory projectFactory, IServiceProvider serviceProvider, HostLanguageServices languageServices, VisualStudioWorkspace workspace) { _state = new CodeModelState(threadingContext, serviceProvider, languageServices, workspace, projectFactory); _projectId = projectId; _codeModelInstanceFactory = codeModelInstanceFactory; }
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 DocumentState CreateDocument(DocumentInfo documentInfo, ParseOptions parseOptions, HostLanguageServices languageServices, SolutionServices solutionServices) { var doc = DocumentState.Create(documentInfo, parseOptions, languageServices, solutionServices); if (doc.SourceCodeKind != documentInfo.SourceCodeKind) { doc = doc.UpdateSourceCodeKind(documentInfo.SourceCodeKind); } return(doc); }
public AbstractSyntaxTreeFactoryService(HostLanguageServices languageServices) { this.languageServices = languageServices; }
public CSharpCodeGenerationService(HostLanguageServices languageServices) : base(languageServices.GetService <ISymbolDeclarationService>(), languageServices.WorkspaceServices.Workspace) { }
public CSharpSyntaxTriviaService(HostLanguageServices provider) : base(provider.GetService<ISyntaxFactsService>(), (int)SyntaxKind.EndOfLineTrivia) { }
private static ParseOptions GetParseOptions(XElement projectElement, string language, HostLanguageServices languageServices) { return(language == LanguageNames.CSharp || language == LanguageNames.VisualBasic ? GetParseOptionsWorker(projectElement, language, languageServices) : null); }
public ILanguageService CreateLanguageService(HostLanguageServices languageServices) { return new CSharpCompletionService(languageServices.WorkspaceServices.Workspace); }
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 featuresAttribute = projectElement.Attribute(FeaturesAttributeName); if (featuresAttribute != null) { parseOptions = GetParseOptionsWithFeatures(parseOptions, featuresAttribute); } var documentationMode = GetDocumentationMode(projectElement); if (documentationMode != null) { parseOptions = parseOptions.WithDocumentationMode(documentationMode.Value); } return(parseOptions); }