Skip to content

Commit

Permalink
🔖 Alpha release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkangxgwe committed Jul 23, 2019
2 parents 43ecb49 + 60272bb commit 7adcf02
Show file tree
Hide file tree
Showing 21 changed files with 4,078 additions and 741 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2019-07-23 🏖️

### Added

- Document structure is provided in DocumentSymbol. (Thanks to Brenton's `AST` package)
- Hovering for `MessageName` and numeral literals.
- Completion for both aliases and long names of the unicode characters (with leader key <kbd>\\</kbd>).
- Auto check for upgrades and dependencies.

### Changed

- Using Brenton's `Lint` package to diagnose the document.
- Documentations now have a better format with code block (in hovers and completions).
- Diagnostics are published schedulely.

### Fixed

- High CPU usage when reading message via sockets under Linux.
(Reported by [@kc9jud](https://github.com/kc9jud) and solution suggested by
[@megatron0000](https://github.com/megatron0000))

### Known Issues

- Some of the documentations was not transcribed correctly into Markdown format, see issues.

## [0.1.2] - 2019-05-15

### Added
Expand Down
105 changes: 69 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ with addition power from the editor.
We have provided the client-side code for VS Code [here](https://github.com/kenkangxgwe/vscode-lsp-wl), which is based on some slight
modifications of [Microsoft's LSP
example](https://github.com/Microsoft/vscode-extension-samples/tree/master/lsp-sample).
If you are using other tools supporting LSP, some slight modifications to the
If you are using other editors supporting LSP, some adaptation to the
client would certainly work too.

## Installation
Expand All @@ -42,13 +42,19 @@ client would certainly work too.
name="ref1"></a>[<sup>1</sup>](#footnote1)) or [Wolfram
Engine](https://www.wolfram.com/engine/) (12.0 or higher).

1. Use git to clone this repository.
1. Use git to clone this repository.
``` sh
git clone https://github.com/kenkangxgwe/lsp-wl.git
```

``` sh
git clone https://github.com/kenkangxgwe/lsp-wl.git
```
2. Install the dependent paclets with the correct versions from the Wolfram kernel / Mathematica.
(_This will cost some time for the first time_) :
``` mathematica
PacletInstall[{"AST", "0.11"}, "Site" -> "http://pacletserver.wolfram.com", "UpdateSites" -> True]
PacletInstall[{"Lint", "0.11"}, "Site" -> "http://pacletserver.wolfram.com", "UpdateSites" -> True]
```

2. Install the client. Currently, we provide the VS Code extension on [Visual
3. Install the client. Currently, we provide the VS Code extension on [Visual
Studio Marketplace: Wolfram Language Server](https://marketplace.visualstudio.com/items?itemName=lsp-wl.lsp-wl-client)

## Run the Server
Expand Down Expand Up @@ -88,28 +94,52 @@ This is a good way to see the results from the unit tests.
## Features
- *Hover:* Provide definitions for Wolfram functions and system variables, such
as `String` and `$Path`.
- **DocumentSymbol:** You may typeset your package in the same way that
Mathematica FrontEnd handles it: a cell begins with two lines of comments,
where the first line specifies the style of the cell and the second line names it.
So you may get the outline structure of the file.
``` mathematica
(* ::Title:: *)
(*Title of the file*)
(* ::Section:: *)
(*Section 1*)
```
![documentSymbol](images/documentSymbol.png)
![hover](images/hover.png)
- **Hover:** Provide documentations for functions and variables from the
``System` `` context, such as `String` and `$Path`, the `MessageName` and
the special numerical literals with `^^` or `*^`.
- *Completion:* The completion is triggered by the client automatically.
Currently, Wolfram functions and system variables would be displayed.
![hover](images/hover.png)
- *Completion Resolve:* Further information would be provided for the items in
the list.
- **Completion:** The completion is shown by the client automatically.
Functions and system variables from the ``System` `` context that matches the
input would be displayed. To enter an unicode character, you may use the
leader key <kbd>\\</kbd> followed by the alias just like <kbd>esc</kbd> in
Wolfram FrondEnd. E.g., `<esc>a` in the FrontEnd is input as `\a` in the
editor and the server will show you the available completions.
![completion](images/completion.png)
![completion-unicode](images/completion_alias.png)
- *Diagnostics:* Syntax error would be underlined. However, the specific syntax
error is not supported at the moment.
- **Completion Resolve:** Further information (such as documentation) would be
provided for the items in the list.
![diagnostics](images/diagnostics.png)

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](https://marketplace.visualstudio.com/items?itemName=flipphillips.wolfram-language).
![completion](images/completion.png)
- **Diagnostics:** Syntax error would be underlined. This feature is powered by
Brenton's `AST` and `Lint` paclets, thank you
[@bostick](https://github.com/bostick).
![diagnostics](images/diagnostics.png)
This is an early release, so more features are on the way. Notice that,
syntax highlight will not be provided as long as it is excluded in the LSP,
but I believe there are plenty of good Mathematica highlighter available for
your editor.
Here is a full list of [LSP features](https://microsoft.github.io/language-server-protocol/specification).
Expand All @@ -124,12 +154,13 @@ Here is a full list of [LSP features](https://microsoft.github.io/language-serve
2. We implemented an stateless server in ``WolframLanguageServer`Server` `` that
will parse and handle the messages.
3. ``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.
3. ``DataType` `` is a simple type system now extracted as a independent
package in the [Matypetica](https://github.com/kenkangxgwe/Matypetica)
library that supports pattern test on every field of a class. The operations
on the objects are designed to be immutable.
4. ``WolframLanguageServer`Test`* `` stores the unit tests for some of
the packages.
the functions.
### Todo list
Expand All @@ -139,16 +170,19 @@ It will be nice if you want to make a contribution to the following topic.
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.
* It will be helpful to implement a stdio channel, ~so that the Mathematica
earlier than 11.2 will also be supported,~ but it is really hard to expose
the `stdin` channel. Hope this will be dicussed in future release of Wolfram
kernel.
* 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.
create a pull request to add the clients in README.md once your client is
released.
* Thanks to Brenton's `AST` and `Lint` paclets, we are able to parse the code
and extract useful information. If you have an idea about how to use these
fantastic syntax tools to help the language server add more features, please
send us issues or pull requests.
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.
Expand All @@ -167,5 +201,4 @@ thanks in advance :smile:.
## Footnotes
<a name="footnote1"> </a> **[1]** `SocketListen[]` is used for server-client
communication, which is introduced since 11.2. We plan to support stdio for
better compatibility. [^](#ref1)
communication, which is introduced since 11.2. [^](#ref1)
51 changes: 51 additions & 0 deletions WolframLanguageServer/Archives.wl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(* ::Package:: *)
(*Archives*)

(* Wolfram Language Server Archived Functions *)
(* Author: kenkangxgwe <kenkangxgwe_at_gmail.com>,
huxianglong <hxianglong_at_gmail.com>
*)


BeginPackage["WolframLanguageServer`Archives`"]
ClearAll[Evaluate[Context[] <> "*"]]


Begin["`Private`"]
ClearAll[Evaluate[Context[] <> "*"]]


(* ::Section:: *)
(*GenSvgImg*)


Options[GenSvgImg] := {
"Theme" -> "dark",
"TempDir" -> $TemporaryDirectory
}


GenSvgImg[token_String, width_Integer, o:OptionsPattern[]] := Module[
{
tempImgPath, background, theme, tempDir
},

{theme, tempImgPath} = OptionValue[GenSvgImg, {o}, {"Theme", "TempDir"}];
background = If[theme === "light", Black, White];
tempImgPath = FileNameJoin[{tempDir, CreateUUID[] <> ".svg"}];
(* Export[tempImgPath, Style[#, background]& @* (#::usage&) @ Symbol[token]]; *)
Export[tempImgPath,
Style[
Pane[StringReplace[#, StartOfLine -> "\[FilledSmallCircle] "], .85*width, Alignment -> Left], FontSize -> 13, background
]& @ ToExpression[token <> "::usage"]
];
(* "![" <> "test" <> "](" <> tempImgPath <> ")" <> "\n" <> "```" <> StringRepeat[StringJoin[CharacterRange["a", "z"]], 4] <> "```" *)
"![" <> "test" <> "](" <> tempImgPath <> ")" <> "\n\n" <> "```typescript" <> StringRepeat[StringRepeat["\t", 50] <> "\n", 20] <> "```" <> "\n\n"
(* "![" <> ToString[(#::usage&) @ Symbol[token]] <> "](" <> tempImgPath <> ")" *)
]


End[]


EndPackage[]
Loading

0 comments on commit 7adcf02

Please sign in to comment.