clojure-lsp / clojure-lsp

Clojure & ClojureScript Language Server (LSP) implementation

Home Page:https://clojure-lsp.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parinfer in smart/indent modes messes with refactors

vlnn opened this issue · comments

Describe the bug
When parinfer mode is indent or smart, lsp code actions are messing with the code.

To Reproduce
Steps to reproduce the behavior:

Wrong function with changed structure is moved out let when parinfer in indent or smart mode
CleanShot 2024-01-12 at 03 39 03

Expected behavior
I expect the code action is not changing the code structure/behaviour. When parinfer is in parens mode, code actions work as expected:

CleanShot 2024-01-12 at 03 38 12

Log - client <-> server
ADD JSON HERE
Log - clojure-lsp
[Trace - 03:45:35 AM] Sending request 'textDocument/codeAction - (1416)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/va/tmp/lsp-par.clj"
  },
  "range": {
    "start": {
      "line": 1,
      "character": 12
    },
    "end": {
      "line": 1,
      "character": 12
    }
  },
  "context": {
    "diagnostics": []
  }
}

[Trace - 03:45:35 AM] Received response 'textDocument/codeAction - (1416)' in 2ms.
Result: [
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12
]
}
},
{
"title": "Drag forward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag forward",
"command": "drag-forward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
12
]
}
}
]

[Trace - 03:45:36 AM] Sending request 'textDocument/hover - (1417)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 11
}
}

[Trace - 03:45:36 AM] Sending request 'textDocument/codeAction - (1418)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 2,
"character": 11
},
"end": {
"line": 2,
"character": 11
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:36 AM] Sending request 'textDocument/documentHighlight - (1419)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 11
}
}

[Trace - 03:45:36 AM] Received response 'textDocument/hover - (1417)' in 7ms.
Result: {
"range": {
"start": {
"line": 2,
"character": 7
},
"end": {
"line": 2,
"character": 8
}
},
"contents": {
"kind": "markdown",
"value": "clojure\n>\n\n\n----\n\n*/Users/va/tmp/lsp-par.clj*"
}
}

[Trace - 03:45:36 AM] Received response 'textDocument/codeAction - (1418)' in 9ms.
Result: [
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11,
null
]
}
},
{
"title": "Thread first all",
"kind": "refactor.rewrite",
"command": {
"title": "Thread first all",
"command": "thread-first-all",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11
]
}
},
{
"title": "Thread last all",
"kind": "refactor.rewrite",
"command": {
"title": "Thread last all",
"command": "thread-last-all",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
11
]
}
}
]

[Trace - 03:45:36 AM] Received response 'textDocument/documentHighlight - (1419)' in 11ms.
Result: []

[Trace - 03:45:37 AM] Sending request 'textDocument/codeAction - (1420)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 5,
"character": 12
},
"end": {
"line": 5,
"character": 12
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:37 AM] Sending request 'textDocument/documentHighlight - (1421)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 5,
"character": 12
}
}

[Trace - 03:45:37 AM] Sending request 'textDocument/hover - (1422)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 5,
"character": 12
}
}

[Trace - 03:45:37 AM] Received response 'textDocument/codeAction - (1420)' in 5ms.
Result: [
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12
]
}
},
{
"title": "Drag forward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag forward",
"command": "drag-forward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
5,
12
]
}
}
]

[Trace - 03:45:37 AM] Received response 'textDocument/documentHighlight - (1421)' in 8ms.
Result: [
{
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 23
}
}
}
]

[Trace - 03:45:37 AM] Received response 'textDocument/hover - (1422)' in 8ms.
Result: {
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 23
}
},
"contents": {
"kind": "markdown",
"value": "clojure\nuser/test-parinfer-lsp []\n\n\n----\n\n*/Users/va/tmp/lsp-par.clj*"
}
}

[Trace - 03:45:40 AM] Sending request 'textDocument/hover - (1423)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 10
}
}

