コード例 #1
0
ファイル: PythonToolsService.cs プロジェクト: yepeiwen/PTVS
        private LanguageServerOptions CreateLanguageServerOptions()
        {
            var opts = new LanguageServerOptions(this);

            opts.Load();
            return(opts);
        }
コード例 #2
0
 public void Configure(LanguageServerOptions options) =>
 options.ObserveCodeLens(
     (@params, observer, capability, cancellationToken) => {
     observer.OnNext(
         new[] {
         new CodeLens {
             Command = new Command {
                 Name = "CodeLens 1"
             }
         },
     }
         );
     observer.OnNext(
         new[] {
         new CodeLens {
             Command = new Command {
                 Name = "CodeLens 2"
             }
         },
     }
         );
     observer.OnNext(
         new[] {
         new CodeLens {
             Command = new Command {
                 Name = "CodeLens 3"
             }
         },
     }
         );
     observer.OnCompleted();
 }, (_, _) => new CodeLensRegistrationOptions()
     );
コード例 #3
0
        static async Task Main(string[] args)
        {
            var options = new LanguageServerOptions()
                          .WithInput(Console.OpenStandardInput())
                          .WithOutput(Console.OpenStandardOutput())
                          .WithLoggerFactory(new LoggerFactory())
                          .AddDefaultLoggingProvider()
                          .WithMinimumLogLevel(LogLevel.Trace)
                          .WithServices(ConfigureServices)
                          .WithHandler <TextDocumentSyncHandler>()
                          .OnInitialize((s, _) => {
                var serviceProvider    = (s as LanguageServer).Services;
                var bufferManager      = serviceProvider.GetService <BufferManager>();
                var diagnosticsHandler = serviceProvider.GetService <DiagnosticsHandler>();

                // Hook up diagnostics
                bufferManager.BufferUpdated += (__, x) => diagnosticsHandler.PublishDiagnostics(x.Uri, bufferManager.GetBuffer(x.Uri));

                return(Task.CompletedTask);
            });

            var server = await LanguageServer.From(options);

            await server.WaitForExit;
        }
コード例 #4
0
 public LanguageServerOptionsControl(IServiceProvider serviceProvider)
 {
     _serviceProvider = serviceProvider;
     _options         = _serviceProvider?.GetPythonToolsService().LanguageServerOptions;
     InitializeComponent();
     UpdateSettings();
 }
 private void ConfigureServer(LanguageServerOptions options)
 {
     options.WithContentModifiedSupport(true);
     options.OnCompletion(async(x, ct) => {
         await Task.Delay(50000, ct);
         return(new CompletionList());
     }, new CompletionRegistrationOptions());
     options.OnDidChangeTextDocument(async x => { await Task.Delay(20); }, new TextDocumentChangeRegistrationOptions());
 }
コード例 #6
0
 public static LanguageServerOptions WithDafnyLanguageServer(this LanguageServerOptions options, IConfiguration configuration)
 {
     return(options
            .WithDafnyLanguage()
            .WithDafnyWorkspace(configuration)
            .WithDafnyHandlers()
            .OnInitialize(InitializeAsync)
            .OnStarted(StartedAsync));
 }
コード例 #7
0
 private void ServerOptionsAction(LanguageServerOptions obj)
 {
     obj.OnMoniker(
         _request, (_, _) => new MonikerRegistrationOptions()
     {
         DocumentSelector = DocumentSelector.ForLanguage("csharp"),
     }
         );
 }
コード例 #8
0
 public static LanguageServerOptions WithDafnyLanguageServer(this LanguageServerOptions options, IConfiguration configuration)
 {
     return(options
            .WithDafnyLanguage()
            .WithDafnyWorkspace(configuration)
            .WithDafnyHandlers()
            .OnInitialize(Initialize)
            .OnStarted(Started)
            .WithMaximumRequestTimeout(System.TimeSpan.FromMilliseconds(600000)));
 }
