Giter Club home page Giter Club logo

vscode-lsp-wl's Introduction

Visual Studio Code Client for Wolfram Language Server

License: MIT Version Visual Studio Marketplace Downloads

Table of Contents

Please be advised to git pull the lastest minor version 0.3.x. There are some breaking changes you want to know more in the server's README.

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.

This is the client-side code for VS Code, which is based on some slight modifications of Microsoft's LSP example. However, you still need to manually install the server .

Installation

  1. Wolfram Mathematica (11.2 or higher1) or Wolfram Engine (12.0 or higher).

  2. Download the server from its repository.

    git clone https://github.com/kenkangxgwe/lsp-wl.git
    
  3. Install the dependent paclets with the correct versions (currently 1.0 or later) from the Wolfram kernel / Mathematica. (This will cost some time for the first time) :

    PacletInstall["CodeParser"]
    PacletInstall["CodeInspector"]
  4. Install the client extenstion from Visual Studio Marketplace: Wolfram Language Server.

Client Settings

Language support

Once you have installed the extension, a few settings have to be done manually in the client side to make things work.

After the extension is launched, go to Preference -> Settings -> User Settings -> Extensions -> Wolfram Language Server, and configure the following options:

  • Port : The client communicates with the server through port. Feel free to use any port that is not occupied by other processes.

  • WLServer Path : The path to the server repository.

  • Wolfram Path : The path of the Wolfram executable. (NOT Mathematica or WolframKernel)
    For Windows users, the default path is C:\Program Files\Wolfram Research\Mathematica\11.*\wolfram.exe.
    For MaxOS users, the default path is /Applications/Mathematica.app/Contents/MacOS/wolfram.
    For Linux users, the default path is /usr/local/Wolfram/Mathematica/11.*/wolfram.

  • Diagnostics: Mitigated and Diagnostics: Suppressed : To adjust how some of the diagnostics are reported, see Diagnostics: Override Reporting Rules.

Restart VS Code to take effect.

Debugger support

To enable debugger, you need to add the configuration to the project that you are working on by clicking on Run -> Add configuration... in the menu. In the opened .vscode/launch.json file, select Wolfram Debug Adapter: Attach in the completion list.

debugger-configuration

Or add the following configuration directly to the launch.json.

"configurations": [
    {
        "type": "dap-wl",
        "request": "attach",
        "name": "Create a new Wolfram Kernel",
        "stopOnEntry": true
    }
]

To start the debugger, jump to the Run tab in the sidebar and select the configuration name just added and clicked the Start Debugging button.

Language Server Features

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.

(* ::Title:: *)
(*Title of the file*)

(* ::Section:: *)
(*Section 1*)

documentSymbol

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 *^.

hover

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 \ followed by the alias just like esc 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-unicode

Completion Resolve: Further information (such as documentation) would be provided for the items in the list.

completion

Diagnostics

Syntax error would be underlined. This feature is powered by CodeParser and CodeInspector paclets, thank you @bostick.

diagnostics

Override Reporting Rules

To adjust how some of the diagnostics are reported, adding their corresponding tags in the settings.json. There are two kinds of ways to override the reporting rule:

  • Mitigated : The tags under this category will not be considered as an issue, and shown in the lowest severity, i.e. "hint". E.g. In VSCode, this will result in a elipesis under the reporting position but will not listed under the Problems tab.
  • Suppressed : The tags under this category will be completely ignored and not reported.

An example of configuration in settings.json is shown below:

{
    // ...
    "WolframLanguageServer.Diagnostics.mitigated": [
        "ExperimentalSymbol",
        "UnusedParameter",
        "UnusedVariable",
    ],
    "WolframLanguageServer.Diagnostics.suppressed": [
        "DifferentLine",
        "SuspiciousSessionSymbol",
    ],
    // ...
}

Definition / References / Document Highlight

It is now able to look up the definition and references of a local variable in a scope such as Module or pattern rules.