[Trace - 03:45:40 AM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj",
"version": 219
},
"contentChanges": [
{
"text": "(defn test-parinfer-lsp []\n (let [a 2\n b (if (> a 3)\n (+ a 2)\n a)]\n b))\n"
}
]
}

[Trace - 03:45:40 AM] Sending request 'textDocument/codeAction - (1424)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 2,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:40 AM] Sending request 'textDocument/documentHighlight - (1425)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 10
}
}

[Trace - 03:45:40 AM] Sending request 'textDocument/codeLens - (1426)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
}
}

[Trace - 03:45:40 AM] Received response 'textDocument/hover - (1423)' in 8ms.
Result: {
"contents": []
}

[Trace - 03:45:40 AM] Received response 'textDocument/codeLens - (1426)' in 61ms.
Result: [
{
"range": {
"start": {
"line": 0,
"character": 6
},
"end": {
"line": 0,
"character": 23
}
},
"data": [
"file:///Users/va/tmp/lsp-par.clj",
1,
7
]
}
]

[Trace - 03:45:40 AM] Sending request 'codeLens/resolve - (1427)'.
Params: {
"range": {
"start": {
"line": 0,
"character": 6
},
"end": {
"line": 0,
"character": 23
}
},
"data": [
"file:///Users/va/tmp/lsp-par.clj",
1,
7
],
"_workspace": null,
"_pending": true
}

[Trace - 03:45:40 AM] Received response 'codeLens/resolve - (1427)' in 1ms.
Result: {
"range": {
"start": {
"line": 0,
"character": 6
},
"end": {
"line": 0,
"character": 23
}
},
"command": {
"title": "0 references",
"command": "code-lens-references",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
1,
7
]
}
}

[Trace - 03:45:40 AM] Received response 'textDocument/codeAction - (1424)' in 77ms.
Result: [
{
"title": "Change coll to vector",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"vector"
]
}
},
{
"title": "Change coll to set",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"set"
]
}
},
{
"title": "Change coll to map",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"map"
]
}
},
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
}
]

[Trace - 03:45:40 AM] Received response 'textDocument/documentHighlight - (1425)' in 82ms.
Result: []

[Trace - 03:45:40 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///Users/va/tmp/lsp-par.clj",
"diagnostics": []
}

[Trace - 03:45:40 AM] Sending request 'textDocument/codeAction - (1428)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 2,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:40 AM] Sending request 'textDocument/documentHighlight - (1429)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 10
}
}

[Trace - 03:45:40 AM] Received response 'textDocument/codeAction - (1428)' in 3ms.
Result: [
{
"title": "Change coll to vector",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"vector"
]
}
},
{
"title": "Change coll to set",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"set"
]
}
},
{
"title": "Change coll to map",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"map"
]
}
},
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
}
]

[Trace - 03:45:40 AM] Received response 'textDocument/documentHighlight - (1429)' in 5ms.
Result: []

[Trace - 03:45:46 AM] Sending request 'textDocument/hover - (1430)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 10
}
}

[Trace - 03:45:46 AM] Sending request 'textDocument/codeAction - (1431)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 2,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:46 AM] Sending request 'textDocument/documentHighlight - (1432)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 10
}
}

[Trace - 03:45:46 AM] Received response 'textDocument/hover - (1430)' in 7ms.
Result: {
"range": {
"start": {
"line": 2,
"character": 11
},
"end": {
"line": 2,
"character": 13
}
},
"contents": {
"kind": "markdown",
"value": "clojure\nif\n\n\n----\n\n*/Users/va/tmp/lsp-par.clj*"
}
}

[Trace - 03:45:46 AM] Received response 'textDocument/codeAction - (1431)' in 9ms.
Result: [
{
"title": "Change coll to vector",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"vector"
]
}
},
{
"title": "Change coll to set",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"set"
]
}
},
{
"title": "Change coll to map",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"map"
]
}
},
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
}
]

