Skip to content

Commit

Permalink
WIP - Source clojuredocs from clojure-lsp
Browse files Browse the repository at this point in the history
Adding a command for testing how to get clojuredocs.
(Which can't be done yet, see:
clojure-lsp/clojure-lsp#598)
Addressing #689
  • Loading branch information
PEZ committed Oct 31, 2021
1 parent d66cc3b commit 2af74f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,11 @@
"title": "Clojure-lsp Server Info",
"category": "Calva Diagnostics"
},
{
"category": "Calva",
"command": "calva.clojuredocs",
"title": "Clojuredocs"
},
{
"category": "Calva",
"command": "calva.toggleBetweenImplAndTest",
Expand Down
22 changes: 22 additions & 0 deletions src/lsp/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,23 @@ function registerDiagnosticsCommands(context: vscode.ExtensionContext): void {
context.subscriptions.push(vscode.commands.registerCommand('calva.diagnostics.openClojureLspLogFile', openLogFile));
}

async function clojuredocsCommandHandler(): Promise<void> {
const client = getStateValue(LSP_CLIENT_KEY);
if (client) {
const clojuredocs = await getClojuredocs(client);
const calvaSaysChannel = state.outputChannel();
calvaSaysChannel.appendLine(`Clojuredocs:`);
const clojuredocsPretty = JSON.stringify(clojuredocs, null, 2);
calvaSaysChannel.appendLine(clojuredocsPretty);
calvaSaysChannel.show(true);
} else {
vscode.window.showInformationMessage('There is no clojure-lsp server running.');
}
}

async function activate(context: vscode.ExtensionContext): Promise<void> {
registerDiagnosticsCommands(context);
context.subscriptions.push(vscode.commands.registerCommand('calva.clojuredocs', clojuredocsCommandHandler));
const extensionPath = context.extensionPath;
const currentVersion = readVersionFile(extensionPath);
const userConfiguredClojureLspPath = config.getConfig().clojureLspPath;
Expand Down Expand Up @@ -397,6 +412,13 @@ async function openLogFile(): Promise<void> {
}
}

async function getClojuredocs(lspClient: LanguageClient): Promise<any> {
return lspClient.sendRequest('clojure/clojuredocs/raw', {
symName: 'pprint',
symNs: 'clojure.core'
});
}

export default {
activate,
deactivate,
Expand Down

0 comments on commit 2af74f6

Please sign in to comment.