OmniSharp / OmniSharp/csharp-language-server-protocol

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

Open
#660 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
638
Forks
109
Avg merge
1m
Merged PRs (30d)
2

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Program.cs and compare its LanguageServer.From and WithHandler setup with the referenced SampleServer file. Reproduce the DryIoc resolution error and trace TextDocumentSyncHandler registration and scope handling; done means the missing setup is identified and the sample or guidance clearly resolves the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.