references

Code Action

Code action is now able to,

  • Open the documentation of system symbols in Mathematica (Not available for Wolfram Engine).
    documentation

  • Evaluate the selected code if debugger is running. See Evaluate.

Document Color / Color Presentation

Both Named Colors and Color Models with constant parameters are able to show and modify.
(Experimental, may have performance issues.)

documentColor

This is under development, 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 there are already some good enough extensions written by Flip Phillips and by shigma.

Debug Adapter Features

Evaluate

Code evaluation can be run from the code action of the selection or code lens below each section title. The results are usually shown in the debug console on the editor side.

evaluate-code-action

Expressions can also be directly input from the debug console.

evaluate-debug-console

Variables

After evaluation, the symbol values can be retrieved from the editor. This includes the own values of variables and the down/up/sub values of functions defined.

variables

The behavior of the variables mimics the workspace in MATLAB, so all the symbols defined in the debug console as well as evaluated from the file will be recorded. This also includes contexts other than Global` . The editor can also watch on a specific expression after each evaluation if applicable.

Footnotes

[1] SocketListen[] is used for server-client communication, which is introduced since 11.2. ^

vscode-lsp-wl's People

Contributors

kenkangxgwe avatar wangboyu-langya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-lsp-wl's Issues

Depreciation warnings

Output from WLS is giving the following as a result of loading both required paclets:

Lint`LintString::deprecated: 
   

   Lint paclet is deprecated.

   Lint functionality has moved to the CodeInspector paclet.

   Use the CodeInspector paclet.

   PacletInstall["CodeInspector"]


