-
Notifications
You must be signed in to change notification settings - Fork 12
Magik Language Server
To install the Magik Language Server in VSCode you need the following:
- VSCode 1.59.0 or higher
- Java Runtime Environment/Java Development Kit 17 or higher
- The VSIX from the latest release on the releases page from magik-tools
- The sw_type_dumper from magik-tools
We expect that you have a VSCode and Java installation. Java is required for Smallworld itself. You should be able to use the same Java installation for the VSCode extension.
Download the latest magik-language-server VSIX. At the time of writing this is magik-language-server-0.10.1.vsix. In VSCode, in the Extensions sidebar (Ctrl + Shift + X), click on the three horizontal dots on the top and click on Install from VSIX.... This will let you choose the VSIX file to install. Select the magik-tools VSIX you have downloaded. The VSIX will now be installed.
Next, you either have to ensure the environment variable JAVA_HOME is set on your system, or configure the path to the JRE/JDK manually in VSCode. To do the latter, go to Settings in VSCode (Ctrl + ,). Then, search for setting magik.javaHome. Here, fill in the path to your Java installation.
Restart VSCode, and open the workspace/folder to your Magik software in VSCode. You should see a message Indexing workspace, indicating that your Magik sources are being indexed.
Note that you can see the logging of the Magik language server in the (lower) Output panel, in the Magik Lanuage Server channel (the dropdown). The language server logs what it is doing or report any errors there.
Although the extension now "knows" your Magik sources (i.e., it has indexed the sources to find exemplar definitions, methods, etc), it does not know about the Smallworld product(s) itself. Go to the VSCode Settings again (Ctrl + ,), and search for setting magik.productDirs. Here, add the paths to you Smallworld products. For example, adding paths to the core, sw_core, and design_manager products:
/opt/smallworld-5.3.4/core/opt/smallworld-5.3.4/core/sw_core/opt/smallworld-5.3.4/design_manager
The path to your Smallworld installation will most likely differ, update the paths accordingly.
A restart might be required to notify the Magik language server of these new products.
Finally, to be able to start a Smallworld session from VSCode, be sure to set the following settings:
-
magik.aliases: Path to your gis_aliases file. -
magik.environment: Path to your environment/enviroment.bat/environment.cmd file. -
magik.smallworldGis: Path to your Smallworld/core installation.
Although the extension can use the Smallworld products to gather information about exemplars/methods/etc, this information is most likely incomplete. To be able to use the extension to its fullest, it requires more information about the exemplars/methods/etc of the Smallworld session you'll be running.
For this, the product sw_type_dumper should be used. As the name states, it dumps all the information about the types in the session. Save the sw_type_dumper product somewhere, and from a swaf session, load the script sw_type_dumper/scripts/dump_types.magik. This will create a .jsonl file in your temp directory. Copy/move this file to somewhere where you can load and edit it later on.
Once this file is in place, you can point the extension to this using the setting magik.typing.typeDatabasePaths. In VSCode, go to Settings (Ctrl + ,), search for the setting magik.typing.typeDatabasePaths and add the path to the .jsonl file.
Now restart VSCode. The logging should indicate the .jsonl file is being read.
The extension is now installed, has access to your sources, and knows about the Smallworld product(s) you are ready to go.
When the extension is installed properly, you should be able to start a Smallworld session using the standard VSCode. Press (Ctrl + Shift + P) (or F1) to start a Command. Choose Tasks: Run task --> run_alias --> run_alias: swaf. Note, this will show the aliases from the aliases file you have configured using the magik.aliases setting.
After running this task, a session should be opened in a new Terminal, usually at the bottom of your screen.
If you come from emacs, regulair development will most likely be a bit different than you are accustomed to. For example, there is not method finder you are using directly. Instead, you can use auto-complete (inline in the editor), search for symbols (Ctrl + T), and use hover to see exemplar/method documentation.
As an example, create a new file called demo.magik. In this file, add the following snippet:
#% text_encoding = iso8859_1
_package user
_pragma(classify_level=basic,topic=demo)
def_slotted_exemplar(
:demo_exemplar,
{
{:slot_1, _unset},
{:slot_2, _unset}
})
$
_pragma(classify_level=basic,topic=demo)
_method demo_exemplar.demo_method(param1, _optional param2)
## Demo method.
## @param {sw:integer} param1 Example parameter 1.
## @param {sw:float} param2 Example parameter 2. Note that this can be optional.
write("This is the demo method. The first parameter has value: ", param1)
_endmethod
$
demo_exemplar.demo_method(10, 20)
$
Save the file and press (F4 - b) to transmit it to the running Smallworld session. From your terminal session - assuming it was started with a CLI - you should now see the message:
This is the demo method. The first parameter has value: 10
The file contents should be syntax highlighted, including parts of the method comment/doc.
After the write() statement, on a new line, in the method, add a new line and write:
param1.
This should open the auto-complete functionality of VSCode. If not, press (Ctrl + Space) while your cursor is placed after the . of the line. If all went well, you should see a list of methods param1 understands. The language server can infer this from the fact that the method doc contains the line describing the parameter param1 and its type.
If you auto-complete the methods for param2, it will understand that it can be either a sw:float or sw:unset, given that it is optional.
As described in the previous section, you can transmit a file to the current Smallworld session. Using (F4 - enter) you can transmit the current chunck where the cursor currently resides.
Note that - unlike emacs - functionality such as recalling commands is not supported in the Smallworld session CLI. Currently, the VSCode extension does not provide functionality like this. It might do so however in the future.
To work around this, it is adviced to start using unit tests using the munit product. The extension provides test-integration from VSCode, making it easy to run tests from VSCode. Be sure to transmit the any changes to the Smallworld session before running the tests however.
Another tip is to create a new magik file and write your command in there, separated by a single $-character on a line. Then transmit the commands using (F4 - enter). This way you can quickly go the previous commands and also have a (saved) history of your commands.
See the documents describing the Keyboard shortcuts for Windows and Linux.