kenkangxgwe / lsp-wl

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

Running lsp-wl 0.3.0 with Wolfram Engine 12.3.1 fails on MacOS #63

Closed The3DWizard closed 3 years ago

The3DWizard commented 3 years ago

I am on MacOS 11.4 running Wolfram Engine 12.3.1. I try to run the wolfram language server via

wolframscript -f ./init.wls

which unfortunately does not work and gives me the following output

[INFO  2021-07-21T16:07:29] Initializing Wolfram Language Server

StringJoin::string: 
   String expected at position 1 in 
    (Keys::usage)<>
                                                                       .
      Keys[typename] gives a list of the keys field_i in type typename.

MessageName::messg: 
   Keys::usage cannot be set to 
    (Keys::usage)<>
                                                                       . It
      Keys[typename] gives a list of the keys field_i in type typename.
     must be set to a string.
[INFO  2021-07-21T16:07:32] Language server is connecting the client through
socket.
[INFO  2021-07-21T16:07:32] Server listening from port 6536...

DataType`TypeCheck::mispat: 
   Failed socket operation: Connection refused doesn't match the pattern of 
    "client" in WolframLanguageServer`Server`Private`WorkState.
[ERROR 2021-07-21T16:07:32] Which[Undefined message SocketReadyQ::notsocket with
arguments {Failed socket operation: Connection refused},
WolframLanguageServer`Server`Private`handleMessageList[WolframLanguageServer`Ser
ver`Private`ReadMessages[Failed socket operation: Connection refused],
WolframLanguageServer`Server`Private`WorkState[<|initialized -> False,
openedDocs -> <||>, debugSession ->
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>], scheduledTasks -> {}, caches ->
<|textDocument/signatureHelp -> <||>, textDocument/documentSymbol -> <||>,
textDocument/documentColor -> <||>, textDocument/codeLens -> <||>,
textDocument/publishDiagnostics -> <||>|>, pendingServerRequests -> <||>, config
-> <|configFileConfig -> WolframLanguageServer`Server`Private`loadConfig[]|>,
client -> Failed socket operation: Connection refused|>]],
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][server] =!= Null &&
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][client] === Null &&
Length[WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False,
server -> Null, client -> Null|>][server][ConnectedClients]] > 0, {Continue,
DataType`ReplaceKey[WolframLanguageServer`Server`Private`WorkState[<|initialized
[INFO  2021-07-21T16:07:32] Closing socket connection...

DataType`TypeCheck::mispat: 
   Failed socket operation: Connection refused doesn't match the pattern of 
    "client" in WolframLanguageServer`Server`Private`WorkState.
[ERROR 2021-07-21T16:07:32] Server stopped abnormally.
[ERROR 2021-07-21T16:07:32] Which[Undefined message SocketReadyQ::notsocket with
arguments {Failed socket operation: Connection refused},
WolframLanguageServer`Server`Private`handleMessageList[WolframLanguageServer`Ser
ver`Private`ReadMessages[Failed socket operation: Connection refused],
WolframLanguageServer`Server`Private`WorkState[<|initialized -> False,
openedDocs -> <||>, debugSession ->
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>], scheduledTasks -> {}, caches ->
<|textDocument/signatureHelp -> <||>, textDocument/documentSymbol -> <||>,
textDocument/documentColor -> <||>, textDocument/codeLens -> <||>,
textDocument/publishDiagnostics -> <||>|>, pendingServerRequests -> <||>, config
-> <|configFileConfig -> WolframLanguageServer`Server`Private`loadConfig[]|>,
client -> Failed socket operation: Connection refused|>]],
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][server] =!= Null &&
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][client] === Null &&
Length[WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False,
server -> Null, client -> Null|>][server][ConnectedClients]] > 0, {Continue,
DataType`ReplaceKey[WolframLanguageServer`Server`Private`WorkState[<|initialized

Any help is appreciated. I currently do not know where the error exactly comes from.

kenkangxgwe commented 3 years ago

Hi, Do you have a client (an editor like VSCode) running for the server to connect to? If not, try to set up a client, see the instructions.

The3DWizard commented 3 years ago

Hi, I do have VSCode with your extension installed. Unfortunately when opening a wolframscript file in VSCode and your extension would activate I get the same output in VSCode as I posted above. I just read about the tcp issue with ZeroMQLink on the page you linked above and followed your instructions for Wolfram Engine 12.3, but this did not fix the problem either.

I was a bit confused though on which the right path to the wolfram executable would be as there is no wolfram executable in the Wolfram Engine. For now I took "/Applications/Wolfram Engine.app/Contents/MacOS/WolframKernel", although instructions state one should not use WolframKernel. Should this option be set to a different path when using Wolfram Engine?

kenkangxgwe commented 3 years ago

Oh, just realized you are using 0.3.0, could you try develop branch, instead?

When you open WolframKernel, does it give you a GUI or just a console? Since on Windows, the WolframKernel.exe will shows up a white window for the wolfram REPL and it won't work for the language server. So as long as you can run the wolfram -script init.wls in the terminal, it is ok to use that executable.

The3DWizard commented 3 years ago

Starting WolframKernel gives me the Wolfram console where I can execute Wolfram Language code.

When using the develop branch (running wolframscript -f ./init.wls or using VSCode) I get slightly different console output compared to using the master branch, but the core error seams to be the same:

[INFO  2021-07-22T11:22:57] Initializing Wolfram Language Server

Syntax::com: Warning: comma encountered with no adjacent expression. The
     expression will be treated as Null.  (line 932 of
     "WolframLanguageServer`Server`").
[INFO  2021-07-22T11:23:03] Language server is connecting the client through
socket.
[INFO  2021-07-22T11:23:03] Server listening from port 6536...

DataType`TypeCheck::mispat: 
   Failed socket operation: Connection refused doesn't match the pattern of 
    "client" in WolframLanguageServer`Server`Private`WorkState.
[ERROR 2021-07-22T11:23:03] Which[Undefined message SocketReadyQ::notsocket with
arguments {Failed socket operation: Connection refused},
WolframLanguageServer`Server`Private`handleMessageList[WolframLanguageServer`Ser
ver`Private`ReadMessages[Failed socket operation: Connection refused],
WolframLanguageServer`Server`Private`WorkState[<|initialized -> False,
openedDocs -> <||>, debugSession ->
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>], scheduledTasks -> {}, caches ->
<|textDocument/signatureHelp -> <||>, textDocument/documentSymbol -> <||>,
textDocument/documentLink -> <||>, textDocument/documentColor -> <||>,
textDocument/codeLens -> <||>, textDocument/publishDiagnostics -> <||>|>,
pendingServerRequests -> <||>, config -> <|configFileConfig ->
WolframLanguageServer`Server`Private`loadConfig[]|>, client -> Failed socket
operation: Connection refused|>]],
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][server] =!= Null &&
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][client] === Null &&
Length[WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False,
server -> Null, client -> Null|>][server][ConnectedClients]] > 0, {Continue,
[INFO  2021-07-22T11:23:03] Closing socket connection...

DataType`TypeCheck::mispat: 
   Failed socket operation: Connection refused doesn't match the pattern of 
    "client" in WolframLanguageServer`Server`Private`WorkState.
[ERROR 2021-07-22T11:23:03] Server stopped abnormally.
[ERROR 2021-07-22T11:23:03] Which[Undefined message SocketReadyQ::notsocket with
arguments {Failed socket operation: Connection refused},
WolframLanguageServer`Server`Private`handleMessageList[WolframLanguageServer`Ser
ver`Private`ReadMessages[Failed socket operation: Connection refused],
WolframLanguageServer`Server`Private`WorkState[<|initialized -> False,
openedDocs -> <||>, debugSession ->
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>], scheduledTasks -> {}, caches ->
<|textDocument/signatureHelp -> <||>, textDocument/documentSymbol -> <||>,
textDocument/documentLink -> <||>, textDocument/documentColor -> <||>,
textDocument/codeLens -> <||>, textDocument/publishDiagnostics -> <||>|>,
pendingServerRequests -> <||>, config -> <|configFileConfig ->
WolframLanguageServer`Server`Private`loadConfig[]|>, client -> Failed socket
operation: Connection refused|>]],
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][server] =!= Null &&
WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False, server
-> Null, client -> Null|>][client] === Null &&
Length[WolframLanguageServer`Server`Private`DebugSession[<|initialized -> False,
server -> Null, client -> Null|>][server][ConnectedClients]] > 0, {Continue,
kenkangxgwe commented 3 years ago

In Mathematica, if you run FindFile["ZeroMQLink`"], what would you get? Is it 1.1.22?

The3DWizard commented 3 years ago

Funny enough the version I got using FindFile["ZeroMQLink`"] was 1.2.2, even though I did the forced install and disable as mentioned in the lsp-wl wiki. But uninstalling via PacletUninstall["ZeroMQLink"] and then installing version 1.1.22 seems to work at least such that version 1.1.22 is the installed version.

Unfortunately this is still not working. When running wolframscript -f ./init.wls again I now get:

[INFO  2021-07-22T14:35:32] Initializing Wolfram Language Server

Syntax::com: Warning: comma encountered with no adjacent expression. The
     expression will be treated as Null.  (line 932 of
     "WolframLanguageServer`Server`").
[INFO  2021-07-22T14:35:37] Language server is connecting the client through
socket.

SocketConnect::zmqexception: 
   A ZeroMQLink exception was thrown - Connection refused (code 61)
[ERROR 2021-07-22T14:35:37] Cannot connect to client via socket.
kenkangxgwe commented 3 years ago

When you run wolframscript -f ./init.wls, the default behavior is that it will connect to the default port (6536) for socket connection. If there's no established socket server there, it will thrown the "Connection refused" exception. You need to have a editor hosting this socket so that it can connect successfully. So in your case, please just retry it on VSCode. Thanks!

The3DWizard commented 3 years ago

Hi, thanks for the help! Using the develop branch, running VSCode and taking care that ZeroMQLink actually is at version 1.1.22 the server seems to be running now. Just to let you know: The debug branch contains a tiny comma error in Server.wl at line 930, which needed to be fixed. I think I should not push such a tiny code change :) .

One more thing though: I have the latest Wolfram Engine 12.3.1 installed but hover and completion documentation do not work for me (the wiki currently says this problem should be fixed with 12.3.1). Any advice on that? Maybe this has to do with me using WolframKernel as executable?

Thanks for your support.

kenkangxgwe commented 3 years ago

Glad that it worked for you.

For the hover and completion, please take a look at wiki I just updated it.

The3DWizard commented 3 years ago

Indeed the Usage.m file is missing with the current installation of Wolfram Engine 12.3.1 on MacOS. For people reading this, the default installation directory on MacOS is actually /Applications/Wolfram Engine.app/Contents/Resources/Wolfram Player.app/Contents when using the Wolfram Engine. To obtain your installation directory you can just call $InstallationDirectory from the Wolfram console.

kenkangxgwe commented 3 years ago

Thanks for your info. I will close this.

kenkangxgwe commented 2 years ago

Wolfram solved this upstream bug recently. Please manually upgrade the ZeroMQLink paclet

PacletInstall["ZeroMQLink"]

ref: https://github.com/kenkangxgwe/lsp-wl/wiki#working-with-mathematica-123130