[Trace - 03:45:46 AM] Received response 'textDocument/documentHighlight - (1432)' in 11ms.
Result: []

[Trace - 03:45:49 AM] Sending request 'textDocument/codeAction - (1433)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 2,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:49 AM] Sending request 'textDocument/documentHighlight - (1434)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 2,
"character": 10
}
}

[Trace - 03:45:49 AM] Received response 'textDocument/documentHighlight - (1434)' in 3ms.
Result: []

[Trace - 03:45:49 AM] Received response 'textDocument/codeAction - (1433)' in 5ms.
Result: [
{
"title": "Change coll to vector",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"vector"
]
}
},
{
"title": "Change coll to set",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"set"
]
}
},
{
"title": "Change coll to map",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"map"
]
}
},
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
}
]

[Trace - 03:45:50 AM] Sending request 'textDocument/codeAction - (1435)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 2,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:50 AM] Received response 'textDocument/codeAction - (1435)' in 3ms.
Result: [
{
"title": "Change coll to vector",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"vector"
]
}
},
{
"title": "Change coll to set",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"set"
]
}
},
{
"title": "Change coll to map",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"map"
]
}
},
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
null
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10
]
}
}
]

[Trace - 03:45:52 AM] Sending request 'workspace/executeCommand - (1436)'.
Params: {
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
10,
"new-function"
]
}

[Trace - 03:45:52 AM] Received request 'workspace/applyEdit - (6).
Params: {
"edit": {
"documentChanges": [
{
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj",
"version": 219
},
"edits": [
{
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 4,
"character": 14
}
},
"newText": "(new-function a)"
},
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"newText": "\n(defn- new-function [a]\n (if (> a 3)\n (+ a 2)\n a))\n"
}
]
}
]
}
}

[Trace - 03:45:52 AM] Sending response 'workspace/applyEdit - (6)'. Processing request took 1ms
Params: {
"jsonrpc": "2.0",
"id": 6,
"result": {
"applied": true
}
}

[Trace - 03:45:52 AM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj",
"version": 221
},
"contentChanges": [
{
"text": "\n(defn- new-function [a]\n (if (> a 3)\n (+ a 2)\n a))\n(defn test-parinfer-lsp []\n (let [a 2\n b (new-function a)]\n b))\n"
}
]
}

[Trace - 03:45:52 AM] Received response 'workspace/executeCommand - (1436)' in 5ms.
Result: {
"documentChanges": [
{
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj",
"version": 219
},
"edits": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"newText": "\n(defn- new-function [a]\n (if (> a 3)\n (+ a 2)\n a))\n"
},
{
"range": {
"start": {
"line": 2,
"character": 10
},
"end": {
"line": 4,
"character": 14
}
},
"newText": "(new-function a)"
}
]
}
]
}

[Trace - 03:45:52 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"uri": "file:///Users/va/tmp/lsp-par.clj",
"diagnostics": []
}

[Trace - 03:45:53 AM] Sending request 'textDocument/codeAction - (1437)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"range": {
"start": {
"line": 7,
"character": 10
},
"end": {
"line": 7,
"character": 10
}
},
"context": {
"diagnostics": []
}
}

[Trace - 03:45:53 AM] Sending request 'textDocument/documentHighlight - (1438)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 7,
"character": 10
}
}

[Trace - 03:45:53 AM] Sending request 'textDocument/hover - (1439)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
},
"position": {
"line": 7,
"character": 10
}
}

[Trace - 03:45:53 AM] Sending request 'textDocument/codeLens - (1440)'.
Params: {
"textDocument": {
"uri": "file:///Users/va/tmp/lsp-par.clj"
}
}

