Skip to content

Commit

Permalink
Allow Language Server to be used as standalone process independent of…
Browse files Browse the repository at this point in the history
… VS Code Extension (#17)

* fix: allow server to be used standalone without VS Code extension client

* build: fix build output to get npm to install markdoc-ls to bin

* build: revert unintended change to server package name
  • Loading branch information
ferntheplant authored Apr 2, 2024
1 parent a35eaa7 commit 3f53a17
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ The JSON configuration file consists of an array of server instance descriptions
- The `routing` property is an optional object that describes your project's routing configuration
- The `frontmatter` property is a string that tells the extension which property in the Markdoc file's YAML frontmatter contains the URL route associated with the file

### Standalone Server Configuration

When using the server standalone without the client VS Code extension you can pass the configuration object to your LSP client like so:

```json
{
"root": "/path/to/project/root",
"path": "relative/path/to/markdoc/files",
"config": {
"root": "/path/to/project/root",
"path": "relative/path/to/markdoc/files"
}
}
```

Invoke the server with `markdoc-ls --stdio` from within your LSP client.

### File extensions

In order to distinguish Markdoc files from Markdown files, the Visual Studio Code extension expects Markdoc files to use one of the following file extensions: `.markdoc`, `.markdoc.md`, or `.mdoc`.
Expand Down
3 changes: 2 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import {context, build} from 'esbuild';

const config = {
bundle: true,
entryPoints: ['client/index.ts', 'server/index.ts', 'client/server.ts'],
entryPoints: ['client/index.ts', 'server/index.ts', 'server/wrapper.ts', 'client/server.ts'],
outdir: 'dist',
sourcemap: 'linked',
external: ['vscode'],
platform: 'node',
format: 'cjs',
banner: { js: '#!/usr/bin/env node' },
};

if (process.argv.includes('--watch')) {
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"url": "https://github.com/markdoc/language-server.git"
},
"main": "./dist/client/index.js",
"bin": {
"markdoc-ls": "dist/server/wrapper.js"
},
"scripts": {
"build": "node build.mjs",
"build:watch": "node build.mjs --watch",
Expand Down
3 changes: 2 additions & 1 deletion server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export function connect(
});

return new Promise((resolve) => {
connection.onInitialized(() => resolve(options));
const options = connection.onInitialized(() => resolve(options));
connection.listen();
return options
});
}

Expand Down
3 changes: 3 additions & 0 deletions server/wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { server } from './server';

server();

0 comments on commit 3f53a17

Please sign in to comment.