1
头图

Markdown support was the first feature I had when I joined Visual Studio Code in 2016. It has been very beneficial to add VS Code's built-in Markdown support over the years, and also see how our Markdown extensions directly and indirectly shape core features like webviews and notebooks. Here, I'm happy to share a project I've been working on silently for the past six months, representing the next step in VS Code's Markdown tooling: the Markdown language server . With this language server, we can make most of VS Code's built-in Markdown language tools - from document outlines, smart folding, to path completion - available to other editors and tools.


The work of the Markdown language server is divided into two new open source libraries:

  • Markdown Language Service - A TypeScript library that provides tools for working with Markdown
  • Markdown Language Server - Markdown language server built with Language Services

While these libraries are still in their early stages, they are already used by VS Code 1.70+. We've also seen some benefits of this switch, such as moving the Markdown tool into a separate process so it doesn't block other extensions.

At this point, maybe you want to ask: Why do you need a Markdown language server? Honestly, it took me six years to realize this. From simply treating Markdown as plain text with some asterisks, brackets and hashtags, to understanding Markdown as a markup language and can benefit from many of the same tools we publish for programming languages like TypeScript or Python .

The Markdown language feature set now includes:

  • document outline
  • workspace symbol
  • Documentation link
  • smart folding
  • smart choice
  • Finish
  • rename
  • Find all references
  • go to definition
  • Broken link diagnostics
  • Update link for file move/rename

I know these new tools will make working with Markdown faster and safer. But as I reviewed the list of general features of this programming language, one thought kept bugging me. A few months ago I thought it was ridiculous, but now when I think about it again, I realize that it may finally be time for a Markdown language server.

Are you being servered?

First a fairly general question: I find it very challenging to effectively implement link diagnostics for Markdown files. On large Markdown workspaces (eg vscode-docs) I've been inadvertently hindering the scaling host for a few hundred milliseconds, which is not good. On the other hand, the language server is running as its own process. Not only that, but the language server now has a new diagnostic pull model.

Of course there are more noble reasons. For example, the Markdown language server is useful for other editors and tools . This includes another editor released by the VS Code team: Monaco, not to mention possibilities like a Markdown CLI tool. If I don't have time to build such a tool myself, maybe someone else can use a language server as a starting point. By providing a new language server, I might also be able to start a joint effort around improving the Markdown tooling. Instead of each editor/tool duplicating efforts to implement its own Markdown support, a language server can bring developers together on a larger project that benefits everyone.

After doing all the refactoring, moving the code to the language server would also be a lot of work, but I realized that instead of having to do everything in one go, the server can be built incrementally, extending one feature at a time from VS Code Markdown Moved to the new Markdown language server. Ideally, users would never notice when a feature is moved from an extension to a language server. Move one language feature at a time, learning as you go, and refactoring when clearly needed. Diagnostics is the last feature to migrate, as I not only moved them to the language server, but also rewrote them to use the language server's new pull diagnostics model. The last commit of the entire work mostly removed now unused code from the Markdown extension. So today if you're using VS Code 1.70+, almost all Markdown language features use the new language server .

Building better Markdown tools together

What really excites me about the Markdown language server is that the project is now bigger than VS Code. By making our Markdown tools easy to use, I hope we can help everyone push Markdown tools forward. These open source projects are an invitation to help build the future of Markdown tools together. If you're interested in contributing, check out the new projects to see what you can create with them. You can submit bug reports and feature requests, as well as submit PRs. Let's build them together!

If you're interested in viewing the source code or contributing code, the Markdown language service and server can be found on GitHub.


The original text is long, if you are interested in reading the original blog , welcome to the VS Code homepage!


Follow Microsoft Developer MSDN to learn more


微软技术栈
423 声望995 粉丝

微软技术生态官方平台。予力众生,成就不凡!微软致力于用技术改变世界,助力企业实现数字化转型。