[Trace - 03:45:53 AM] Received response 'textDocument/codeAction - (1437)' in 10ms.
Result: [
{
"title": "Change coll to vector",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
"vector"
]
}
},
{
"title": "Change coll to set",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
"set"
]
}
},
{
"title": "Change coll to map",
"kind": "refactor",
"command": {
"title": "Change coll",
"command": "change-coll",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
"map"
]
}
},
{
"title": "Move to let",
"kind": "refactor.extract",
"command": {
"title": "Move to let",
"command": "move-to-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
"new-binding"
]
}
},
{
"title": "Cycle privacy",
"kind": "refactor.rewrite",
"command": {
"title": "Cycle privacy",
"command": "cycle-privacy",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Extract function",
"kind": "refactor.extract",
"command": {
"title": "Extract function",
"command": "extract-function",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
"new-function"
]
}
},
{
"title": "Extract to def",
"kind": "refactor.extract",
"command": {
"title": "Extract to def",
"command": "extract-to-def",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
null
]
}
},
{
"title": "Thread first all",
"kind": "refactor.rewrite",
"command": {
"title": "Thread first all",
"command": "thread-first-all",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Thread last all",
"kind": "refactor.rewrite",
"command": {
"title": "Thread last all",
"command": "thread-last-all",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Move another expression to get/get-in",
"kind": "refactor.rewrite",
"command": {
"title": "Move another expression to get/get-in",
"command": "get-in-more",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Move all expressions to get/get-in",
"kind": "refactor.rewrite",
"command": {
"title": "Move all expressions to get/get-in",
"command": "get-in-all",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Sort list",
"kind": "refactor.rewrite",
"command": {
"title": "Sort list",
"command": "sort-clauses",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Drag backward",
"kind": "refactor.rewrite",
"command": {
"title": "Drag backward",
"command": "drag-backward",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
},
{
"title": "Introduce let",
"kind": "refactor.extract",
"command": {
"title": "Introduce let",
"command": "introduce-let",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10,
"new-binding"
]
}
},
{
"title": "Clean namespace",
"kind": "source.organizeImports",
"command": {
"title": "Clean namespace",
"command": "clean-ns",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
7,
10
]
}
}
]

[Trace - 03:45:53 AM] Received response 'textDocument/documentHighlight - (1438)' in 12ms.
Result: []

[Trace - 03:45:53 AM] Received response 'textDocument/hover - (1439)' in 12ms.
Result: {
"range": {
"start": {
"line": 7,
"character": 11
},
"end": {
"line": 7,
"character": 23
}
},
"contents": {
"kind": "markdown",
"value": "clojure\nuser/new-function [a]\n\n\n----\n\n*/Users/va/tmp/lsp-par.clj*"
}
}

[Trace - 03:45:53 AM] Received response 'textDocument/codeLens - (1440)' in 12ms.
Result: [
{
"range": {
"start": {
"line": 1,
"character": 7
},
"end": {
"line": 1,
"character": 19
}
},
"data": [
"file:///Users/va/tmp/lsp-par.clj",
2,
8
]
},
{
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 23
}
},
"data": [
"file:///Users/va/tmp/lsp-par.clj",
6,
7
]
}
]

[Trace - 03:45:53 AM] Sending request 'codeLens/resolve - (1441)'.
Params: {
"range": {
"start": {
"line": 1,
"character": 7
},
"end": {
"line": 1,
"character": 19
}
},
"data": [
"file:///Users/va/tmp/lsp-par.clj",
2,
8
],
"_workspace": null,
"_pending": true
}

[Trace - 03:45:53 AM] Sending request 'codeLens/resolve - (1442)'.
Params: {
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 23
}
},
"data": [
"file:///Users/va/tmp/lsp-par.clj",
6,
7
],
"_workspace": null,
"_pending": true
}

[Trace - 03:45:53 AM] Received response 'codeLens/resolve - (1441)' in 3ms.
Result: {
"range": {
"start": {
"line": 1,
"character": 7
},
"end": {
"line": 1,
"character": 19
}
},
"command": {
"title": "1 reference",
"command": "code-lens-references",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
2,
8
]
}
}