コード例 #9
0
 private void ConfigureServer(LanguageServerOptions options)
 {
     options.OnRequest("keepalive", (ct) => Task.FromResult(true));
     options.WithLink("keepalive", "ka");
     options.WithLink("throw", "t");
     options.OnRequest("throw", async ct => {
         throw new NotSupportedException();
         return(Task.CompletedTask);
     });
 }
コード例 #10
0
 /// <summary>
 /// Registers all handlers necessary to provide the language server integration of dafny.
 /// </summary>
 /// <param name="options">The language server where the handlers should be registered to.</param>
 /// <returns>The language server enriched with the dafny handlers.</returns>
 public static LanguageServerOptions WithDafnyHandlers(this LanguageServerOptions options)
 {
     return(options
            .WithHandler <DafnyTextDocumentHandler>()
            .WithHandler <DafnyDocumentSymbolHandler>()
            .WithHandler <DafnyHoverHandler>()
            .WithHandler <DafnyDefinitionHandler>()
            .WithHandler <DafnyCompletionHandler>()
            .WithHandler <DafnySignatureHelpHandler>()
            .WithHandler <DafnyCounterExampleHandler>());
 }
 private void ConfigureServer(LanguageServerOptions options)
 {
     options.OnInitialize((server, request, token) => {
         server.Window.LogInfo("OnInitialize");
         return(Task.CompletedTask);
     });
     options.OnInitialized((server, request, response, token) => {
         server.Window.LogInfo("OnInitialized");
         return(Task.CompletedTask);
     });
 }
コード例 #12
0
 /// <summary>
 /// Registers all handlers necessary to provide the language server integration of dafny.
 /// </summary>
 /// <param name="options">The language server where the handlers should be registered to.</param>
 /// <returns>The language server enriched with the dafny handlers.</returns>
 public static LanguageServerOptions WithDafnyHandlers(this LanguageServerOptions options)
 {
     return(options
            .WithHandler <DafnyTextDocumentHandler>()
            // TODO Disabled since its functionallity cannot be observed in VS Code (yet).
            //.WithHandler<DafnyDocumentSymbolHandler>()
            .WithHandler <DafnyHoverHandler>()
            .WithHandler <DafnyDefinitionHandler>()
            .WithHandler <DafnyCompletionHandler>()
            .WithHandler <DafnySignatureHelpHandler>()
            .WithHandler <DafnyCounterExampleHandler>());
 }
コード例 #13
0
        /// <summary>
        /// Used for inject the test host for unit testing
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="configureServer"></param>
        /// <param name="cancellationTokenSource"></param>
        internal LanguageServerHost(
            Stream input,
            Stream output,
            Action <LanguageServerOptions> configureServer,
            CancellationTokenSource cancellationTokenSource)
        {
            _options = new LanguageServerOptions()
                       .WithInput(input)
                       .WithOutput(output)
                       .WithServices(ConfigureServices);

            configureServer(_options);

            _cancellationTokenSource = cancellationTokenSource;
        }
コード例 #14
0
 public void Configure(LanguageServerOptions options) => options.ObserveSemanticTokensFull(
     (@params, observer, arg3) => {
     observer.OnNext(new SemanticTokensPartialResult()
     {
         Data = new[] { 0 }.ToImmutableArray()
     });
     observer.OnNext(new SemanticTokensPartialResult()
     {
         Data = new[] { 0, 1 }.ToImmutableArray()
     });
     observer.OnNext(new SemanticTokensPartialResult()
     {
         Data = new[] { 0, 1, 2 }.ToImmutableArray()
     });
     observer.OnCompleted();
 }, (_, _) => new SemanticTokensRegistrationOptions()
     );
        private void ConfigureServer(LanguageServerOptions options)
        {
            options.OnCompletion(
                (@params, token) => Task.FromResult(new CompletionList()),
                registrationOptions: new CompletionRegistrationOptions()
            {
                DocumentSelector    = DocumentSelector.ForLanguage("csharp"),
                ResolveProvider     = false,
                TriggerCharacters   = new Container <string>("a", "b"),
                AllCommitCharacters = new Container <string>("1", "2"),
            });

            options.OnSemanticTokens(
                (builder, @params, ct) => { return(Task.CompletedTask); },
                (@params, token) => { return(Task.FromResult(new SemanticTokensDocument(new SemanticTokensLegend()))); },
                new SemanticTokensRegistrationOptions());
        }
