kenkangxgwe / lsp-wl

A Wolfram Language Server
MIT License
212 stars 22 forks source link

LSP server crashes when using Emacs #67

Closed dalanicolai closed 2 years ago

dalanicolai commented 2 years ago

I am trying to use the LSP server (again) with Emacs, however, the connection with the server is lost soon after connecting establishing it.

I have no knowledge about the LSP protocol, but it looks like it has to do with Emacs sending:

[Trace - 07:16:32 PM] Sending notification '$/cancelRequest'.
Params: {
  "id": 26
}

here is the stderr from the server:

[INFO  2022-06-11T19:16:28] Initializing Wolfram Language Server
[INFO  2022-06-11T19:16:32] Language server is connecting the client through
socket.
[INFO  2022-06-11T19:16:32] Server listening from port 46325...
[INFO  2022-06-11T19:16:32] Debugger listening at port Null[debuggerPort]

DataType`TypeCheck::mispat: 
   The host specification  1  is wrong because  42 
     doesn't match the pattern of "server" in 
    WolframLanguageServer`Server`Private`DebugSession.

DataType`TypeCheck::mispat: 
   The host specification  1  is wrong because  42 
     doesn't match the pattern of "server" in 
    WolframLanguageServer`Server`Private`DebugSession.

DataType`TypeCheck::mispat: 
   The host specification  1  is wrong because  42 
     doesn't match the pattern of "server" in 
    WolframLanguageServer`Server`Private`DebugSession.

