Skip to content

Commit 08a45ec

Browse files
committed
Add move-form refactoring
1 parent 4e05952 commit 08a45ec

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,12 @@
17701770
"category": "clojure-lsp Refactor",
17711771
"enablement": "editorLangId == clojure && clojureLsp:active"
17721772
},
1773+
{
1774+
"command": "clojureLsp.refactor.moveForm",
1775+
"title": "Move form",
1776+
"category": "clojure-lsp Refactor",
1777+
"enablement": "editorLangId == clojure && clojureLsp:active"
1778+
},
17731779
{
17741780
"command": "clojureLsp.refactor.threadFirst",
17751781
"title": "Thread First",

src/lsp/main.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ type ClojureLspCommand = {
185185
command: string;
186186
extraParamFn?: () => Thenable<string>;
187187
category?: string;
188+
requireLocalFile?: boolean;
188189
};
189190

190191
function makePromptForInput(placeHolder: string) {
@@ -197,6 +198,19 @@ function makePromptForInput(placeHolder: string) {
197198
};
198199
}
199200

201+
function makeQuickPickForInput() {
202+
return async () => {
203+
const uris = await vscode.window.showOpenDialog({
204+
canSelectFolders: false,
205+
canSelectFiles: true,
206+
canSelectMany: false,
207+
openLabel: 'Select destination',
208+
title: 'Select destination',
209+
});
210+
return uris?.length > 0 ? uris[0].path : undefined;
211+
};
212+
}
213+
200214
const clojureLspCommands: ClojureLspCommand[] = [
201215
{
202216
command: 'clean-ns',
@@ -255,6 +269,11 @@ const clojureLspCommands: ClojureLspCommand[] = [
255269
command: 'extract-function',
256270
extraParamFn: makePromptForInput('Function name'),
257271
},
272+
{
273+
command: 'move-form',
274+
extraParamFn: makeQuickPickForInput(),
275+
requireLocalFile: true,
276+
},
258277
];
259278

260279
function sendCommandRequest(command: string, args: (number | string)[]): void {
@@ -284,9 +303,15 @@ function registerLspCommand(command: ClojureLspCommand): vscode.Disposable {
284303
const column = editor.selection.start.character;
285304
const docUri = `${document.uri.scheme}://${document.uri.path}`;
286305
const params = [docUri, line, column];
287-
const extraParam = command.extraParamFn ? await command.extraParamFn() : undefined;
288-
if (!command.extraParamFn || (command.extraParamFn && extraParam)) {
289-
sendCommandRequest(command.command, extraParam ? [...params, extraParam] : params);
306+
if (command.requireLocalFile === true && document.uri.scheme !== 'file') {
307+
vscode.window.showErrorMessage('This function only works on local files');
308+
} else {
309+
let extraParam = command.extraParamFn ? await command.extraParamFn() : undefined;
310+
if (command.command === 'execute-lsp-command' && command.extraParamFn && extraParam) {
311+
sendCommandRequest(extraParam, params);
312+
} else if (!command.extraParamFn || (command.extraParamFn && extraParam)) {
313+
sendCommandRequest(command.command, extraParam ? [...params, extraParam] : params);
314+
}
290315
}
291316
}
292317
});

0 commit comments

Comments
 (0)