コード例 #16
0
 public LanguageServerHost(
     Stream input,
     Stream output,
     CommandLineApplication application,
     CancellationTokenSource cancellationTokenSource)
 {
     _loggerFactory = new LoggerFactory();
     _logger        = _loggerFactory.CreateLogger <LanguageServerHost>();
     _options       = new LanguageServerOptions()
                      .WithInput(input)
                      .WithOutput(output)
                      .WithLoggerFactory(_loggerFactory)
                      .AddDefaultLoggingProvider()
                      .OnInitialize(Initialize)
                      .WithMinimumLogLevel(application.LogLevel)
                      .WithServices(services => _services = services);
     _application             = application;
     _cancellationTokenSource = cancellationTokenSource;
 }
コード例 #17
0
        public LanguageServerHost(
            Stream input,
            Stream output,
            CommandLineApplication application,
            CancellationTokenSource cancellationTokenSource)
        {
            _options = new LanguageServerOptions()
                       .WithInput(input)
                       .WithOutput(output)
                       .ConfigureLogging(x => x
                                         .AddLanguageProtocolLogging()
                                         // .SetMinimumLevel(application.LogLevel)
                                         )
                       .OnInitialize(Initialize)
                       .WithServices(ConfigureServices);

            _application             = application;
            _cancellationTokenSource = cancellationTokenSource;
        }
コード例 #18
0
        public static void ConfigureLanguageServer(LanguageServerOptions options, Action <ILoggingBuilder> configureLoggingAction = null)
        {
            // Hack to circumvent OmniSharp bug: https://github.com/OmniSharp/csharp-language-server-protocol/issues/609
            options.Services.AddSingleton <IReceiver, RhetosJsonRpcReceiver>();

            options
            .WithHandler <TextDocumentHandler>()
            .WithHandler <RhetosHoverHandler>()
            .WithHandler <RhetosSignatureHelpHandler>()
            .WithHandler <RhetosCompletionHandler>()
            .WithUnhandledExceptionHandler(UnhandledExceptionHandler)
            .WithServices(ConfigureServices)
            .OnInitialize(OnInitializeAsync)
            .OnInitialized(OnInitializedAsync);

            if (configureLoggingAction != null)
            {
                options.ConfigureLogging(configureLoggingAction);
            }
        }
コード例 #19
0
        public LanguageServerHost(
            Stream input,
            Stream output,
            CommandLineApplication application,
            CancellationTokenSource cancellationTokenSource,
            Action <ILoggingBuilder> configureLogging = null)
        {
            _options = new LanguageServerOptions()
                       .WithInput(input)
                       .WithOutput(output)
                       // initializeParams from the client won't be arriving yet, configure with app loglevel
                       .ConfigureLogging(GetLogBuilderAction(configureLogging, application.LogLevel))
                       .OnInitialize(Initialize)
                       .OnInitialized(Initialized)
                       .WithServices(ConfigureServices);

            _application             = application;
            _cancellationTokenSource = cancellationTokenSource;
            _configureLogging        = configureLogging;
        }
コード例 #20
0
        static async Task Main(string[] args)
        {
            //System.Diagnostics.Debugger.Launch();
            //while (!System.Diagnostics.Debugger.IsAttached)
            //{
            //    await Task.Delay(100);
            //}

            var options = new LanguageServerOptions()
                          .WithInput(Console.OpenStandardInput())
                          .WithOutput(Console.OpenStandardOutput())
                          .WithLoggerFactory(new LoggerFactory())
                          .AddDefaultLoggingProvider()
                          .WithMinimumLogLevel(LogLevel.Trace)
                          .WithHandler <TextDocumentHandler>();

            options.OnInitialize(Delegate);

            var server = await LanguageServer.From(options);

            await server.WaitForExit;
        }
