by kenkangxgwe and hxianglong
Table of Contents
Wolfram Language Server (WLServer) is an implementation of the Microsoft's Language Server Protocol (LSP) for Wolfram Language. This server is implemented in Wolfram Language itself.
Our current goal is to provide the experience as good as the Mathematica FrontEnd with addition power from the editor.
We have provided the client-side code for VS Code here, which is based on some slight modifications of Microsoft's LSP example. If you are using other tools supporting LSP, some slight modifications to the client would certainly work too.
-
Wolfram Mathematica (11.2 or higher1) or Wolfram Engine (12.0 or higher).
-
Use git to clone this repository.
git clone https://github.com/kenkangxgwe/lsp-wl.git
- Install the client. Currently, we provide the VS Code extension on Visual Studio Marketplace: Wolfram Language Server
Clients can start the server by running the init.wls
file from Wolfram
Mathematica executables
wolfram -script /path/to/lsp-wl/init.wls [args]
# or
wolframscript -f /path/to/lsp-wl/init.wls [args]
The posible arguments for the server are
--help, -h
to print help information.--socket=port
to assign the port to which the server will connect. (Default:6536
)--tcp-server=port
to assign the port at which the server will start. (Default:6536
)--pipe=pipename
to specify the pipe name for the server to connect to.--log=level, -l level
to specify the logging level of the server. (Levels:error
,warn
,info
,debug
. Default:info
)--test, -t
to run the unit test for the server.
If you want to run the server from Mathematica you can use the following code.
initfile = "/path/to/lsp-wl/init.wls";
args = {};
Block[{$ScriptCommandLine = Prepend[args, initfile], Quit = Function[{}, Throw[Null]]},
Catch[<< (initfile)]
];
This is a good way to see the results from the unit tests.
- Hover: Provide definitions for Wolfram functions and system variables, such
as
String
and$Path
.
-
Completion: The completion is triggered by the client automatically. Currently, Wolfram functions and system variables would be displayed.
-
Completion Resolve: Further information would be provided for the items in the list.
- Diagnostics: Syntax error would be underlined. However, the specific syntax error is not supported at the moment.
This is an early release, so more features are on the way. Syntax highlight is NOT supported according to the design of LSP, but there are already some good enough extensions like Wolfram Language.
Here is a full list of LSP features.
-
The files are located according to its context name. The
init.wls
is the entry script that parses the commandline arguments, loads packages and starts the server. -
We implemented an stateless server in
WolframLanguageServer`Server`
that will parse and handle the messages. -
WolframLanguageServer`DataType`
is a simple type system that supports pattern test on every field of a class. The operations on the objects are designed to be immutable. -
WolframLanguageServer`Test`*
stores the unit tests for some of the packages.
It will be nice if you want to make a contribution to the following topic.
-
Our server-client communication only supports Socket with TCP protocol. We tried to use ZMQ_Stream protocol and
SocketListen[]
to enable concurrency, but it fails to send responses back to the client. -
It will be helpful to implement a stdio channel, so that the Mathematica earlier than 11.2 will also be supported.
-
More editor clients are needed. You can feel free to open a repository and create a pull request to add the clients in README.md once your client is released.
-
A scanner/parser might be needed to extract tokens for future usage. We have investigated serveral implementations in other languages, but we are still prefer a wolfram language scanner/parser written in wolfram language and can be easily integrated into this project.
If you want to help us with this project, feel free to fork and create a pull request. Do not forget to add unit tests if possible.
If you really like this project, please donate to us! $5 (or equivalently ¥35). A cup of coffee ☕ would certainly brighten our day! Your donation would be the motivation for us to move forward, thanks in advance 😄.
- Paypal: [email protected]
- Alipay (With QRCode): 13916018006
[1] SocketListen[]
is used for server-client
communication, which is introduced since 11.2. We plan to support stdio for
better compatibility. ^