[Trace - 03:45:53 AM] Received response 'codeLens/resolve - (1442)' in 3ms.
Result: {
"range": {
"start": {
"line": 5,
"character": 6
},
"end": {
"line": 5,
"character": 23
}
},
"command": {
"title": "0 references",
"command": "code-lens-references",
"arguments": [
"file:///Users/va/tmp/lsp-par.clj",
6,
7
]
}
}

User details (please complete the following information):

  • OS: MacOS
  • Editor: emacs
  • Version: 2023.10.30-21.15.51-nightly

@vlnn clojure-lsp has nothing related with the paren package you use in the client side, could you elaborate what is "messing with the code"? is that only related to wrong format (spaces)?

Yes it seems to be related to wrong format (extra spaces) — but it becomes structural problem, you may see how new function on first gif gets (if (> a 3 (+ a 2) a)) instead of (if (> a 3) (+ a 2) a). I'm not sure that it's just parinfer's problem, though. I guess some kind of configurable option restricting refactorings from formatting (letting the parinfer or similar things to do its stuff) could become a solution. Or maybe I'm just not aware of one?

when lsp-mode apply code actions it doesn't call any format IIRC, but you can confirm disabling rangeFormatting feature via lsp-enable-indentation (this disables range formatting not whole buffer formatting which is ok).

Also, you can check the Log - client <-> server to know if clojure-lsp is really returning something wrong which I doubt

I have lsp-enable-indentation set to nil. I'll reproduce and will add log-client <-> server to the issue.

log-client <-> server
[Trace - 01:58:40 PM] Sending request 'workspace/executeCommand - (4121)'.
Params: {
  "command": "extract-function",
  "arguments": [
    "file:///Users/va/tmp/test-lsp-parinfer.clj",
    2,
    10,
    "new-function"
  ]
}


[Trace - 01:58:40 PM] Received request 'workspace/applyEdit - (3).
Params: {
  "edit": {
    "documentChanges": [
      {
        "textDocument": {
          "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj",
          "version": 12
        },
        "edits": [
          {
            "range": {
              "start": {
                "line": 2,
                "character": 10
              },
              "end": {
                "line": 4,
                "character": 14
              }
            },
            "newText": "(new-function a)"
          },
          {
            "range": {
              "start": {
                "line": 0,
                "character": 0
              },
              "end": {
                "line": 0,
                "character": 0
              }
            },
            "newText": "\n(defn- new-function [a]\n  (if (> a 3)\n            (+ a 2)\n            a))\n"
          }
        ]
      }
    ]
  }
}


[Trace - 01:58:40 PM] Sending response 'workspace/applyEdit - (3)'. Processing request took 10ms
Params: {
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "applied": true
  }
}


[Trace - 01:58:40 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj",
    "version": 14
  },
  "contentChanges": [
    {
      "text": "\n(defn- new-function [a]\n  (if (> a 3)\n            (+ a 2)\n            a))\n(defn test-parinfer-lsp []\n  (let [a 2\n        b (new-function a)]\n    b))\n"
    }
  ]
}


[Trace - 01:58:40 PM] Received response 'workspace/executeCommand - (4121)' in 24ms.
Result: {
  "documentChanges": [
    {
      "textDocument": {
        "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj",
        "version": 12
      },
      "edits": [
        {
          "range": {
            "start": {
              "line": 0,
              "character": 0
            },
            "end": {
              "line": 0,
              "character": 0
            }
          },
          "newText": "\n(defn- new-function [a]\n  (if (> a 3)\n            (+ a 2)\n            a))\n"
        },
        {
          "range": {
            "start": {
              "line": 2,
              "character": 10
            },
            "end": {
              "line": 4,
              "character": 14
            }
          },
          "newText": "(new-function a)"
        }
      ]
    }
  ]
}


[Trace - 01:58:40 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 5,
          "character": 6
        },
        "end": {
          "line": 5,
          "character": 23
        }
      },
      "tags": [
        1
      ],
      "message": "Unused public var 'user/test-parinfer-lsp'",
      "code": "clojure-lsp/unused-public-var",
      "langs": [],
      "severity": 3,
      "source": "clojure-lsp"
    }
  ]
}