コード例 #21
0
 private void ConfigureServerWithDelegateCodeLens(LanguageServerOptions options)
 {
     options.OnCodeLens((@params, observer, capability, cancellationToken) => {
         observer.OnNext(new [] {
             new CodeLens()
             {
                 Command = new Command()
                 {
                     Name = "CodeLens 1"
                 }
             },
         });
         observer.OnNext(new [] {
             new CodeLens()
             {
                 Command = new Command()
                 {
                     Name = "CodeLens 2"
                 }
             },
         });
         observer.OnNext(new [] {
             new CodeLens()
             {
                 Command = new Command()
                 {
                     Name = "CodeLens 3"
                 }
             },
         });
         observer.OnCompleted();
     }, new CodeLensRegistrationOptions()
     {
         // DocumentSelector = DocumentSelector.ForPattern("**/*.cs")
     });
 }
コード例 #22
0
 private void ConfigureServer(LanguageServerOptions options)
 {
 }
コード例 #23
0
 public void Configure(LanguageServerOptions options) => options.AddHandler <InnerCodeLensHandler>();
コード例 #24
0
 protected virtual void ConfigureServerInputOutput(PipeReader clientOutput, PipeWriter serverInput, LanguageServerOptions options) =>
 options.WithInput(clientOutput).WithOutput(serverInput);
コード例 #25
0
            public ActionDelegateData()
            {
                {
                    var baseOptions = new LanguageServerOptions().WithPipe(new Pipe());

                    void BaseDelegate(LanguageServerOptions o)
                    {
                        o.WithPipe(new Pipe());
                    }

                    var serviceProvider = new ServiceCollection().BuildServiceProvider();
                    Add(new ActionDelegate("create (server): options", () => LanguageServer.Create(baseOptions)));
                    Add(new ActionDelegate("create (server): options, serviceProvider", () => LanguageServer.Create(baseOptions, serviceProvider)));
                    Add(new ActionDelegate("create (server): action", () => LanguageServer.Create(BaseDelegate)));
                    Add(new ActionDelegate("create (server): action, serviceProvider", () => LanguageServer.Create(BaseDelegate, serviceProvider)));

                    Add(new ActionDelegate("from (server): options", () => LanguageServer.From(baseOptions)));
                    Add(new ActionDelegate("from (server): options, cancellationToken", () => LanguageServer.From(baseOptions, CancellationToken.None)));
                    Add(
                        new ActionDelegate(
                            "from (server): options, serviceProvider, cancellationToken",
                            () => LanguageServer.From(baseOptions, serviceProvider, CancellationToken.None)
                            )
                        );
                    Add(new ActionDelegate("from (server): options, serviceProvider", () => LanguageServer.From(baseOptions, serviceProvider)));
                    Add(new ActionDelegate("from (server): action", () => LanguageServer.From(BaseDelegate)));
                    Add(new ActionDelegate("from (server): action, cancellationToken", () => LanguageServer.From(BaseDelegate, CancellationToken.None)));
                    Add(
                        new ActionDelegate(
                            "from (server): action, serviceProvider, cancellationToken",
                            () => LanguageServer.From(BaseDelegate, serviceProvider, CancellationToken.None)
                            )
                        );
                    Add(new ActionDelegate("from (server): action, serviceProvider", () => LanguageServer.From(BaseDelegate, serviceProvider)));
                }
                {
                    var baseOptions = new LanguageClientOptions().WithPipe(new Pipe());

                    void BaseDelegate(LanguageClientOptions o)
                    {
                        o.WithPipe(new Pipe());
                    }

                    var serviceProvider = new ServiceCollection().BuildServiceProvider();
                    Add(new ActionDelegate("create (client): options", () => LanguageClient.Create(baseOptions)));
                    Add(new ActionDelegate("create (client): options, serviceProvider", () => LanguageClient.Create(baseOptions, serviceProvider)));
                    Add(new ActionDelegate("create (client): action", () => LanguageClient.Create(BaseDelegate)));
                    Add(new ActionDelegate("create (client): action, serviceProvider", () => LanguageClient.Create(BaseDelegate, serviceProvider)));

                    Add(new ActionDelegate("from (client): options", () => LanguageClient.From(baseOptions)));
                    Add(new ActionDelegate("from (client): options, cancellationToken", () => LanguageClient.From(baseOptions, CancellationToken.None)));
                    Add(
                        new ActionDelegate(
                            "from (client): options, serviceProvider, cancellationToken",
                            () => LanguageClient.From(baseOptions, serviceProvider, CancellationToken.None)
                            )
                        );
                    Add(new ActionDelegate("from (client): options, serviceProvider", () => LanguageClient.From(baseOptions, serviceProvider)));
                    Add(new ActionDelegate("from (client): action", () => LanguageClient.From(BaseDelegate)));
                    Add(new ActionDelegate("from (client): action, cancellationToken", () => LanguageClient.From(BaseDelegate, CancellationToken.None)));
                    Add(
                        new ActionDelegate(
                            "from (client): action, serviceProvider, cancellationToken",
                            () => LanguageClient.From(BaseDelegate, serviceProvider, CancellationToken.None)
                            )
                        );
                    Add(new ActionDelegate("from (client): action, serviceProvider", () => LanguageClient.From(BaseDelegate, serviceProvider)));
                }
            }
 private void ConfigureServer(LanguageServerOptions options) => options.WithConfigurationSection("mysection").WithConfigurationSection("othersection");
