-
Notifications
You must be signed in to change notification settings - Fork 33
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-
datapack.regenerateCache
: regenerate the cache file.
-
- ✅
- ✅ Folding range provider
- ✅ Hover provider
- ✅ Reference provider
- ✅ Rename provider
- ✅ Selection range provider
- ✅ Semantic tokens provider
- ✅
textDocument/semanticTokens
- ✅
textDocument/semanticTokens/edits
- ✅
textDocument/semanticTokens/range
⚠️ Semantic legend: #308
- ✅
- ✅ 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}
: 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 requests and notifications for documents of language id mcfunction
and certain other files:
{
documentSelector: [
{ language: 'mcfunction' },
{ scheme: 'file', pattern: '**/pack.mcmeta' },
{ scheme: 'file', pattern: '**/data/*/{advancements,dimension,dimension_type,functions,loot_tables,predicates,recipes,structures,tags,worldgen}/**/*.json' }
]
}
The client must not throw errors when it receives the following notifications/requests:
-
datapackLanguageServer/checkVersion
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 should be used. -
action
: A string. If the client decides to show an information box, this action should be used as the title of the action. -
url
: A string. If the client decides to show an information box, clicking the action should open this url.
-
window/showMessage
window/showMessageRequest
Also, the client should somehow provide supports for stuff marked as
-
globalStoragePath
: (Required) A string. Should be a path to a folder where the language server can store global cache file, 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. -
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 whendatapack.env.language
is set toDefault
in the config.
The client's response for the workspace/configuration
request must match the Config
interface in src/types/Config.ts
.
Version | Description |
---|---|
? | ? |
3.0.0 | Supported textDocument/declaration request. storagePath is no longer required in initialization options. Added localeCode initialization option. |