-
Notifications
You must be signed in to change notification settings - Fork 34
Language Server Details
As a language server, you can simply implement the features provided by the datapack-language-server on any other modern editors. Here are all the technical details you may concern.
Check out this page to see if there's already an LSP client integration available.
You can also launch the language server as a command and connect to it. For that, install the datapack-language-server npm module:
npm i -g datapack-language-server
Start the language server with the datapack-language-server
command.
The language server supports request on documents of language id mcfunction
and json
.
- There's no specification for
mcfunction
files. The language server tries it best to imitate how Minecraft: Java Edition behaves. All inconsistencies are considerd as bugs of either the language server or Minecraft, and should be reported at either Issues or Mojira. - Only JSON files under specific directories can be handled by the language server. A complete list of glob patterns that match supported JSON files can be found here.
The language server protocol consists of a number of capabilities. Here's a list of capabilities that are implemented by the language server.
- ✅ Call hierarchy provider
- ✅ Color provider
- ✅ Completion provider
- ✅ Definition provider
- ✅ Declaration provider
- ✅ Document formatting provider
- ✅ Document highlight provider
- ✅ Document link provider
- ✅ Execute command provider
- ✅
workspace/executeCommand
⚠️ Available commands
- ✅
- ✅ Folding range provider
- ✅ Hover provider
- ✅ Reference provider
- ✅ Rename provider
- ✅ Selection range provider
- ✅ Semantic tokens provider
- ✅ Signature help provider
- ✅ Text document sync
- ✅
textDocument/didOpen
- ✅
textDocument/didChange
: Incremental update. - ❌
textDocument/willSave
- ❌
textDocument/willSaveWaitUntil
- ❌
textDocument/didSave
- ✅
textDocument/didClose
- ✅
- ✅ Watch files
- ✅
workspace/didChangeWatchedFiles
⚠️ Here is a list of files that should be watched; glob patterns are relative from the root of workspace folders.-
**/data/**/*.{json,mcfunction,nbt}
: Should trigger create event, change event, and delete event. -
**/{data,pack.mcmeta}
: Should trigger create event and delete event. When events for these entries are received, the language server will start re-detecting data packs. The client should not send change events for these entries, otherwise it would make the language server laggy.
-
- ✅
- ✅ Workspace
- ✅ Multi-root workspace.
- ✅
workspace/didChangeWorkspaceFolders
The language server expects the client to only send messages for documents of language ID mcfunction
, certain JSON files, and pack.mcmeta
:
{
"documentSelector": [
{ "language": "mcfunction" },
{ "scheme": "file", "pattern": "**/pack.mcmeta" },
{ "scheme": "file", "pattern": "**/data/*/*/**/*.json" }
]
}
However, if your client doesn't support the pattern
selector, you may send all requests of language ID json
to the language server. Hopefully the server can handle them correctly for you.
{
"documentSelector": [
{ "language": "mcfunction" },
{ "language": "json" }
]
}
The client must not throw exceptions when it receives the following messages from the server:
Also, the client may somehow provide supports for stuff marked as
The client may provide support for the following custom messages that are sent from the server to the client:
-
spgoding/datapack/checkServerVersion
notification: check if the version where the language server was started last time is older than current version. If so, the client may show an information box indicating the user.-
currentVersion
: A string. The current version of the language server. -
title
: A string. If the client decides to show an information box, this title may be used. -
action
: A string. If the client decides to show an information box, this action may be used as the title of the action button. -
url
: A string. If the client decides to show an information box, clicking the action button may open this URL.
-
-
globalStoragePath
: (Optional) A string. Should be a path to a folder where the language server can store global cache files, like the block definitions, registries, and nbtdocs for Minecraft. The folder doesn't need to exist, but the client must ensure that the server has the permission to create, read, and write to that folder. If not specified, the language server will use the platform-specific appdata-path for thespgoding.datapack-language-server
APP name. -
storagePath
: (Optional) A string. Should be a path to a folder where the language server can store workspace-specific cache file. The folder doesn't need to exist, but the client must ensure that the server has the permission to create, read, and write to that folder. If not specified, the cache file won't be saved and the language server need to generate it every time it starts. -
localeCode
: (Optional) A string, defaults toen
. Should be a locale code that the server could use when thedatapack.env.language
setting is set toDefault
. A list of acceptable locale codes can be fond here. -
customCapabilities
: (Optional) An object which indicates the server what custom messages does the client support.-
checkServerVersion
: (Optional) If the client supports the customspgoding/datapack/checkServerVersion
notification.
-
If the client indicates that it supports the workspace/configuration
request, the response for it must follow the Config
interface in src/types/Config.ts
.
Version | Description |
---|---|
? | ? |
3.0.0 | Supported textDocument/declaration request on server.Both storagePath and globalStoragePath are no longer required in the initialization options.Added localeCode and customCapabilities initialization options.The prefix for custom messages is changed from datapackLanguageServer/ to spgoding/datapack/ . |
3.0.1 | Files with the .nbt extension should also be watched on client. |