コード例 #27
0
 private void ConfigureServerWithClassCodeLens(LanguageServerOptions options)
 {
     options.AddHandler <InnerCodeLensHandler>();
 }
コード例 #28
0
 private void ConfigureServer(LanguageServerOptions options)
 {
     options.OnCodeAction(@params => Task.FromResult(new CommandOrCodeActionContainer()), (capability, capabilities) => new CodeActionRegistrationOptions());
 }
コード例 #29
0
 private void ConfigureServer(LanguageServerOptions options)
 {
     // options.OnCodeLens()
 }
コード例 #30
0
        private LanguageServerOptions AddRequests(LanguageServerOptions options)
        {
            // Pathmap creation is seperated into 2 requests, 'pathmapFromClipboard' and 'pathmapApply'.
            // Pathmap generation request.
            options.OnRequest <object, string>("pathmapFromClipboard", _ => Task <string> .Run(() =>
            {
                // Create the error handler for pathmap parser.
                ServerPathmapHandler error = new ServerPathmapHandler();

                // Get the pathmap. 'map' will be null if there is an error.
                try
                {
                    Pathmap map = Pathmap.ImportFromCSV(Clipboard.GetText(), error);

                    if (map == null)
                    {
                        return(error.Message);
                    }
                    else
                    {
                        lastMap = map;
                        return("success");
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }));

            // Pathmap save request.
            options.OnRequest <Newtonsoft.Json.Linq.JToken>("pathmapApply", uriToken => Task.Run(() =>
            {
                // Save 'lastMap' to a file.
                string result = lastMap.ExportAsJSON();
                string output = uriToken["path"].ToObject <string>().Trim('/');
                using (var stream = new StreamWriter(output))
                    stream.Write(result);
            }));

            // Pathmap editor request.
            options.OnRequest <PathmapDocument, bool>("pathmapEditor", (editFileToken) => Task <bool> .Run(() =>
            {
                DeltinScript compile;
                if (editFileToken.Text == null)
                {
                    string editor = Extras.CombinePathWithDotNotation(null, "!PathfindEditor.del");
                    compile       = new DeltinScript(new TranslateSettings(editor)
                    {
                        OutputLanguage = ConfigurationHandler.OutputLanguage
                    });
                }
                else
                {
                    compile = Editor.Generate(editFileToken.File, Pathmap.ImportFromText(editFileToken.Text), ConfigurationHandler.OutputLanguage);
                }

                Clipboard.SetText(compile.WorkshopCode);

                return(true);
            }));

            // semantic tokens
            options.OnRequest <Newtonsoft.Json.Linq.JToken, SemanticToken[]>("semanticTokens", (uriToken) => Task <SemanticToken[]> .Run(async() =>
            {
                await DocumentHandler.WaitForParse();
                SemanticToken[] tokens = LastParse?.ScriptFromUri(new Uri(uriToken["fsPath"].ToObject <string>()))?.GetSemanticTokens();
                return(tokens ?? new SemanticToken[0]);
            }));

            // debugger start
            options.OnRequest <object>("debugger.start", args => Task.Run(() =>
            {
                _debugger.Start();
                return(new object());
            }));

            // debugger stop
            options.OnRequest <object>("debugger.stop", args => Task.Run(() =>
            {
                _debugger.Stop();
                return(new object());
            }));

            // debugger scopes
            options.OnRequest <ScopesArgs, DBPScope[]>("debugger.scopes", args => Task <DBPScope[]> .Run(() =>
            {
                try
                {
                    if (_debugger.VariableCollection != null)
                    {
                        return(_debugger.VariableCollection.GetScopes(args));
                    }
                }
                catch (Exception ex)
                {
                    DebuggerException(ex);
                }
                return(new DBPScope[0]);
            }));

            // debugger variables
            options.OnRequest <VariablesArgs, DBPVariable[]>("debugger.variables", args => Task <DBPVariable[]> .Run(() =>
            {
                try
                {
                    if (_debugger.VariableCollection != null)
                    {
                        return(_debugger.VariableCollection.GetVariables(args));
                    }
                }
                catch (Exception ex)
                {
                    DebuggerException(ex);
                }
                return(new DBPVariable[0]);
            }));

            // debugger evaluate
            options.OnRequest <EvaluateArgs, EvaluateResponse>("debugger.evaluate", args => Task <EvaluateResponse> .Run(() =>
            {
                try
                {
                    return(_debugger.VariableCollection?.Evaluate(args));
                }
                catch (Exception ex)
                {
                    DebuggerException(ex);
                    return(EvaluateResponse.Empty);
                }
            }));

            // Decompile insert
            options.OnRequest <DecompileResult>("decompile.insert", () => Task <DecompileResult> .Run(() =>
            {
                try
                {
                    var tte      = new ConvertTextToElement(Clipboard.GetText());
                    var workshop = tte.Get();
                    var code     = new WorkshopDecompiler(workshop, new OmitLobbySettingsResolver(), new CodeFormattingOptions()).Decompile();
                    return(new DecompileResult(tte, code));
                }
                catch (Exception ex)
                {
                    return(new DecompileResult(ex));
                }
            }));

            // Decompile file
            options.OnRequest <DecompileFileArgs, DecompileResult>("decompile.file", args => Task.Run <DecompileResult>(() =>
            {
                try
                {
                    // Parse the workshop code.
                    var tte      = new ConvertTextToElement(Clipboard.GetText());
                    var workshop = tte.Get();

                    // Decompile the parsed workshop code.
                    var workshopToCode = new WorkshopDecompiler(workshop, new FileLobbySettingsResolver(args.File, workshop.LobbySettings), new CodeFormattingOptions());
                    var code           = workshopToCode.Decompile();

                    var result = new DecompileResult(tte, code);

                    // Only create the decompile was successful.
                    if (result.Success)
                    {
                        // Create the file.
                        using (var writer = File.CreateText(args.File))
                            // Write the code to the file.
                            writer.Write(code);
                    }

                    return(result);
                }
                catch (Exception ex)
                {
                    return(new DecompileResult(ex));
                }
            }));

            return(options);
        }