|
| 1 | +# Markdown Language Server |
| 2 | + |
| 3 | +> **❗ Import** This is still in development. While the language server is being used by VS Code, it has not yet been tested with other clients. |
| 4 | +
|
| 5 | +The Markdown language server powers VS Code's built-in markdown support, providing tools for writing and browsing Markdown files. It runs as a separate executable and implements the [language server protocol](https://microsoft.github.io/language-server-protocol/overview). |
| 6 | + |
| 7 | +This server uses the [Markdown Language Service](https://github.com/microsoft/vscode-markdown-languageservice) to implement almost all of the language features. You can use that library if you need a library for working with Markdown instead of a full language server. |
| 8 | + |
| 9 | + |
| 10 | +## Server capabilities |
| 11 | + |
| 12 | +- [Completions](https://microsoft.github.io/language-server-protocol/specification#textDocument_completion) for Markdown links. |
| 13 | + |
| 14 | +- [Folding](https://microsoft.github.io/language-server-protocol/specification#textDocument_foldingRange) of Markdown regions, block elements, and header sections. |
| 15 | + |
| 16 | +- [Smart selection](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_selectionRange) for inline elements, block elements, and header sections. |
| 17 | + |
| 18 | +- [Document Symbols](https://microsoft.github.io/language-server-protocol/specification#textDocument_documentSymbol) for quick navigation to headers in a document. |
| 19 | + |
| 20 | +- [Workspace Symbols](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_symbol) for quick navigation to headers in the workspace |
| 21 | + |
| 22 | +- [Document links](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_documentLink) for making Markdown links in a document clickable. |
| 23 | + |
| 24 | +- [Find all references](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_references) to headers and links across all Markdown files in the workspace. |
| 25 | + |
| 26 | +- [Go to definition](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition) from links to headers or link definitions. |
| 27 | + |
| 28 | +- [Rename](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_rename) of headers and links across all Markdown files in the workspace. |
| 29 | + |
| 30 | +- Find all references to a file. Uses a custom `markdown/getReferencesToFileInWorkspace` message. |
| 31 | + |
| 32 | +- [Code Actions](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction) |
| 33 | + |
| 34 | + - Organize link definitions source action. |
| 35 | + - Extract link to definition refactoring. |
| 36 | + |
| 37 | +- Updating links when a file is moved / renamed. Uses a custom `markdown/getEditForFileRenames` message. |
| 38 | + |
| 39 | +- [Pull diagnostics (validation)](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics) for links. |
| 40 | + |
| 41 | + |
| 42 | +## Client requirements |
| 43 | + |
| 44 | +### Initialization options |
| 45 | + |
| 46 | +The client can send the following initialization options to the server: |
| 47 | + |
| 48 | +- `markdownFileExtensions` Array file extensions that should be considered as Markdown. These should not include the leading `.`. For example: `['md', 'mdown', 'markdown']`. |
| 49 | + |
| 50 | +### Settings |
| 51 | + |
| 52 | +Clients may send a `workspace/didChangeConfiguration` notification to notify the server of settings changes. |
| 53 | +The server supports the following settings: |
| 54 | + |
| 55 | +- `markdown` |
| 56 | + - `suggest` |
| 57 | + - `paths` |
| 58 | + - `enabled` — Enable/disable path suggestions. |
| 59 | + |
| 60 | + - `occurrencesHighlight` |
| 61 | + - `enabled` — Enable/disable highlighting of link occurrences. |
| 62 | + |
| 63 | + - `validate` |
| 64 | + - `enabled` — Enable/disable all validation. |
| 65 | + - `referenceLinks` |
| 66 | + - `enabled` — Enable/disable validation of reference links: `[text][ref]` |
| 67 | + - `fragmentLinks` |
| 68 | + - `enabled` — Enable/disable validation of links to fragments in the current files: `[text](#head)` |
| 69 | + - `fileLinks` |
| 70 | + - `enabled` — Enable/disable validation of links to file in the workspace. |
| 71 | + - `markdownFragmentLinks` — Enable/disable validation of links to headers in other Markdown files. Use `inherit` to inherit the `fragmentLinks` setting. |
| 72 | + - `ignoredLinks` — Array of glob patterns for files that should not be validated. |
| 73 | + - `unusedLinkDefinitions` |
| 74 | + - `enabled` — Enable/disable validation of unused link definitions. |
| 75 | + - `duplicateLinkDefinitions` |
| 76 | + - `enabled` — Enable/disable validation of duplicated link definitions. |
| 77 | + |
| 78 | +### Custom requests |
| 79 | + |
| 80 | +To support all of the features of the language server, the client needs to implement a few custom request types. The definitions of these request types can be found in [`protocol.ts`](./src/protocol.ts) |
| 81 | + |
| 82 | +#### `markdown/parse` |
| 83 | + |
| 84 | +Get the tokens for a Markdown file. Clients are expected to use [Markdown-it](https://github.com/markdown-it/markdown-it) for this. |
| 85 | + |
| 86 | +We require that clients bring their own version of Markdown-it so that they can customize/extend Markdown-it. |
| 87 | + |
| 88 | +#### `markdown/fs/readFile` |
| 89 | + |
| 90 | +Read the contents of a file in the workspace. |
| 91 | + |
| 92 | +#### `markdown/fs/readDirectory` |
| 93 | + |
| 94 | +Read the contents of a directory in the workspace. |
| 95 | + |
| 96 | +#### `markdown/fs/stat` |
| 97 | + |
| 98 | +Check if a given file/directory exists in the workspace. |
| 99 | + |
| 100 | +#### `markdown/fs/watcher/create` |
| 101 | + |
| 102 | +Create a file watcher. This is needed for diagnostics support. |
| 103 | + |
| 104 | +#### `markdown/fs/watcher/delete` |
| 105 | + |
| 106 | +Delete a previously created file watcher. |
| 107 | + |
| 108 | +#### `markdown/findMarkdownFilesInWorkspace` |
| 109 | + |
| 110 | +Get a list of all markdown files in the workspace. |
| 111 | + |
| 112 | + |
| 113 | +## Contribute |
| 114 | + |
| 115 | +The source code of the Markdown language server can be found in the [VSCode repository](https://github.com/microsoft/vscode) at [extensions/markdown-language-features/server](https://github.com/microsoft/vscode/tree/master/extensions/markdown-language-features/server). |
| 116 | + |
| 117 | +File issues and pull requests in the [VSCode GitHub Issues](https://github.com/microsoft/vscode/issues). See the document [How to Contribute](https://github.com/microsoft/vscode/wiki/How-to-Contribute) on how to build and run from source. |
| 118 | + |
| 119 | +Most of the functionality of the server is located in libraries: |
| 120 | + |
| 121 | +- [vscode-markdown-languageservice](https://github.com/microsoft/vscode-markdown-languageservice) contains the implementation of all features as a reusable library. |
| 122 | +- [vscode-languageserver-node](https://github.com/microsoft/vscode-languageserver-node) contains the implementation of language server for NodeJS. |
| 123 | + |
| 124 | +Help on any of these projects is very welcome. |
| 125 | + |
| 126 | +## Code of Conduct |
| 127 | + |
| 128 | +This project has adopted the [Microsoft Open Source Code of Conduct ](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
| 129 | + |
| 130 | +## License |
| 131 | + |
| 132 | +Copyright (c) Microsoft Corporation. All rights reserved. |
| 133 | + |
| 134 | +Licensed under the [MIT](https://github.com/microsoft/vscode/blob/master/LICENSE.txt) License. |
| 135 | + |
0 commit comments