public static WorkAndProgressTester Setup(LanguageClient client) { var tester = new WorkAndProgressTester(); client.HandleNotification("$/progress", (JObject progressParams) => { var jsonAgain = progressParams.ToString() .Replace(SrcFolderUri, "SRC") .Replace(Lsp4DUtil.DefaultSrcFolder, "ABSSRC"); switch (progressParams["token"].ToString()) { case "partialResult": tester._recordedResultProgress.Append(jsonAgain).Append(',').AppendLine(); break; case "workDone": tester._recordedWorkProgress.Append(jsonAgain).Append(',').AppendLine(); break; default: Assert.Fail("unexpected progress notification token " + progressParams["token"]); return; } }); return(tester); }
/// <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."); } }
static async Task Main(string[] args) { ProcessStartInfo serverStartInfo = new ProcessStartInfo("c:\\Program Files\\LLVM\\bin\\clangd.exe") { Arguments = "-compile-commands-dir=c:\\dev\\repos\\ILMD" }; var factory = new LoggerFactory(); await Task.Factory.StartNew(async() => { using (var client = new LanguageClient(factory, serverStartInfo)) { var doc = client.ClientCapabilities.TextDocument = new TextDocumentClientCapabilities { CodeAction = new CodeActionCapability { DynamicRegistration = true }, CodeLens = new CodeLensCapability { DynamicRegistration = true }, ColorProvider = new ColorProviderCapability { DynamicRegistration = true }, Completion = new CompletionCapability { CompletionItem = new CompletionItemCapability { CommitCharactersSupport = true, DocumentationFormat = new Container <MarkupKind>(MarkupKind.Markdown, MarkupKind.Plaintext), SnippetSupport = true }, CompletionItemKind = new CompletionItemKindCapability { ValueSet = new Container <CompletionItemKind>((CompletionItemKind[])Enum.GetValues(typeof(CompletionItemKind))) }, ContextSupport = true, DynamicRegistration = true }, Definition = new DefinitionCapability { DynamicRegistration = true, }, DocumentHighlight = new DocumentHighlightCapability { DynamicRegistration = true, }, DocumentLink = new DocumentLinkCapability { DynamicRegistration = true, }, DocumentSymbol = new DocumentSymbolCapability { DynamicRegistration = true, SymbolKind = new SymbolKindCapability { ValueSet = new Container <SymbolKind>((SymbolKind[])Enum.GetValues(typeof(SymbolKind))) } }, Formatting = new DocumentFormattingCapability { DynamicRegistration = true }, Hover = new HoverCapability { DynamicRegistration = true, ContentFormat = new Container <MarkupKind>((MarkupKind[])Enum.GetValues(typeof(MarkupKind))) }, Implementation = new ImplementationCapability { DynamicRegistration = true }, OnTypeFormatting = new DocumentOnTypeFormattingCapability { DynamicRegistration = true }, PublishDiagnostics = new PublishDiagnosticsCapability { RelatedInformation = true }, RangeFormatting = new DocumentRangeFormattingCapability { DynamicRegistration = true }, References = new ReferencesCapability { DynamicRegistration = true }, Rename = new RenameCapability { DynamicRegistration = true }, SignatureHelp = new SignatureHelpCapability { DynamicRegistration = true, SignatureInformation = new SignatureInformationCapability { ContentFormat = new Container <MarkupKind>((MarkupKind[])Enum.GetValues(typeof(MarkupKind))) } }, Synchronization = new SynchronizationCapability { DidSave = true, DynamicRegistration = true, WillSave = true, WillSaveWaitUntil = true }, TypeDefinition = new TypeDefinitionCapability { DynamicRegistration = true }, }; var workspace = client.ClientCapabilities.Workspace = new WorkspaceClientCapabilities { ApplyEdit = true, Configuration = true, DidChangeConfiguration = new DidChangeConfigurationCapability { DynamicRegistration = true }, DidChangeWatchedFiles = new DidChangeWatchedFilesCapability { DynamicRegistration = true }, ExecuteCommand = new ExecuteCommandCapability { DynamicRegistration = true }, Symbol = new WorkspaceSymbolCapability { DynamicRegistration = true, SymbolKind = new SymbolKindCapability { ValueSet = new Container <SymbolKind>((SymbolKind[])Enum.GetValues(typeof(SymbolKind))) } }, WorkspaceEdit = new WorkspaceEditCapability { DocumentChanges = true }, WorkspaceFolders = true }; client.ClientCapabilities.TextDocument.PublishDiagnostics = new PublishDiagnosticsCapability { RelatedInformation = true }; client.HandleNotification("dummy/notify", () => { Log.Information("Received dummy notification from language server."); }); await client.Initialize("c:\\dev\\repos\\ILMD", new InitializedParams { }); var caps = client.ServerCapabilities; var ccaps = client.ClientCapabilities; client.TextDocument.OnPublishDiagnostics((uri, diags) => { }); string filePath = "c:\\dev\\repos\\ILMD\\PeripheralBoard\\PeripheralBoard.DiscoveryBoard\\main.cpp"; client.TextDocument.DidOpen(filePath, "cpp", File.ReadAllText(filePath)); } }); while (true) { Thread.Sleep(10); } }