elbywan / crystalline

A Language Server Protocol implementation for Crystal. 🔮
MIT License
424 stars 21 forks source link

LSP delete code before save buffer unexpectedly if there exists syntax error when use crystallize as LSP server. #41

Open zw963 opened 2 years ago

zw963 commented 2 years ago

Following is the log come from emacs lsp client, thank you.

[Trace - 09:36:53 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr",
    "version": 737
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 2,
          "character": 0
        },
        "end": {
          "line": 2,
          "character": 2
        }
      },
      "rangeLength": 2,
      "text": ""
    }
  ]
}

[Trace - 09:36:53 PM] Sending request 'textDocument/formatting - (1879)'.
Params: {
  "textDocument": {
    "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr"
  },
  "options": {
    "tabSize": 2,
    "insertSpaces": true
  }
}

[Trace - 09:36:53 PM] Received response 'textDocument/formatting - (1879)' in 0ms.
Result: [
  {
    "range": {
      "start": {
        "line": 0,
        "character": 0
      },
      "end": {
        "line": 18,
        "character": 0
      }
    },
    "newText": "class Home::IndexPage < AuthLayout\n  def content\n    div class: \"px-4 py-5 my-5 text-center\" do\n      h1 \"CoverApp\", class: \"display-5 fw-bold\"\n      div class: \"col-lg-6 mx-auto\" do\n        para \"It's your lucky day! See a fortune, and share the luck.\", class: \"lead mb-4\"\n        div class: \"d-grid gap-2 d-sm-flex justify-content-sm-center\" do\n          link \"Join\", to: SignUps::New, class: \"btn btn-primary btn-lg px4 me-sm-3\"\n          link \"Login\", to: SignIns::New, class: \"btn btn-outline-secondary btn-lg px-4\"\n        end\n      end\n    end\n    div class: \"container\" do\n      # we will use this later\n    end\n  end\nend\n"
  }
]

[Trace - 09:36:53 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr",
    "version": 738
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 0,
          "character": 0
        },
        "end": {
          "line": 18,
          "character": 0
        }
      },
      "rangeLength": 659,
      "text": "class Home::IndexPage < AuthLayout\n  def content\n    div class: \"px-4 py-5 my-5 text-center\" do\n      h1 \"CoverApp\", class: \"display-5 fw-bold\"\n      div class: \"col-lg-6 mx-auto\" do\n        para \"It's your lucky day! See a fortune, and share the luck.\", class: \"lead mb-4\"\n        div class: \"d-grid gap-2 d-sm-flex justify-content-sm-center\" do\n          link \"Join\", to: SignUps::New, class: \"btn btn-primary btn-lg px4 me-sm-3\"\n          link \"Login\", to: SignIns::New, class: \"btn btn-outline-secondary btn-lg px-4\"\n        end\n      end\n    end\n    div class: \"container\" do\n      # we will use this later\n    end\n  end\nend\n"
    }
  ]
}

[Trace - 09:36:53 PM] Sending notification 'textDocument/didSave'.
Params: {
  "textDocument": {
    "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr",
    "version": 738
  }
}

[Trace - 09:36:53 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr",
    "version": 739
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 16,
          "character": 3
        },
        "end": {
          "line": 16,
          "character": 3
        }
      },
      "rangeLength": 0,
      "text": "  "
    }
  ]
}

[Trace - 09:36:53 PM] Received request 'window/workDoneProgress/create - (0).
Params: {
  "token": "workspace/compile/284"
}

[Trace - 09:36:53 PM] Sending response 'window/workDoneProgress/create - (0)'. Processing request took 0ms
Params: {
  "jsonrpc": "2.0",
  "id": 0,
  "result": null
}

[Trace - 09:36:53 PM] Received notification '$/progress'.
Params: {
  "token": "workspace/compile/284",
  "value": {
    "title": "Building",
    "message": "/home/zw963/Magpie/clover/src/pages/home/index_page.cr",
    "kind": "begin"
  }
}

[Trace - 09:36:53 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 17,
          "character": 0
        },
        "end": {
          "line": 17,
          "character": 0
        }
      },
      "severity": 1,
      "source": "/home/zw963/Magpie/clover/src/pages/home/index_page.cr",
      "message": "expecting token 'EOF', not 'end'",
      "relatedInformation": []
    }
  ]
}

[Trace - 09:36:53 PM] Received notification '$/progress'.
Params: {
  "token": "workspace/compile/284",
  "value": {
    "message": "Completed with errors.",
    "kind": "end"
  }
}

[Trace - 09:36:54 PM] Sending request 'textDocument/documentSymbol - (1880)'.
Params: {
  "textDocument": {
    "uri": "file:///home/zw963/Magpie/clover/src/pages/home/index_page.cr"
  }
}

[Trace - 09:36:54 PM] Received response 'textDocument/documentSymbol - (1880)' in 382ms.
Result: [
  {
    "name": "Home::IndexPage",
    "kind": 5,
    "range": {
      "start": {
        "line": 0,
        "character": 0
      },
      "end": {
        "line": 16,
        "character": 2
      }
    },
    "selectionRange": {
      "start": {
        "line": 0,
        "character": 0
      },
      "end": {
        "line": 16,
        "character": 2
      }
    },
    "children": [
      {
        "name": "content",
        "detail": "public content ",
        "kind": 12,
        "range": {
          "start": {
            "line": 1,
            "character": 2
          },
          "end": {
            "line": 15,
            "character": 4
          }
        },
        "selectionRange": {
          "start": {
            "line": 1,
            "character": 2
          },
          "end": {
            "line": 15,
            "character": 4
          }
        },
        "children": []
      }
    ]
  }
]
zw963 commented 2 years ago

BTW, in some cases(possible syntax error too), LSP will always revert my changes whens i save changes.

peterhoeg commented 1 year ago

I have noticed this too and have had to disable crystalline as a consequence. I haven't been able to find a pattern/reliable way to reproduce it.

watzon commented 11 months ago

This is most certainly one of the most annoying issues I've faced recently

elbywan commented 11 months ago

I am not facing this issue on mac with vscode (or very rarely).

I am also not planning to work on crystalline anytime soon, so PRs are welcome if anyone is up for it.

watzon commented 11 months ago

The issue @zw963 and I are having with it undoing the changes you make on save seem to be related to the formatter. Turning off formatting on save would probably work as a temporary solution (if I can figure that one out in neovim).

zw963 commented 11 months ago

I am not using LSP with Crystal for a long time ...