[Trace - 01:58:40 PM] Sending request 'textDocument/codeAction - (4122)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj"
  },
  "range": {
    "start": {
      "line": 7,
      "character": 10
    },
    "end": {
      "line": 7,
      "character": 10
    }
  },
  "context": {
    "diagnostics": []
  }
}


[Trace - 01:58:40 PM] Sending request 'textDocument/documentHighlight - (4123)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj"
  },
  "position": {
    "line": 7,
    "character": 10
  }
}


[Trace - 01:58:40 PM] Sending request 'textDocument/hover - (4124)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj"
  },
  "position": {
    "line": 7,
    "character": 10
  }
}


[Trace - 01:58:40 PM] Sending request 'textDocument/codeLens - (4125)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/va/tmp/test-lsp-parinfer.clj"
  }
}


[Trace - 01:58:40 PM] Received response 'textDocument/documentHighlight - (4123)' in 17ms.
Result: []


[Trace - 01:58:40 PM] Received response 'textDocument/codeAction - (4122)' in 19ms.
Result: [
  {
    "title": "Change coll to vector",
    "kind": "refactor",
    "command": {
      "title": "Change coll",
      "command": "change-coll",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        "vector"
      ]
    }
  },
  {
    "title": "Change coll to set",
    "kind": "refactor",
    "command": {
      "title": "Change coll",
      "command": "change-coll",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        "set"
      ]
    }
  },
  {
    "title": "Change coll to map",
    "kind": "refactor",
    "command": {
      "title": "Change coll",
      "command": "change-coll",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        "map"
      ]
    }
  },
  {
    "title": "Move to let",
    "kind": "refactor.extract",
    "command": {
      "title": "Move to let",
      "command": "move-to-let",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        "new-binding"
      ]
    }
  },
  {
    "title": "Cycle privacy",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Cycle privacy",
      "command": "cycle-privacy",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Extract function",
    "kind": "refactor.extract",
    "command": {
      "title": "Extract function",
      "command": "extract-function",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        "new-function"
      ]
    }
  },
  {
    "title": "Extract to def",
    "kind": "refactor.extract",
    "command": {
      "title": "Extract to def",
      "command": "extract-to-def",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        null
      ]
    }
  },
  {
    "title": "Thread first all",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Thread first all",
      "command": "thread-first-all",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Thread last all",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Thread last all",
      "command": "thread-last-all",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Move another expression to get/get-in",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Move another expression to get/get-in",
      "command": "get-in-more",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Move all expressions to get/get-in",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Move all expressions to get/get-in",
      "command": "get-in-all",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Sort list",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Sort list",
      "command": "sort-clauses",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Drag backward",
    "kind": "refactor.rewrite",
    "command": {
      "title": "Drag backward",
      "command": "drag-backward",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  },
  {
    "title": "Introduce let",
    "kind": "refactor.extract",
    "command": {
      "title": "Introduce let",
      "command": "introduce-let",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10,
        "new-binding"
      ]
    }
  },
  {
    "title": "Clean namespace",
    "kind": "source.organizeImports",
    "command": {
      "title": "Clean namespace",
      "command": "clean-ns",
      "arguments": [
        "file:///Users/va/tmp/test-lsp-parinfer.clj",
        7,
        10
      ]
    }
  }
]


[Trace - 01:58:40 PM] Received response 'textDocument/hover - (4124)' in 20ms.
Result: {
  "range": {
    "start": {
      "line": 7,
      "character": 11
    },
    "end": {
      "line": 7,
      "character": 23
    }
  },
  "contents": {
    "kind": "markdown",
    "value": "```clojure\nuser/new-function [a]\n```\n\n----\n\n*[/Users/va/tmp/test-lsp-parinfer.clj](file:///Users/va/tmp/test-lsp-parinfer.clj)*"
  }
}


