xoong
Menu · Editor support
DocsToolsEditor support

Editor support

The mistakes xoong check reports can show up while you type. There are two ways to get that, and they work together: HTML custom data, which gives completion and hover in VS Code with nothing to install, and a language server, xoong-lsp, which adds the checks themselves, quick fixes and completion in any editor that speaks LSP.

Which one

ComparedHTML custom dataLanguage server
Gives youCompletion and hover for every xo-* element and attribute, the operation names, the fixed valuesThe same, and the findings of xoong check as you type, with quick fixes
NeedsThe file xoong sync writes, and one setting@xoong/lsp, and an editor that can start a language server
Works inVS Code (and tools that read its HTML custom data format)Any editor with an LSP client, for HTML, JavaScript and TypeScript files
Checks your codeNoYes

HTML custom data in VS Code

xoong sync writes .xoong/xoong.html-data.json next to operations.json, and so does xoong new. It is the format that VS Code's HTML language service reads. Point the editor at it once, in .vscode/settings.json:

{
  "html.customData": ["./.xoong/xoong.html-data.json"]
}
{
  "version": 1.1,
  "globalAttributes": [
    {
      "name": "xo-click",
      "description": "Call an operation when clicked: \"METHOD /path/{param}\" or an operationId. Params come from the current item, then the view's p-* params.",
      "valueSet": "xo-mutations"
    }
  ],
  "valueSets": [
    {
      "name": "xo-mutations",
      "values": [
        {
          "name": "DELETE /api/people/{id}"
        },
        {
          "name": "POST /api/people"
        },
        {
          "name": "PUT /api/people/{id}"
        },
        {
          "name": "createPerson"
        },
        {
          "name": "deletePerson"
        },
        {
          "name": "updatePerson"
        }
      ]
    }
  ]
}

You then get, in HTML files:

The file is made again by every sync, so it follows the API. It only offers; it does not check, and it does not fix.

The language server

xoong-lsp is a language server for the Language Server Protocol, over standard input and output. It finds .xoong/operations.json from the workspace folder upward and reads it again when it changes; saving a file checks it again, which also picks up a fresh xoong sync. It needs no options.

npm install --save-dev @xoong/lsp@next
npx xoong sync openapi.json
npx xoong-lsp                # started by your editor, not by hand

Any editor with a language-server client can run it: the command is npx xoong-lsp, the files are HTML, JavaScript and TypeScript, and the root is the folder with .xoong/. In Neovim:

vim.api.nvim_create_autocmd('FileType', {
  pattern = { 'html', 'javascript', 'typescript' },
  callback = function(args)
    vim.lsp.start({
      name = 'xoong',
      cmd = { 'npx', 'xoong-lsp' },
      root_dir = vim.fs.root(args.buf, '.xoong'),
    })
  end,
})

VS Code has no setting that starts an arbitrary language server, so there the custom data above is what you use; an extension that wraps the server is planned.

What it gives you

FeatureWhat you get
DiagnosticsThe findings of xoong check, with the same code, message and fix, in HTML files and in JavaScript and TypeScript files (html`...` templates and client.* calls). A new rule shows up in the editor without any change to it. Errors and warnings keep their level.
Operation namesCompletion inside xo-click, xo-submit and op offers mutations; inside get it offers reads, written as paths. It filters by what you typed.
NamesCompletion of xo-* elements after <xo-, of the attributes of the element you are in (page-size inside <xo-pager , on a tag that spans several lines too), of p-<param> on a <xo-view>, and of the xo-* attributes.
ValuesCompletion of the fixed sets (xo-confirm-kind=", <xo-dialog size=") and of the ids of the <xo-dialog>s of the file inside xo-open=".
HoverWhat an element, an xo-* attribute or an attribute of an element does, and the values it takes; what p-id, p-id="?id" and p-id=":id" mean.
Quick fixesReplace an unknown operation (XO201), a misspelled xo-* attribute or element (XO230) or a value outside its set (XO271) with the closest one.
No table yetWithout .xoong/operations.json a file gets one information message: run xoong sync. Nothing else is reported until it exists.

The packages' tests cover each of these. A test also fails when an element or attribute is added to the syntax lists and the server cannot complete or explain it.

Limits

See also: Command line · MCP server · Error codes · How it is built