diff --git a/package.json b/package.json index c377fe786..551d1301a 100644 --- a/package.json +++ b/package.json @@ -1770,6 +1770,12 @@ "category": "clojure-lsp Refactor", "enablement": "editorLangId == clojure && clojureLsp:active" }, + { + "command": "clojureLsp.refactor.moveForm", + "title": "Move form", + "category": "clojure-lsp Refactor", + "enablement": "editorLangId == clojure && clojureLsp:active" + }, { "command": "clojureLsp.refactor.threadFirst", "title": "Thread First", diff --git a/src/lsp/main.ts b/src/lsp/main.ts index 56c499ecd..913cdd7eb 100644 --- a/src/lsp/main.ts +++ b/src/lsp/main.ts @@ -185,6 +185,7 @@ type ClojureLspCommand = { command: string; extraParamFn?: () => Thenable; category?: string; + requireLocalFile?: boolean; }; function makePromptForInput(placeHolder: string) { @@ -197,6 +198,19 @@ function makePromptForInput(placeHolder: string) { }; } +function makeQuickPickForInput() { + return async () => { + const uris = await vscode.window.showOpenDialog({ + canSelectFolders: false, + canSelectFiles: true, + canSelectMany: false, + openLabel: 'Select destination', + title: 'Select destination', + }); + return uris?.length > 0 ? uris[0].path : undefined; + }; +} + const clojureLspCommands: ClojureLspCommand[] = [ { command: 'clean-ns', @@ -255,6 +269,11 @@ const clojureLspCommands: ClojureLspCommand[] = [ command: 'extract-function', extraParamFn: makePromptForInput('Function name'), }, + { + command: 'move-form', + extraParamFn: makeQuickPickForInput(), + requireLocalFile: true, + }, ]; function sendCommandRequest(command: string, args: (number | string)[]): void { @@ -284,9 +303,15 @@ function registerLspCommand(command: ClojureLspCommand): vscode.Disposable { const column = editor.selection.start.character; const docUri = `${document.uri.scheme}://${document.uri.path}`; const params = [docUri, line, column]; - const extraParam = command.extraParamFn ? await command.extraParamFn() : undefined; - if (!command.extraParamFn || (command.extraParamFn && extraParam)) { - sendCommandRequest(command.command, extraParam ? [...params, extraParam] : params); + if (command.requireLocalFile === true && document.uri.scheme !== 'file') { + vscode.window.showErrorMessage('This function only works on local files'); + } else { + let extraParam = command.extraParamFn ? await command.extraParamFn() : undefined; + if (command.command === 'execute-lsp-command' && command.extraParamFn && extraParam) { + sendCommandRequest(extraParam, params); + } else if (!command.extraParamFn || (command.extraParamFn && extraParam)) { + sendCommandRequest(command.command, extraParam ? [...params, extraParam] : params); + } } } });