This repository contains an extension for Visual Studio Code that uses LSP to communicate with the Mo|E server. It is currently only used for testing purposes.
Since version 0.0.1, the extension is now available as VSIX file, which can be installed as follows:
- Download the VSIX file from the latest release.
- Open the command palette with CTRL+SHIFT+P.
- Select the command "Extensions: Install from VSIX...".
- Select the file you just downloaded.
- You should now see several commands starting with "Mo|E:" in the command palette.
Currently, the extension does not start the server itself, so you have to refer to the README of MopeSWTP-SS21/MopeSWTP to do this. We chose this setup, because it allows connecting to a server that is attached to a debugger in an IDE.
Once you have installed the extension and started the server, you can connect to the server using the following commands:
- Use the command
Mo|E: connect
(via CTRL+SHIFT+P) to connect to the Mo|E server. You have to enter the server port that is shown on the console when you start the server. The host is currently locked to the local host. - Use the command
Mo|E: loadModel
(or any of the otherMo|E:
commands besidesconnect
anddisconnect
) to send aworkspace/executeCommand
to the server with the commandloadModel
and the argument specified by the prompt. - Use the command
Mo|E: disconnect
to properly shut the server down.
In order to set up the project for development, you have to do the following:
- Follow the setup instructions of either MopeSWTP-SS21/MopeSWTP or MopeSWTP-SS21/LSP4J-test-CS.
- Install VS Code and node.js through your favorite package manager.
- Clone this repository.
- Run
npm install
in your working copy of this repository in order to install the node modules that this extension depends upon. - Create a VS Code project that has the working copy of this repository as the only workspace folder (this is needed, because the repo contains a
.vscode
folder with settings that are required to test the extension). You can do this with the following steps:- Open a new window in VS code.
- Select File -> Add folder to workspace ...
- Add the folder containing this repository and save the workspace using File -> Save Workspace As ...
Once this is all done, you can press F5 in VS Code to open a new VS Code instance that has the extension installed and is connected to a debug session in the development window.
In order to package the project to a VSIX file, you need to install the node package vsce
and then run the following command:
vsce package
The most important files of this (and any) VS code extension are package.json
, which contains the definition of available commands for VS code, and src/extension.ts
, which defines how the client reacts to these commands.
For the most part, the messages that the client sends are predefined by the class LanguageServer
in the node module vscode-languageclient/node
. You can find the source code of vscode-languageclient on GitHub, and it will be downloaded to the folder node_modules
when you follow the above instructions to install this extension.
While the LanguageClient
class does honor the ServerCapabilities
sent by the server, there seem to be some capabilities that are not allowed to be null/undefined, such as textDocumentSync
.
This leads to errors in the client code of the type cannot something something of undefined
.
There seem to be other instances, where such missing or wrong capabilities do not result in an error, but in the client simply asking the server to shut down.
This is the case when a new workspace folder is added while the Mo|E client is active.
I am not entirely sure if this is really connected to ServerCapabilities
or to some other error.
Currently, the server uses command names for the workspace/executeCommand
calls that start with an uppercase letter.
This will stop to work in future versions of MopeLSP.
If you start seeing errors about rejected promises, the command names will have to be changed in package.json
and src/extension.ts
.
I used the following resources (among others) to build this client: