@@ -12,7 +12,8 @@ type BaseLspCommand = {
1212 category ?: string ;
1313} ;
1414
15- // If afterCommandFn is defined, then defaultName must be too
15+ const namePositionDefault = 3 ;
16+ // If afterCommandFn is defined, then defaultName must be too, namePosition defaults to position 3
1617type ClojureLspCommand = BaseLspCommand &
1718 (
1819 | {
@@ -21,9 +22,11 @@ type ClojureLspCommand = BaseLspCommand &
2122 commandResponse : Record < string , unknown >
2223 ) => Thenable < any > ;
2324 defaultName : string ;
25+ namePosition ?: number ;
2426 }
2527 | {
2628 defaultName ?: string ;
29+ namePosition ?: number ;
2730 afterCommandFn ?: never ;
2831 }
2932 ) ;
@@ -38,7 +41,7 @@ async function renameAfterRefactor(
3841 commandArgs : Array < string | number > ,
3942 commandResponse : vscode_lsp . WorkspaceEdit
4043) {
41- if ( commandArgs [ 3 ] !== this . defaultName ) {
44+ if ( commandArgs [ this . namePosition ?? namePositionDefault ] !== this . defaultName ) {
4245 return ;
4346 }
4447
@@ -106,6 +109,8 @@ const clojureLspCommands: ClojureLspCommand[] = [
106109 { command : 'drag-param-backward' , category : 'clojureLsp' } ,
107110 { command : 'drag-param-forward' , category : 'clojureLsp' } ,
108111 { command : 'expand-let' , category : 'clojureLsp.refactor' } ,
112+ { command : 'if->cond-refactor' , category : 'clojureLsp.refactor' } ,
113+ { command : 'cond->if-refactor' , category : 'clojureLsp.refactor' } ,
109114 { command : 'get-in-all' , category : 'clojureLsp.refactor' } ,
110115 { command : 'get-in-less' , category : 'clojureLsp.refactor' } ,
111116 { command : 'get-in-more' , category : 'clojureLsp.refactor' } ,
@@ -114,6 +119,7 @@ const clojureLspCommands: ClojureLspCommand[] = [
114119 { command : 'move-coll-entry-down' , category : 'clojureLsp.refactor' } ,
115120 { command : 'move-coll-entry-up' , category : 'clojureLsp.refactor' } ,
116121 { command : 'move-form' , category : 'clojureLsp.refactor' } ,
122+ { command : 'move-to-for-let' , category : 'clojureLsp.refactor' } ,
117123 { command : 'replace-refer-all-with-alias' , category : 'clojureLsp.refactor' } ,
118124 { command : 'replace-refer-all-with-refer' , category : 'clojureLsp.refactor' } ,
119125 { command : 'resolve-macro-as' , category : 'clojureLsp.refactor' } ,
@@ -146,6 +152,17 @@ const clojureLspCommands: ClojureLspCommand[] = [
146152 defaultName : 'new-fn' ,
147153 category : 'clojureLsp.refactor' ,
148154 } ,
155+ {
156+ command : 'inline-function' ,
157+ category : 'clojureLsp.refactor' ,
158+ } ,
159+ {
160+ command : 'extract-function-2' ,
161+ afterCommandFn : renameAfterRefactor ,
162+ defaultName : 'new-fn' ,
163+ namePosition : 5 ,
164+ category : 'clojureLsp.refactor' ,
165+ } ,
149166 {
150167 command : 'extract-to-def' ,
151168 afterCommandFn : renameAfterRefactor ,
@@ -245,18 +262,7 @@ function registerUserspaceLspCommand(
245262 // default rather than letting clojure-lsp pick a name so that when we trigger a rename action
246263 // after the command completes, we know what to rename.
247264 if ( command . defaultName ) {
248- params [ 3 ] = command . defaultName ;
249- }
250-
251- // clojure-lsp's `extract-function` always destructures selection-end coords
252- // from the args so a 4-arg call throws IndexOutOfBoundsException.
253- // Append the selection end so the call works whether or not a region is
254- // selected.
255- // https://github.com/clojure-lsp/clojure-lsp/issues/2118
256- if ( command . command === 'extract-function' ) {
257- const selection = calva_utils . getActiveTextEditor ( ) . selections [ 0 ] ;
258- params [ 4 ] = selection . end . line ;
259- params [ 5 ] = selection . end . character ;
265+ params [ command . namePosition ?? namePositionDefault ] = command . defaultName ;
260266 }
261267
262268 sendCommandRequest ( clients , command . command , params ) ;
@@ -273,7 +279,7 @@ function registerInternalLspCommand(
273279 // default name. Replace that name with our own default so we know what to look for when we
274280 // trigger a rename action on it afterwards.
275281 if ( command . defaultName ) {
276- args [ 3 ] = command . defaultName ;
282+ args [ command . namePosition ?? namePositionDefault ] = command . defaultName ;
277283 }
278284
279285 sendCommandRequest ( clients , command . command , args ) ;
0 commit comments