Language server and VSCode extension that provides rich language support for LPC (Lars Pensjö C) - an object-oriented programming language derived from C and developed originally by Lars Pensjö to facilitate MUD building on LPMuds.
Currently supports LDMud and FluffOS.
Install from the VS Code Marketplace: https://marketplace.visualstudio.com/items?itemName=jlchmura.lpc
- Code Completion / IntelliSense - Results appear for symbols as you type, including lfuns.
- Diagnostics
- Hover info
- Signature help, with type info
- Code navigation - Jump to or peek at a symbol's declaration
- Go to definitions (f12)
- Go to implementations (ctrl/cmd+f12)
- Go to symbol (cltr/cmd+o)
- Code outline
- Code navigation
- Include / sefun support
LPC Language Services uses JSDoc-style comments to provide additional context during hover and signature help.
Example:
/**
* Attempts to run a command
* @param {string} cmd - The command to run
* @returns 1 if successful, otherwise 0
*/
int doCommand(string cmd) {
return 1;
}
See CHANGELOG.md.
The VS Code LPC Language Services extension does not use your MUD driver to compile code. As such, several configuration options are available to help the language server understand the structure of your mudlib.
Please note: After creating (or moving) your lpc-config
file, you will need to restart VS Code.
For an example mudlib, pre-configured to work with LPC Language Services, see this slightly modified version of the LP 2.4.5 mudlib. LPC Language Services can parse and validate this entire lib without errors.
Language services can be customized by creating an lpc-config.json
file in the root folder of your workspace. The available options are as follows:
Setting | Description |
---|---|
type |
Driver type. Valid options are ldmud or fluffos . |
version |
The driver version string, i.e. "3.6.7" |
Most file locations and path settings in the lpc-config file are set relative to the mudlib root regardless of where your lpc-config file is located. The one exception to this is the mudlibDir
setting, which is always relative to the workspace root.
By default, LPC Language Services will use the location of your lpc-config.json
file to determine the root folder of your mudlib. If no config file is found, the VS Code workspace root is used.
If you want to place the lpc-config.json file in a different location, then you must set the mudlibDir
setting.
This optional setting specifies which local folder the root of your mudlib will map to. The path is relative to the location of your lpc-config file.
For example, let's say your project is structured thus:
MyProj
|- settings
| |- lpc-config.json
|- lib
| |- std
| | |- simul_efun.c
| |- rooms
| | |- entrance.c
| |- admin
Then your mudlibDir
setting should be set to ../lib
Setting | Description |
---|---|
master |
The location of your master object. Defaults to "/obj/master.c" |
simul_efun |
The location of your simul_efun file. Defaults to "/obj/simul_efun.c" |
init_files |
An array of init files. Defaults to ["/room/init_files"] |
global_include |
When provided, will add this file as an #include to each file. |
player |
The location of your player file. Defaults to "/obj/player.c" |
An array of folders that are searched when including files via the #include
directive.
Defaults to ["/sys", "/obj", "/room"]
An array of glob patterns of directories and files that are excluded from language services. Excluded files will not report errors unless specifically opened in VS Code.
Since your code is not being evaluating in the mud driver, you may need to simulate one or more defines that are normally provided by the driver's compiler. Values are an array of key value pairs. Example:
"defines": [
{ "__HOST_NAME__": "\"localhost\"" },
{ "TLS_PORT": "5555" }
]
In the example above, __HOST_NAME__
will be defined as the string value "localhost"
. TLS_PORT
on the other hand, will be defined as an int value 5555
.
The severity level of several diagnostics can be controlled through this configuration option. When a LPC language services reports a diagnostic, the code is printed at the end the message and enclosed in lpc()
, i.e. lpc(functionNotFound)
.
For example, to turn off the functionNotFound
error completely:
"diagnostics": {
"functionNotFound": "none"
}
Valid severity levels are:
error
warning
info
hint
none
All semantic diagnostics can be disabled by setting the config to "off"
. Syntax errors will always be reported. Example:
"diagnostics": "off"
Language services is a work in progress. Some major areas that have yet to be implemented are:
- LWObjects
- Named object validation
- Coroutines
- Complete FluffOS specific syntax parsing
Syntax highlighting is based on the LPC Language VS Code extension by Gwenn Reece, adjusted for LDMud.
Original inspiration for the structure of this project came from Mike Lischke's ANTLR4 grammar syntax support. This language server would not have been possible without Mike's work on the ANTLR4-ng package.
Many thanks for the fellow MUD admins, wizards, and LPC aficionados in the LPC Discord for their inspiration.
Feedback welcome. You can open an issue in the lpc-language-server repo. Otherwise, you can usually find me on the LPC Discord or idling on Infinity Mud.