diff --git a/examples/servers/json_server.py b/examples/servers/json_server.py index 64c1c6a6..34fe101b 100644 --- a/examples/servers/json_server.py +++ b/examples/servers/json_server.py @@ -41,7 +41,7 @@ class JsonLanguageServer(LanguageServer): CMD_SHOW_CONFIGURATION_THREAD = "showConfigurationThread" CMD_UNREGISTER_COMPLETIONS = "unregisterCompletions" - CONFIGURATION_SECTION = "jsonServer" + CONFIGURATION_SECTION = "pygls.jsonServer" def __init__(self, *args): super().__init__(*args) diff --git a/examples/vscode-playground/package.json b/examples/vscode-playground/package.json index 31d75f5a..4c4addad 100644 --- a/examples/vscode-playground/package.json +++ b/examples/vscode-playground/package.json @@ -33,6 +33,17 @@ } ], "configuration": [ + { + "type": "object", + "title": "Json Server Configuration", + "properties": { + "pygls.jsonServer.exampleConfiguration": { + "scope": "resource", + "type": "string", + "default": "You can override this message" + } + } + }, { "type": "object", "title": "Server Configuration", diff --git a/examples/vscode-playground/src/extension.ts b/examples/vscode-playground/src/extension.ts index b8a6abe1..910d64e9 100644 --- a/examples/vscode-playground/src/extension.ts +++ b/examples/vscode-playground/src/extension.ts @@ -30,7 +30,6 @@ const MIN_PYTHON = semver.parse("3.7.9") // Some other nice to haves. // TODO: Check selected env satisfies pygls' requirements - if not offer to run the select env command. -// TODO: Inspect ServerCapabilities and present a quick pick list of runnable commands. // TODO: Start a debug session for the currently configured server. // TODO: TCP Transport // TODO: WS Transport @@ -62,6 +61,13 @@ export async function activate(context: vscode.ExtensionContext) { }) ) + // Execute command... command + context.subscriptions.push( + vscode.commands.registerCommand("pygls.server.executeCommand", async () => { + await executeServerCommand() + }) + ) + // Restart the language server if the user switches Python envs... context.subscriptions.push( python.environments.onDidChangeActiveEnvironmentPath(async () => { @@ -213,6 +219,35 @@ function startLangServerTCP(addr: number): LanguageClient { ); } +/** + * Execute a command provided by the language server. + */ +async function executeServerCommand() { + if (!client || client.state !== State.Running) { + await vscode.window.showErrorMessage("There is no language server running.") + return + } + + const knownCommands = client.initializeResult.capabilities.executeCommandProvider?.commands + if (!knownCommands || knownCommands.length === 0) { + const info = client.initializeResult.serverInfo + const name = info?.name || "Server" + const version = info?.version || "" + + await vscode.window.showInformationMessage(`${name} ${version} does not implement any commands.`) + return + } + + const commandName = await vscode.window.showQuickPick(knownCommands, { canPickMany: false }) + if (!commandName) { + return + } + logger.info(`executing command: '${commandName}'`) + + const result = await vscode.commands.executeCommand(commandName /* if your command accepts arguments you can pass them here */) + logger.info(`${commandName} result: ${JSON.stringify(result, undefined, 2)}`) +} + /** * If the user has explicitly provided a src directory use that. * Otherwise, fallback to the examples/servers directory.