[Trace - 01:58:40 PM] Received response 'textDocument/codeLens - (4125)' in 30ms.
Result: [
  {
    "range": {
      "start": {
        "line": 1,
        "character": 7
      },
      "end": {
        "line": 1,
        "character": 19
      }
    },
    "data": [
      "file:///Users/va/tmp/test-lsp-parinfer.clj",
      2,
      8
    ]
  },
  {
    "range": {
      "start": {
        "line": 5,
        "character": 6
      },
      "end": {
        "line": 5,
        "character": 23
      }
    },
    "data": [
      "file:///Users/va/tmp/test-lsp-parinfer.clj",
      6,
      7
    ]
  }
]


[Trace - 01:58:40 PM] Sending request 'codeLens/resolve - (4126)'.
Params: {
  "range": {
    "start": {
      "line": 1,
      "character": 7
    },
    "end": {
      "line": 1,
      "character": 19
    }
  },
  "data": [
    "file:///Users/va/tmp/test-lsp-parinfer.clj",
    2,
    8
  ],
  "_workspace": null,
  "_pending": true
}


[Trace - 01:58:40 PM] Sending request 'codeLens/resolve - (4127)'.
Params: {
  "range": {
    "start": {
      "line": 5,
      "character": 6
    },
    "end": {
      "line": 5,
      "character": 23
    }
  },
  "data": [
    "file:///Users/va/tmp/test-lsp-parinfer.clj",
    6,
    7
  ],
  "_workspace": null,
  "_pending": true
}


[Trace - 01:58:40 PM] Received response 'codeLens/resolve - (4126)' in 3ms.
Result: {
  "range": {
    "start": {
      "line": 1,
      "character": 7
    },
    "end": {
      "line": 1,
      "character": 19
    }
  },
  "command": {
    "title": "1 reference",
    "command": "code-lens-references",
    "arguments": [
      "file:///Users/va/tmp/test-lsp-parinfer.clj",
      2,
      8
    ]
  }
}


[Trace - 01:58:40 PM] Received response 'codeLens/resolve - (4127)' in 3ms.
Result: {
  "range": {
    "start": {
      "line": 5,
      "character": 6
    },
    "end": {
      "line": 5,
      "character": 23
    }
  },
  "command": {
    "title": "0 references",
    "command": "code-lens-references",
    "arguments": [
      "file:///Users/va/tmp/test-lsp-parinfer.clj",
      6,
      7
    ]
  }
}

In "newText": "\n(defn- new-function [a]\n (if (> a 3)\n (+ a 2)\n a))\n" I can see lots of extra spaces, which may create that kind of mess.

commented

I think the issue here is that Parinfer expects that any new text will be correctly indented and adjusts the parentheses to reflect that. Parinfer relies on the author to verify that the indentation is correct, and I don't know if clojure-lsp can make reasonably certain that a given block of code will be correctly indented when moving it from a nested position to a top-level position.

Maybe clojure-lsp can call into cljfmt? But then that relies on cljfmt knowing how to properly indent the code as well, which might not align with how Parinfer expects the code to be laid out (macros, etc).

Both smart and indent modes of parinfer depend on indentation (in the sense they auto-slurp or auto-barf the current sexp depending on how many extra-spaces prepend it). So my proposal is either to format the code correctly from the beginning (but what is correctly? this will add dependency to something external) or provide the option to skip all the extra spaces leaving bare minimum. This could be an option for dumb terminals as well as for terminals that are too clever.

commented

Maybe clojure-lsp could look at the column of the initial position, and then cut that amount of whitespace from each line, so that the resulting lines are in the same position relative to each other when moved to the new location.

Initial position of what? I dont think that extract function should depend on initial position of sexp being extracted, as well as initial position of defn sexp seems to be correct (i.e. without prepending spaces)

yeah, I don't think manually fixing the space in clojure-lsp will be a good idea, we could call format-range using cljfmt but there are some performance issues with that cljfmt feature