AST`ConcreteParseString::deprecated: 
   

   AST paclet is deprecated.

   AST functionality has moved to the CodeParser paclet.

   Use the CodeParser paclet.

   PacletInstall["CodeParser"]

安装的一些问题

作者你好,我按照说明文档安装完后,服务似乎没有生效(既没有浮窗帮助,也没有自动补全),请问我是哪里配置有问题呢?

按照说明文档对服务器的配置的参数如下
image

运行后查看服务器的信息如下,

[INFO  2023-03-18T18:37:17] Initializing Wolfram Language Server

Syntax::sntufn: Unknown unicode longname Application.
[INFO  2023-03-18T18:37:18] Language server is connecting the client through
socket.

FromCharacterCode::notunicode: 
   A character code, which should be a non-negative integer less than 65536,
     is expected at position 1 in 
    {-45, -55, -45, -38, -60, -65, -79, -22, -68, -58, -53, -29, -69, -6, 
     -69, -3, -68, -85, -66, -36, -66, -8, -93, -84, -50, -34, -73, -88, -63, 
     -84, -67, -45, -95, -93, 13, 10}.

SocketConnect::zmqexception: 
   A ZeroMQLink exception was thrown - 
    FromCharacterCode[{-45, -55, -45, -38, -60, -65, -79, -22, -68, -58, -53, 
      -29, -69, -6, -69, -3, -68, -85, -66, -36, -66, <<5>>, -73, -88, -63, 
      -84, -67, -45, -95, -93, 13, 10}, UTF-8] (code 10061)
[ERROR 2023-03-18T18:37:20] Cannot connect to client via socket.

lsp-wl not work in vscode now...

"AST-0.11" and "Lint-0.11" are not available on the official server now, I think the 0.11 version has been deleted, the latest version 0.13 were provided. Unfortunately, they can't be used in vscode.

Error: Request textDocument/documentSymbol failed

Hi there @kenkangxgwe !

First of all, thanks a lot for developing this great extension! I'm trying to transition from IntelliJ to VS Code and your extension is the most complete out there for Wolfram Language.

Now the issue is the following. While i'm writing Wolfram Language code i continuously get the output window reporting the error:

[Error - 6:19:32 PM] Request textDocument/documentSymbol failed.
  Message: There is a more recent duplicate request.
  Code: -32801 

I'm pretty sure the paths in settings are correctly configured. What could be the problem?

Thanks in advance.

"Connection to server is erroring. Shutting down server." after update to Mathematica 12.3

I updated Mathematica to the new 12.3 release. I installed the paclets as instructed:

PacletInstall["CodeParser"]
PacletInstall["CodeInspector"]

I then entered the correct path to wolfram.exe in the extension settings:

C:\Program Files\Wolfram Research\Mathematica\12.3\wolfram.exe

However, when I start VS Code and open a Mathematica source file, I get the following in the Output pane:

[Error - 9:45:47 AM] Connection to server is erroring. Shutting down server.
[INFO  2021-05-21T09:45:47] Server listening from port 6536...

Is the extension incompatible with Mathematica 12.3? If so, could it be updated? I find this extension extremely useful, but don't want to downgrade Mathematica just so I can use it...

Any help would be appreciated.

Questions about the install

My biggest concern is that by installing this extension, I am going to jeopardize my working version of Mathematica.

  1. Will the paclets interfere with Mathematica 13.0? Will I still be able to use Mathematica on the same machine as the VS Code extension?

  2. Do I need to specify a full path specification for the PacletInstall commands?

  3. I recommend that you enumerate the steps in the HowToBuild.md file and include a reference to this file in the installation instructions.

  4. What is the purpose of the two trailing dots at the end of the command:

    cmake -DMATHEMATICA_INSTALL_DIR = "C:/Program Files/Wolfram Research/Mathematica/13.0" ..
    

    in the HowToBuild.md file?

  5. After installation of the extension in VS Code, how do you activate the extension?

  6. How would you use this extension in VS Code? What file types are recognized (.m, .nb, .wl,)?

Folding closed sections by default

I found that the MMA FE generates tokens like (* ::Section::Closed:: *) if you export a package file from a notebook and there are folded sections; when the package file is opened with MMA FE, these cells will be folded by default; if you open them and save them, the Closed:: tag is removed.

I imagine we may be able to reproduce this for VS Code. I don't think we should modify the tag at all, which can leads to unnecessary trace in commits. We may only fold the section by default the first time the file is opened in the editor.

This can reflect the author's intention if he want viewers to focus on certain passages at first and don't worry about details in the folded sections. It may be convenient for template script files, where the author may demand non-experienced users to manually paste some URL/file path in a line or two.

Actually I don't really think this is a often occurring situation 😂 so I am just putting forward this for completeness.

[Minor problem] `dap-wl` is not recognised (30 Jan 2021)

Trying the new dap-wl debugger feature, I followed the instruction in the Readme to find that the run button is not working on my platform.
A more careful inspection reveals that the following exception is thrown:

dap-wl-is-down-screenshot

dap-wl-down-screenshot

However lacking experience with VS-Code extension development I cannot pin down why the debugger is not added correctly.
I would like to see whether this may be reproduced by other users, as well as brief instructions on how to further investigate the registering process of the "dap-wl" debugger type.

Platform informations

Since I do not clearly know what sort of information may be related, I offer the following:

OS: Windows 10 Professional 1909
VS Code: vscode-version
lsp-wl.lsp-wl-client: 1.8.0

Update 2021-01-30: After an OS reboot, the debugger is now actually working, and it seems that the only problem is the exception thrown, without any other implication.

"White" problems are not shown in the problem panel

Hello,

I love this extension, and I use it all the time to write my Mathematica package in VS Code. There is one issue that bugs me, however. While errors, warnings, and infos appear in the problems panel:

image

It seems that the Wolfram engine also generates additional, sometimes useful, problems that are marked with a dotted white underline, provide information upon hovering over them with the mouse, but do not appear in the problems panel:

image

Since these "white" problems cannot be found in the problems panel, there seems to be no way to find all of them, other than manually going over the entire source code and visually looking for the dotted white underline, which is obviously not feasible.

Would it be possible to add an option to display these problems in the problems panel?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.