Skip to content

Commit

Permalink
Add clojure-lsp command showing trace settings
Browse files Browse the repository at this point in the history
Fixes #1876
  • Loading branch information
PEZ committed Sep 25, 2022
1 parent 1c8a883 commit f745929
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes to Calva.

## [Unreleased]

- [Make it easier to find the clojure-lsp server trace log level](https://github.com/BetterThanTomorrow/calva/issues/1876)

## [2.0.304] - 2022-09-20

- [Keep deps.clj updated](https://github.com/BetterThanTomorrow/calva/issues/1871)
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,11 @@
"title": "Open Clojure LSP Log File",
"category": "Calva Diagnostics"
},
{
"command": "calva.diagnostics.showLspTraceLevelSettings",
"title": "Show LSP Trace Level Settings",
"category": "Calva Diagnostics"
},
{
"command": "calva.diagnostics.toggleNreplLoggingEnabled",
"title": "Toggle nREPL Logging Enabled",
Expand Down
54 changes: 41 additions & 13 deletions src/lsp/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ function registerDiagnosticsCommands(context: vscode.ExtensionContext): void {
context.subscriptions.push(
vscode.commands.registerCommand('calva.diagnostics.openClojureLspLogFile', openLogFile)
);
context.subscriptions.push(
vscode.commands.registerCommand(
'calva.diagnostics.showLspTraceLevelSettings',
configureTraceLogLevel
)
);
}

export type LspStatus = 'stopped' | 'starting' | 'started' | 'downloading' | 'error';
Expand Down Expand Up @@ -767,6 +773,10 @@ async function openLogFile(): Promise<void> {
}
}

function configureTraceLogLevel() {
void vscode.commands.executeCommand('workbench.action.openSettings', 'clojure.trace.server');
}

export async function getClojuredocs(symName: string, symNs: string): Promise<any> {
if (serverVersion > '2021.10.20-16.49.47') {
const client: LanguageClient = getStateValue(LSP_CLIENT_KEY);
Expand Down Expand Up @@ -819,14 +829,30 @@ function showMenu(items: vscode.QuickPickItem[], commands: Record<string, string
});
}

function commonMenuCommands(): [vscode.QuickPickItem[], Record<string, string>] {
const SHOW_TRACE_LEVEL_SETTINGS_COMMAND = 'calva.diagnostics.showLspTraceLevelSettings';
const SHOW_TRACE_LEVEL_SETTINGS_OPTION = 'Open Trace Level Settings';
const commands = {
[SHOW_TRACE_LEVEL_SETTINGS_OPTION]: SHOW_TRACE_LEVEL_SETTINGS_COMMAND,
};
const items: vscode.QuickPickItem[] = [
{
label: SHOW_TRACE_LEVEL_SETTINGS_OPTION,
description: 'Opens the client/server trace level in VS Code Settings',
},
];
return [items, commands];
}

function stoppedMenuCommand() {
const START_OPTION = 'Start';
const START_COMMAND = 'calva.clojureLsp.start';
const DOWNLOAD_OPTION = 'Download configured version';
const DOWNLOAD_COMMAND = 'calva.clojureLsp.download';
const commands = {};
commands[START_OPTION] = START_COMMAND;
commands[DOWNLOAD_OPTION] = DOWNLOAD_COMMAND;
const commands: Record<string, string> = {
[START_OPTION]: START_COMMAND,
[DOWNLOAD_OPTION]: DOWNLOAD_COMMAND,
};
const items: vscode.QuickPickItem[] = [
{
label: START_OPTION,
Expand All @@ -837,7 +863,8 @@ function stoppedMenuCommand() {
description: `${config.getConfig().clojureLspVersion}`,
},
];
showMenu(items, commands);
const [commonItems, commonCommands] = commonMenuCommands();
showMenu([...items, ...commonItems], { ...commands, ...commonCommands });
}

function startedMenuCommand() {
Expand All @@ -856,14 +883,6 @@ function startedMenuCommand() {
[RESTART_OPTION]: RESTART_COMMAND,
};
const items: vscode.QuickPickItem[] = [
{
label: INFO_OPTION,
description: 'Print clojure-lsp server info to `Calva says`',
},
{
label: LOG_OPTION,
description: 'Open the clojure-lsp log file',
},
{
label: STOP_OPTION,
description: 'Stop the clojure-lsp server',
Expand All @@ -872,8 +891,17 @@ function startedMenuCommand() {
label: RESTART_OPTION,
description: 'Restart the clojure-lsp server',
},
{
label: INFO_OPTION,
description: 'Print clojure-lsp server info to `Calva says`',
},
{
label: LOG_OPTION,
description: 'Open the clojure-lsp log file',
},
];
showMenu(items, commands);
const [commonItems, commonCommands] = commonMenuCommands();
showMenu([...items, ...commonItems], { ...commands, ...commonCommands });
}

export default {
Expand Down

0 comments on commit f745929

Please sign in to comment.