General::stop: Further output of DataType`TypeCheck::mispat
     will be suppressed during this calculation.
[ERROR 2022-06-11T19:16:32] Which[Socket operation failed:  29 ,
WolframLanguageServer`Server`Private`handleDapMessageList[WolframLanguageServer`
Server`Private`ReadMessages[WolframLanguageServer`Server`Private`DebugSession[<|
initialized -> False, server -> The host specification  1  is wrong because 
42 , client -> NotAvailable|>][client]],
WolframLanguageServer`Server`Private`WorkState[<|pendingServerRequests -> <||>,
config -> <|configFileConfig ->
WolframLanguageServer`Server`Private`loadConfig[]|>, client ->
SocketObject[14388f61-928e-4925-8e14-99bbbdfd53eb], clientCapabilities ->
<|workspace -> <|workspaceEdit -> <|documentChanges -> True, resourceOperations
-> {create, rename, delete}|>, applyEdit -> True, symbol -> <|symbolKind ->
<|valueSet -> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26}|>|>, executeCommand -> <|dynamicRegistration ->
False|>, didChangeWatchedFiles -> <|dynamicRegistration -> True|>,
workspaceFolders -> True, configuration -> True, codeLens -> <|refreshSupport ->
True|>, fileOperations -> <|didCreate -> False, willCreate -> False, didRename
-> True, willRename -> True, didDelete -> False, willDelete -> False|>|>,
textDocument -> <|declaration -> <|linkSupport -> True|>, definition ->
<|linkSupport -> True|>, implementation -> <|linkSupport -> True|>,
typeDefinition -> <|linkSupport -> True|>, synchronization -> <|willSave ->
[INFO  2022-06-11T19:16:32] Closing socket connection...
[ERROR 2022-06-11T19:16:32] Server stopped abnormally.
[ERROR 2022-06-11T19:16:32] Which[Socket operation failed:  29 ,
WolframLanguageServer`Server`Private`handleDapMessageList[WolframLanguageServer`
Server`Private`ReadMessages[WolframLanguageServer`Server`Private`DebugSession[<|
initialized -> False, server -> The host specification  1  is wrong because 
42 , client -> NotAvailable|>][client]],
WolframLanguageServer`Server`Private`WorkState[<|pendingServerRequests -> <||>,
config -> <|configFileConfig ->
WolframLanguageServer`Server`Private`loadConfig[]|>, client ->
SocketObject[14388f61-928e-4925-8e14-99bbbdfd53eb], clientCapabilities ->
<|workspace -> <|workspaceEdit -> <|documentChanges -> True, resourceOperations
-> {create, rename, delete}|>, applyEdit -> True, symbol -> <|symbolKind ->
<|valueSet -> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26}|>|>, executeCommand -> <|dynamicRegistration ->
False|>, didChangeWatchedFiles -> <|dynamicRegistration -> True|>,
workspaceFolders -> True, configuration -> True, codeLens -> <|refreshSupport ->
True|>, fileOperations -> <|didCreate -> False, willCreate -> False, didRename
-> True, willRename -> True, didDelete -> False, willDelete -> False|>|>,
textDocument -> <|declaration -> <|linkSupport -> True|>, definition ->
<|linkSupport -> True|>, implementation -> <|linkSupport -> True|>,
typeDefinition -> <|linkSupport -> True|>, synchronization -> <|willSave ->

Process lsp-wl stderr finished

I have found the following info in the LSP docs: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#notificationMessage.

So might this happen because the server is not ignoring this request?

Would be great if this issue could get fixed.

Anyway... thanks a lot for creating and sharing this great package!

kenkangxgwe commented 2 years ago

Hi Daniel, 71a2fe4313f8d95f27bad4ecd0e136e13c05234a is supposed to fix the issue, but I haven't tested it yet. Thanks for your feedback, could you try it again?

dalanicolai commented 2 years ago

Great! Thanks, that does fix this issue. However, a little later but still very soon after connecting, the server crashes again. This time, the 'last parts of the communication' look as follows (I guess only the last block is relevant):

[Trace - 02:24:08 PM] Sending request 'textDocument/codeLens - (29)'.
Params: {
  "textDocument": {
    "uri": "file:///home/dalanicolai/test/wolfram/test.wls"
  }
}

[Trace - 02:24:08 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///home/dalanicolai/test/wolfram/test.wls",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 2,
          "character": 4
        },
        "end": {
          "line": 2,
          "character": 5
        }
      },
      "severity": 1,
      "source": "Wolfram",
      "message": "[UnterminatedGroup] Missing closer.",
      "tags": [],
      "data": []
    }
  ]
}

[Trace - 02:24:08 PM] Received response 'textDocument/codeLens - (29)' in 151ms.
Result: []

[Trace - 02:24:17 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///home/dalanicolai/test/wolfram/test.wls",
    "version": 16
  },
  "contentChanges": [
    {
      "text": "#!/usr/bin/env wolframscript\n\nPlot[Cos\n"
    }
  ]
}

And now the stderr gives:

[INFO  2022-06-12T14:22:57] Initializing Wolfram Language Server
[INFO  2022-06-12T14:23:04] Language server is connecting the client through
socket.
[INFO  2022-06-12T14:23:04] Server listening from port 43931...

WolframLanguageServer`Server`Private`NestedLookup::NotAssoc: 
   Null is not an association and cannot lookup for key debuggerPort.
[INFO  2022-06-12T14:23:04] The server is initialized in 9.787618 s.
[INFO  2022-06-12T14:23:04] {InitialCheck, Quantity[0.198635, "Seconds"]}
[INFO  2022-06-12T14:23:10] {JustContinue, Quantity[0.205169, "Seconds"]}
[INFO  2022-06-12T14:23:12] {JustContinue, Quantity[0.179712, "Seconds"]}
[INFO  2022-06-12T14:23:13] {JustContinue, Quantity[0.361634, "Seconds"]}
[INFO  2022-06-12T14:23:14] {ClientProcessCheck, Quantity[0.06097276681518515,
"Seconds"]}

DataType`TypeCheck::mispat: 
   Null doesn't match the pattern of "clientProcessId" in 
    WolframLanguageServer`Server`Private`WorkState.

DataType`TypeCheck::mispat: 
   Null doesn't match the pattern of "clientProcessId" in 
    WolframLanguageServer`Server`Private`WorkState.
[INFO  2022-06-12T14:23:14] Client process is no longer alive. Exiting...
[INFO  2022-06-12T14:23:14] Closing socket connection...
[INFO  2022-06-12T14:23:14] Server stopped normally.

Process lsp-wl stderr finished
[INFO  2022-06-12T14:24:00] Initializing Wolfram Language Server
[INFO  2022-06-12T14:24:07] Language server is connecting the client through
socket.
[INFO  2022-06-12T14:24:07] Server listening from port 40033...

WolframLanguageServer`Server`Private`NestedLookup::NotAssoc: 
   Null is not an association and cannot lookup for key debuggerPort.
[INFO  2022-06-12T14:24:08] The server is initialized in 10.496336 s.
[INFO  2022-06-12T14:24:08] {InitialCheck, Quantity[0.266789, "Seconds"]}
[INFO  2022-06-12T14:24:17] {JustContinue, Quantity[0.1054, "Seconds"]}
[INFO  2022-06-12T14:24:18] {ClientProcessCheck, Quantity[0.027395146209716614,
"Seconds"]}

DataType`TypeCheck::mispat: 
   Null doesn't match the pattern of "clientProcessId" in 
    WolframLanguageServer`Server`Private`WorkState.

DataType`TypeCheck::mispat: 
   Null doesn't match the pattern of "clientProcessId" in 
    WolframLanguageServer`Server`Private`WorkState.
[INFO  2022-06-12T14:24:18] Client process is no longer alive. Exiting...
[INFO  2022-06-12T14:24:18] Closing socket connection...
[INFO  2022-06-12T14:24:18] Server stopped normally.

Process lsp-wl stderr finished

Would be great if this could be fixed also.

kenkangxgwe commented 2 years ago

Aha, seems lsp-mode or eglot (which one do you use?) doesn't send the clientProcessId. Should be fixed in https://github.com/kenkangxgwe/lsp-wl/commit/b6470221304b14bb77579e5852ccb1c88485e115, while I still haven't got a linux emacs environment to test this conveniently.

dalanicolai commented 2 years ago

Works great! The server seems to be 'stable' again now.

One small, not so important comment; when I add a shebang line at the beginning of the buffer, then the first line of the code below it gets very much indented, while it should not get indented at all. I am not sure if this is due to LSP (which is what I am using via Spacemacs), or due to lsp-wl. But this is only a small 'cosmetic' issue, which does not bother me at all. Just wanted to inform you about it.

Again, thanks a lot for your help and your work! :+1:

kenkangxgwe commented 2 years ago

Is that due to the wolfram-mode emacs package itself? Currently, the server doesn't do any formatting.

dalanicolai commented 2 years ago

Ah, you're right... it is! I had not really used wolfram-mode yet, I just installed it and then focused on configuring LSP first.