Skip to content

Language Server Details

SPGoding edited this page Aug 3, 2020 · 8 revisions

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.

Integrate

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.

Capabilities

Server Capabilities

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.

Client Requirements

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 ⚠️ in the Server Capabilities section to enjoy full features.

Configuration

Initialization options

  • 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 to en. Should be a locale code that the server could use when datapack.env.language is set to Default in the config.

Settings

The client's response for the workspace/configuration request must match the Config interface in src/types/Config.ts.

References

History

Version Description
? ?
3.0.0 Supported textDocument/declaration request. storagePath is no longer required in initialization options. Added localeCode initialization option.
Clone this wiki locally