Skip to content

Unable to resolve resolution root for TextDocumentSyncHandler from container without any scope. #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
bobbytreed opened this issue Oct 11, 2021 · 2 comments

Comments

@bobbytreed
Copy link

Good Morning,
I'm upgrading from .095 to the latest version of OmniSharp.

Everything was working fine in .095, but after upgrading, and changing my Program.cs file to look like your SampleServer File (for testing), I get the following error.

DryIoc.ContainerException: 'code: Error.UnableToResolveFromRegisteredServices;
message: Unable to resolve Resolution root DocIndex.VsCode.Server.TextDocumentSyncHandler
  from container without scope
 with Rules with {TrackingDisposableTransients, ResolveIEnumerableAsLazyEnumerable, UseDynamicRegistrationsAsFallbackOnly, SelectLastRegisteredFactory} and without {ThrowOnRegisteringDisposableTransient, VariantGenericTypesInResolvedCollection}
 with DefaultReuse=Scoped {Lifespan=100}
 with FactorySelector=SelectLastRegisteredFactory
 with Made={FactoryMethod=ConstructorWithResolvableArgumentsIncludingNonPublic}
  with normal and dynamic registrations:
  (DefaultDynamicKey(0), {FactoryID=134, ImplType=DocIndex.VsCode.Server.TextDocumentSyncHandler, Reuse=TransientReuse, HasCondition})'

Source Code

var server = await LanguageServer.From(
                options =>
                    options
                       .WithInput(Console.OpenStandardInput())
                       .WithOutput(Console.OpenStandardOutput())
                       .ConfigureLogging(
                            x => x
                                .AddSerilog(Log.Logger)
                                .AddLanguageProtocolLogging()
                                .SetMinimumLevel(LogLevel.Debug)
                        )
                       .WithHandler<TextDocumentHandler>()
                       .WithHandler<DidChangeWatchedFilesHandler>()
                       .WithHandler<FoldingRangeHandler>()
                       .WithHandler<MyWorkspaceSymbolsHandler>()
                       .WithHandler<MyDocumentSymbolHandler>()
                       .WithHandler<SemanticTokensHandler>()
                       .WithServices(x => x.AddLogging(b => b.SetMinimumLevel(LogLevel.Trace)))
                       .WithServices(
                            services => {
                                services.AddSingleton(
                                    provider => {
                                        var loggerFactory = provider.GetService<ILoggerFactory>();
                                        var logger = loggerFactory.CreateLogger<Foo>();

                                        logger.LogInformation("Configuring");

                                        return new Foo(logger);
                                    }
                                );
                                services.AddSingleton(
                                    new ConfigurationItem {
                                        Section = "typescript",
                                    }
                                ).AddSingleton(
                                    new ConfigurationItem {
                                        Section = "terminal",
                                    }
                                );
                            }
                        )
                       .OnInitialize(
                            async (server, request, token) => {
                                var manager = server.WorkDoneManager.For(
                                    request, new WorkDoneProgressBegin {
                                        Title = "Server is starting...",
                                        Percentage = 10,
                                    }
                                );
                                workDone = manager;

                                await Task.Delay(2000).ConfigureAwait(false);

                                manager.OnNext(
                                    new WorkDoneProgressReport {
                                        Percentage = 20,
                                        Message = "loading in progress"
                                    }
                                );
                            }
                        )
                       .OnInitialized(
                            async (server, request, response, token) => {
                                workDone.OnNext(
                                    new WorkDoneProgressReport {
                                        Percentage = 40,
                                        Message = "loading almost done",
                                    }
                                );

                                await Task.Delay(2000).ConfigureAwait(false);

                                workDone.OnNext(
                                    new WorkDoneProgressReport {
                                        Message = "loading done",
                                        Percentage = 100,
                                    }
                                );
                                workDone.OnCompleted();
                            }
                        )
                       .OnStarted(
                            async (languageServer, token) => {
                                using var manager = await languageServer.WorkDoneManager.Create(new WorkDoneProgressBegin { Title = "Doing some work..." }).ConfigureAwait(false);

                                manager.OnNext(new WorkDoneProgressReport { Message = "doing things..." });
                                await Task.Delay(10000).ConfigureAwait(false);
                                manager.OnNext(new WorkDoneProgressReport { Message = "doing things... 1234" });
                                await Task.Delay(10000).ConfigureAwait(false);
                                manager.OnNext(new WorkDoneProgressReport { Message = "doing things... 56789" });

                                var logger = languageServer.Services.GetService<ILogger<Foo>>();
                                var configuration = await languageServer.Configuration.GetConfiguration(
                                    new ConfigurationItem {
                                        Section = "typescript",
                                    }, new ConfigurationItem {
                                        Section = "terminal",
                                    }
                                ).ConfigureAwait(false);

                                var baseConfig = new JObject();
                                foreach (var config in languageServer.Configuration.AsEnumerable())
                                {
                                    baseConfig.Add(config.Key, config.Value);
                                }

                                logger.LogInformation("Base Config: {Config}", baseConfig);

                                var scopedConfig = new JObject();
                                foreach (var config in configuration.AsEnumerable())
                                {
                                    scopedConfig.Add(config.Key, config.Value);
                                }

                                logger.LogInformation("Scoped Config: {Config}", scopedConfig);
                            }
                        )

In your example, I don't see anywhere that you are registering the TextDocumentHandler outside of the .With Statement.

Do you hany any ideas what could be missing here?

@Skleni
Copy link

Skleni commented Dec 6, 2021

I just had the same problem after updating to 0.19.5...did you find out what was the problem?

@Skleni
Copy link

Skleni commented Dec 6, 2021

For me, it was caused by #338. I had some handlers with ILanguageServer constructor parameters. Changing these to ILanguageServerFacade fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants