LPC Language ServicesLanguage 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 Attention v1.0 Users
If you are updating from the 1.0.x version, please see config-changes.md for required changes to your Features
LPCDoc CommentsLPC Language Services uses JSDoc-style comments to provide additional context during hover and signature help. Example:
Similar to typed languages like TypeScript, the type annotations are optional but can provide valuable context to the language server. For more, see Type Annotations, below. If you love this extension, you couldChangelogSee CHANGELOG.md. Semantic AnalysisSemantic analysis (sometimes refered to as the type checker) will perform many useful checks on your code, but you must opt-in to this feature.
To enable semantic code analysis, set the diagnostics options to Disable Checks on Per-File BasisSemantic checks can be disabled for a single file by placing a nocheck directive at the top of the file:
this_object()By default, the type checker will assume
Ignoring a single line -
|
Setting | Description |
---|---|
type |
Driver type. Valid options are ldmud or fluffos . |
version |
The driver version string, i.e. "3.6.7" |
Include - include
Specifies an array of filenames or patterns to include in the program. These filenames are resolved relative to the directory containing the lpc-config.json file.
Default: **/*
Example:
{
"include": ["lib/**/*"]
}
Exclude - exclude
Specifies an array of filenames or patterns that should be skipped when resolving include.
Important: exclude only changes which files are included as a result of the include setting. A file specified by exclude can still become part of your codebase due to a statement in your code such as an include, a types inclusion, clone_object, etc.
It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include setting finds.
Lib File Locations - libFiles
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" |
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" |
Lib Root Dir - rootDir
If your config file is located in a folder other than your lib's root directory, use this setting to specify the location of the root folder.
Include Search Dirs - libInclude
An array of folders that are searched when including files via the #include
directive.
Defaults to ["/sys", "/obj", "/room"]
Predefined Macros - defines
Since your code is not being evaluated 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
.
Diagnostics - diagnostics
Semantic analysis is always run, but diagnostics are only reported if you opt in to receiving them. (Syntax errors will always be reported.) Example:
"diagnostics": "on"
Compiler Options - compilerOptions
Compiler options are specified under the compilerOptions
object:
{
"compilerOptions": {
...
}
}
Strict Object Type Checking - strictObjectTypes
Defaults to false
unless strict
is on.
When enabled, strick object checking will report an error when an untyped object is being assigned to a typed object. For example:
/**
* @param {"std/player.c"} p
*/
void foo(object p) {
tell_object(p, "hi");
}
void bar(object p) {
tell_object(p, "hi");
}
object player;
foo(p); /* p will report an error when strictObjectTypes is true, because it is an untyped object. */
bar(p); /* this call is ok because both objects are untyped */
Grammar ToDo's
Language services is a work in progress. Some major areas that have yet to be implemented are:
- LWObjects
- Named object validation
- Coroutines
Credits
Syntax highlighting is based on the LPC Language VS Code extension by Gwenn Reece, adjusted for LDMud.
The guts of this language server is a heavily modified version of the TypeScript compiler/server. None of it would be possible without the work of the many brilliant people working on that team.
Many thanks for the fellow MUD admins, wizards, and LPC aficionados in the LPC Discord for their inspiration.
Contact / Feature Requests / Bugs
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.