Language Server Protocol (LSP) Support for Markdown

I was taking a look at the LSP Spec and I noticed here that CommonMark currently doesn’t support this protocol.

Is there anyone currently working on support for this?

1 Like

Here’s a couple of pointers.

I do know of one editor, the Xi Editor project, that supports a client/server architecture.

In the “server” code, LSP is mentioned: https://github.com/xi-editor/xi-editor/tree/master/rust

And I know from testing that this editor does support Markdown. That happens through its component called “syntect”, where Sublime Text/TextMate highlighting is used.

I’m not fluent in Rust, the programming language of the Xi Editor – but I do think that one could replace this Markdown parser with a CommonMark implementation. In fact, the Xi Editor does support syntax highlighting for Rust itself via another extension in its core sans TextMate highlighting, so there’s hope.

So if one combined a Rust CommonMark implementation with this editor, you might end up with an LSP server for Markdown already :thinking:

LSP is designed for programming languages, something Markdown/CommonMark is not*. Markdown doesn’t have reserved words, identifiers or symbols** needing auto-completion, method signatures for which help info can be displayed, etc. Okay, maybe LSP could still be useful to highlight syntax errors? Nope. In Markdown, there is no such thing as a syntax error. Every string of text is a valid Markdown document.

You’ll notice in the list of implementations there is not one that isn’t a programming language.


*though the complexity of the rules sometimes makes them feel like programming languages.

**with the exception of Link Ref Definitions

1 Like

I disagree with @vas here and say that it makes sense to have a markdown server somewhere on github that editors can use.

  1. Such a server can report syntax errors via textDocument/publishDiagnostics
  2. Such a server can provide hover popup documentation via textDocument/hover about various markdown constructs
  3. It can implement textDocument/documentLink to allow the user to click on a URL. This can be made smart by implementing it in such a way that even things like (foo)[1] work.
  4. It can implement textDocument/documentSymbol to provide a sort of “table of contents” by collecting all the header titles.