internal RoslynWorkspace(HostServices host, INuGetProvider nuGetProvider, RoslynHost roslynHost)
            : base(host, WorkspaceKind.Host)
        {
            _nuGetProvider = nuGetProvider;
            _referencesDirectives = new ConcurrentDictionary<string, DirectiveInfo>();

            RoslynHost = roslynHost;
        }
Beispiel #2
0
 public static string ResolveReference(this INuGetProvider nuGetProvider, string reference)
 {
     if (nuGetProvider?.PathVariableName != null &&
         nuGetProvider.PathToRepository != null &&
         reference.StartsWith(nuGetProvider.PathVariableName, StringComparison.OrdinalIgnoreCase))
     {
         reference = Path.Combine(nuGetProvider.PathToRepository,
                                  reference.Substring(nuGetProvider.PathVariableName.Length).TrimStart('/', '\\'));
     }
     return(reference);
 }
 public void Initialize(IList<string> references, IList<string> imports, INuGetProvider nuGetProvider, string workingDirectory, Action<ResultObject> dumped, Action<int> completed)
 {
     var scriptOptions = _scriptOptions
         .WithReferences(references)
         .WithImports(imports);
     if (nuGetProvider != null)
     {
         var resolver = new NuGetScriptMetadataResolver(nuGetProvider, workingDirectory);
         scriptOptions = scriptOptions.WithMetadataResolver(resolver);
     }
     _scriptOptions = scriptOptions;
     _dumped = dumped;
     _completed = completed;
 }
 public ExecutionHost(string hostPath, string initialWorkingDirectory,
     IEnumerable<string> references, IEnumerable<string> imports,
     INuGetProvider nuGetProvider, ChildProcessManager childProcessManager)
 {
     HostPath = hostPath;
     _initialWorkingDirectory = initialWorkingDirectory;
     _references = references;
     _imports = imports;
     _nuGetProvider = nuGetProvider;
     _childProcessManager = childProcessManager;
     var serverProvider = new BinaryServerFormatterSinkProvider { TypeFilterLevel = TypeFilterLevel.Full };
     _serverChannel = new IpcServerChannel(GenerateUniqueChannelLocalName(), "Channel-" + Guid.NewGuid(), serverProvider);
     ChannelServices.RegisterChannel(_serverChannel, ensureSecurity: false);
 }
Beispiel #5
0
        public RoslynHost(INuGetProvider nuGetProvider = null)
        {
            _nuGetProvider           = nuGetProvider;
            _referencesDirectives    = new ConcurrentDictionary <string, DirectiveInfo>();
            _referenceDirectivesLock = new SemaphoreSlim(1, 1);

            var assemblies = new[]
            {
                Assembly.Load("Microsoft.CodeAnalysis"),
                Assembly.Load("Microsoft.CodeAnalysis.CSharp"),
                Assembly.Load("Microsoft.CodeAnalysis.Features"),
                Assembly.Load("Microsoft.CodeAnalysis.CSharp.Features"),
                typeof(RoslynHost).Assembly,
            };

            // we can't import this entire assembly due to composition errors
            // and we don't need all the VS services
            var editorFeaturesAssembly = Assembly.Load("Microsoft.CodeAnalysis.EditorFeatures");
            var types = editorFeaturesAssembly.GetTypes().Where(x => x.Namespace == "Microsoft.CodeAnalysis.CodeFixes");

            _compositionContext = new ContainerConfiguration()
                                  .WithAssemblies(MefHostServices.DefaultAssemblies.Concat(assemblies))
                                  .WithParts(types)
                                  .WithDefaultConventions(new AttributeFilterProvider())
                                  .CreateContainer();

            var host = MefHostServices.Create(_compositionContext);

            _workspace = new RoslynWorkspace(host, this);
            _workspace.ApplyingTextChange += (d, s) => ApplyingTextChange?.Invoke(d, s);

            _parseOptions = new CSharpParseOptions(kind: SourceCodeKind.Script);

            _referenceAssembliesPath      = GetReferenceAssembliesPath();
            _documentationProviderService = new DocumentationProviderServiceFactory.DocumentationProviderService();

            _references = _defaultReferenceAssemblies.Select(t =>
                                                             (MetadataReference)MetadataReference.CreateFromFile(t.Location,
                                                                                                                 documentation: GetDocumentationProvider(t.Location))).ToImmutableArray();
            var metadataReferenceResolver = CreateMetadataReferenceResolver();

            _compilationOptions = new CSharpCompilationOptions(OutputKind.NetModule,
                                                               usings: _defaultReferenceAssemblyTypes.Select(x => x.Namespace).ToImmutableArray(),
                                                               metadataReferenceResolver: metadataReferenceResolver);

            _workspace.Services.GetService <Microsoft.CodeAnalysis.SolutionCrawler.ISolutionCrawlerRegistrationService>()
            .Register(_workspace);

            _compositionContext.GetExport <ISemanticChangeNotificationService>().OpenedDocumentSemanticChanged +=
                OnOpenedDocumentSemanticChanged;

            // MEF v1
            var container = new CompositionContainer(new AggregateCatalog(
                                                         new AssemblyCatalog(Assembly.Load("Microsoft.CodeAnalysis.EditorFeatures")),
                                                         new AssemblyCatalog(Assembly.Load("Microsoft.CodeAnalysis.CSharp.EditorFeatures")),
                                                         new AssemblyCatalog(typeof(RoslynHost).Assembly)),
                                                     CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);

            ((AggregateSignatureHelpProvider)GetService <ISignatureHelpProvider>()).Initialize(container);

            CompletionService.Initialize(container);
        }
Beispiel #6
0
 public NuGetScriptMetadataResolver(INuGetProvider nuGetProvider)
 {
     _nuGetProvider = nuGetProvider;
     _inner         = ScriptMetadataResolver.Default;
 }
 public NuGetScriptMetadataResolver(INuGetProvider nuGetProvider, string workingDirectory)
 {
     _nuGetProvider = nuGetProvider;
     _inner = ScriptMetadataResolver.Default.WithBaseDirectory(workingDirectory);
 }