public async Task Test1() { var logFactory = LoggerFactory.Create(a => a.AddNLog().SetMinimumLevel(LogLevel.Trace)); var serverProcess = new NamedPipeServerProcess("test", logFactory); var languageClient = new LanguageClient(logFactory, serverProcess); var clientInit = languageClient.Initialize("/"); var serverInit = RhetosLanguageServer.BuildLanguageServer(serverProcess.ClientOutputStream, serverProcess.ClientInputStream, builder => builder.AddNLog().AddLanguageServer().AddConsole()); Task.WaitAll(clientInit, serverInit); Console.WriteLine(languageClient.IsConnected.ToString()); var textDocument = new TextDocumentItem() { Text = @"// <rhetosRootPath="""" />\nble ble ble\nblelle", Uri = new Uri("file://ble.rhe") }; var opened = await languageClient.SendRequest <object>(DocumentNames.DidOpen, new DidOpenTextDocumentParams() { TextDocument = textDocument }); Task.Delay(2500).Wait(); var result = await languageClient.SendRequest <CompletionList>(DocumentNames.Completion, new CompletionParams() { TextDocument = new TextDocumentIdentifier(textDocument.Uri), Position = new Position() }); Console.WriteLine(JsonConvert.SerializeObject(result.Items, Formatting.Indented)); Task.Delay(3000).Wait(); languageClient.Dispose(); }
public async Task DocumentSymbols_DocumentSymbol_Success() { await Connect(); const int line = 5; const int character = 6; var expectedDocumentPath = AbsoluteDocumentPath; var expectedDocumentUri = DocumentUri.FromFileSystemPath(expectedDocumentPath); var detail = "some detail"; var documentSymbol = new DocumentSymbol { Detail = detail, Kind = SymbolKind.Class, Range = new Range(new Position(line, character), new Position(line, character)) }; var expectedSymbols = new SymbolInformationOrDocumentSymbolContainer( new SymbolInformationOrDocumentSymbol(documentSymbol)); ServerDispatcher.HandleRequest <DocumentSymbolParams, SymbolInformationOrDocumentSymbolContainer>(DocumentNames.DocumentSymbol, (request, cancellationToken) => { Assert.NotNull(request.TextDocument); Assert.Equal(expectedDocumentUri, request.TextDocument.Uri); return(Task.FromResult(expectedSymbols)); }); var documentSymbolParams = new DocumentSymbolParams { TextDocument = new TextDocumentIdentifier(expectedDocumentUri) }; var symbols = await LanguageClient.SendRequest <SymbolInformationOrDocumentSymbolContainer>(DocumentNames.DocumentSymbol, documentSymbolParams); var actualSymbols = symbols.ToArray(); Assert.Collection(actualSymbols, actualSymbol => { var expectedSymbol = expectedSymbols.Single(); Assert.True(expectedSymbol.IsDocumentSymbol); Assert.NotNull(actualSymbol.DocumentSymbol); Assert.Equal(expectedSymbol.DocumentSymbol.Detail, actualSymbol.DocumentSymbol.Detail); Assert.Equal(expectedSymbol.DocumentSymbol.Kind, actualSymbol.DocumentSymbol.Kind); Assert.Equal(expectedSymbol.DocumentSymbol.Range.Start.Line, actualSymbol.DocumentSymbol.Range.Start.Line); Assert.Equal(expectedSymbol.DocumentSymbol.Range.Start.Character, actualSymbol.DocumentSymbol.Range.Start.Character); Assert.Equal(expectedSymbol.DocumentSymbol.Range.End.Line, actualSymbol.DocumentSymbol.Range.End.Line); Assert.Equal(expectedSymbol.DocumentSymbol.Range.End.Character, actualSymbol.DocumentSymbol.Range.End.Character); }); }
public async Task CanSendPowerShellGetVersionRequest() { PowerShellVersion details = await LanguageClient.SendRequest <PowerShellVersion>("powerShell/getVersion", new GetVersionParams()); if (PwshExe == "powershell") { Assert.Equal("Desktop", details.Edition); } else { Assert.Equal("Core", details.Edition); } }
/// <summary> /// The main asynchronous program entry-point. /// </summary> /// <returns> /// A <see cref="Task"/> representing program operation. /// </returns> static async Task AsyncMain() { ProcessStartInfo serverStartInfo = new ProcessStartInfo("dotnet") { Arguments = $"\"{ServerAssembly}\"" }; Log.Information("Starting server..."); LanguageClient client = new LanguageClient(Log.Logger, serverStartInfo) { ClientCapabilities = { Workspace = { DidChangeConfiguration = new DidChangeConfigurationCapability { DynamicRegistration = false } } } }; using (client) { // Listen for log messages from the language server. client.Window.OnLogMessage((message, messageType) => { Log.Information("Language server says: [{MessageType:l}] {Message}", messageType, message); }); // Listen for our custom notification from the language server. client.HandleNotification <DummyParams>("dummy/notify", notification => { Log.Information("Received dummy notification from language server: {Message}", notification.Message ); }); await client.Initialize(workspaceRoot : @"C:\Foo"); Log.Information("Client started."); // Update server configuration. client.Workspace.DidChangeConfiguration( new JObject( new JProperty("setting1", true), new JProperty("setting2", "Hello") ) ); // Invoke our custom handler. await client.SendRequest("dummy", new DummyParams { Message = "Hello, world!" }); Log.Information("Stopping language server..."); await client.Shutdown(); Log.Information("Server stopped."); } }