XML Language Client VS Code + LSP setup

Setup guide

Connect the XML VS Code client to the language server and service.

This guide shows the expected sibling-project layout, build order, VS Code launch flow, schema configuration, and the moving parts between the client, server, and service.

What runs where

Overview

Client

This repository is the VS Code extension. It activates on the xml language and starts the server process with Node over stdio.

Server

xml-language-server is the Language Server Protocol wrapper. It exposes completion, hover, diagnostics, symbols, folding, rename, definition, references, and formatting.

Service

xml-language-service is the editor-agnostic TypeScript library. It provides XML parsing, language features, schema association, and Xerces WASM XSD validation.

Important

Workspace Layout

Keep the three language tooling projects beside each other. The client currently launches the server from ../xml-language-server/dist/server.js, and both the client and server use the service through file:../xml-language-service.

xml-language-workspace/
  xml-language-service/
  xml-language-server/
  xml-language-client/

The parent folder can be named anything. What matters is that these repositories are siblings while you are developing with local file: dependencies.

Fresh setup

Clone Repositories

Start by cloning all three repositories into the same parent folder so the local file: dependencies and server path resolve correctly.

mkdir xml-language-workspace
cd xml-language-workspace

git clone https://github.com/harshanacz/xml-language-service.git
git clone https://github.com/harshanacz/xml-language-server.git
git clone https://github.com/harshanacz/xml-language-client.git

After cloning, continue with the build commands below from inside xml-language-client.

Build order

Quick Start

Build from the bottom layer upward: service first, server second, client last. That ensures the local file: dependencies and generated server entry point are ready before the extension tries to start. Start from inside xml-language-workspace and run the steps in order.

1

Install and build the service

cd xml-language-service
npm install
npm run build
2

Install and build the server

cd ../xml-language-server
npm install
npm run bundle

npm run bundle creates dist/server.js and copies runtime assets such as the Xerces WASM file and default schemas.

3

Install and build the VS Code client

cd ../xml-language-client
npm install
npm run build
New terminal note: If you open a fresh terminal in xml-language-workspace for step 2 or 3, use cd xml-language-server or cd xml-language-client instead of the ../ command shown for the sequential flow.

Development

Run in VS Code

  1. Open xml-language-client in VS Code.
  2. Run the Launch Extension debug configuration, or press F5.
  3. In the Extension Development Host window, open an .xml, .xsd, or .xsl file.
  4. The client starts ../xml-language-server/dist/server.js --stdio automatically.
Activation trigger: The extension activates on onLanguage:xml, so the server starts only after VS Code opens a document recognized as XML.

Try it

Test Workspace

Use the xls-test repository as a sample XML workspace for checking activation, diagnostics, completion, hover, outline, folding, rename, formatting, and schema validation.

git clone https://github.com/harshanacz/xls-test.git
code xls-test

Start the extension from xml-language-client, then open this test workspace in the Extension Development Host window and edit its XML files.

Validation

Schema Setup

Built-in schema associations are provided by the service for common files such as pom.xml and web.xml. Add custom associations in VS Code settings with xmlLanguageServer.schemas.

{
  "xmlLanguageServer.schemas": [
    {
      "pattern": "config.xml",
      "xsdPath": "schemas/config.xsd"
    },
    {
      "pattern": "**/*.xml",
      "xsdPath": "/absolute/path/to/schema.xsd"
    }
  ]
}

Relative xsdPath values are resolved from the workspace root. For XSD files with xs:include or xs:import, keep the imported XSD and DTD files beside the entry schema or in subdirectories under it; the server loads sibling schema assets recursively.

Debug flow

Debugging

Client debugging

Use Launch Extension. The configured pre-launch task runs npm run build and loads dist/extension.js in the Extension Development Host.

Server debugging

Use Launch + Attach Server. The client starts Node with --inspect=6009, and VS Code attaches to the server output in ../xml-language-server/dist.

Distribution

Package

After building the service, server, and client, create a VSIX package from the client repo.

cd ../xml-language-client
npm run package

The package script uses vsce package from this repository's dev dependencies.

Fast fixes

Troubleshooting

Symptom Check Fix
Extension starts but no XML features appear. Open an XML file and check the Extension Host console. Rebuild the client with npm run build.
Server module cannot be found. Confirm ../xml-language-server/dist/server.js exists. Run npm install and npm run bundle in the server repo.
Service package cannot be resolved. Confirm ../xml-language-service/dist/index.js exists. Run npm install and npm run build in the service repo, then reinstall server/client dependencies.
XSD diagnostics do not show. Check xmlLanguageServer.schemas and schema paths. Use workspace-relative paths or absolute paths, then reload the VS Code window.
WASM validation fails at runtime. Confirm xerces_validator.wasm was copied into server dist. Run the server npm run bundle script again.

Verify

Setup Checklist