mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:14:31 +00:00
[mlir][mlir-lsp-server] Add some initial documentation on the MLIR LSP server
This covers some of the basic documentation, but is still missing some documentation/examples of features provided by the server. Feature documentation will be added in a followup. Differential Revision: https://reviews.llvm.org/D100690
This commit is contained in:
1 parent
b810e3a552
commit
52fad38d28
2 files changed
+112
No files matched your search
@@ -0,0 +1,111 @@
|
||||
# MLIR : Language Server Protocol
|
||||
|
||||
[TOC]
|
||||
|
||||
This document describes the tools and utilities related to supporting
|
||||
[LSP](https://microsoft.github.io/language-server-protocol/) IDE language
|
||||
extensions for the MLIR textual assembly format. An LSP language extension is
|
||||
generally comprised of two components; a language client and a language server.
|
||||
A language client is a piece of code that interacts with the IDE that you are
|
||||
using, such as VSCode. A language server acts as the backend for queries that
|
||||
the client may want to perform, such as "Find Definition", "Find References",
|
||||
etc.
|
||||
|
||||
## MLIR LSP Language Server : `mlir-lsp-server`
|
||||
|
||||
MLIR provides an implementation of an LSP language server in the form of the
|
||||
`mlir-lsp-server` tool. This tool interacts with the MLIR C++ API to support
|
||||
rich language queries, such as "Find Definition".
|
||||
|
||||
### Supporting custom dialects and passes
|
||||
|
||||
`mlir-lsp-server`, like many other MLIR based tools, relies on having the
|
||||
appropriate dialects registered to be able to parse in the custom assembly
|
||||
formats used in the textual .mlir files. The `mlir-lsp-server` found within the
|
||||
main MLIR repository provides support for all of the upstream MLIR dialects and
|
||||
passes. Downstream and out-of-tree users will need to provide a custom
|
||||
`mlir-lsp-server` executable that registers the entities that they are
|
||||
interested in. The implementation of `mlir-lsp-server` is provided as a library,
|
||||
making it easy for downstream users to register their dialect/passes and simply
|
||||
call into the main implementation. A simple example is shown below:
|
||||
|
||||
```c++
|
||||
#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
mlir::DialectRegistry registry;
|
||||
registerMyDialects(registry);
|
||||
registerMyPasses();
|
||||
return failed(mlir::MlirLspServerMain(argc, argv, registry));
|
||||
}
|
||||
```
|
||||
|
||||
### Design
|
||||
|
||||
The design of `mlir-lsp-server` is largely comprised of three different
|
||||
components:
|
||||
|
||||
* Communication and Transport (via JSON-RPC)
|
||||
* Language Server Protocol
|
||||
* MLIR Language Server
|
||||
|
||||

|
||||
|
||||
#### Communication and Transport
|
||||
|
||||
`mlir-lsp-server` communicates with the language client via JSON-RPC over
|
||||
stdin/stdout. In the code, this is the `JSONTransport` class. This class knows
|
||||
nothing about the Language Server Protocol, it only knows that JSON-RPC messages
|
||||
are coming in and JSON-RPC messages are going out. The handling of incoming and
|
||||
outgoing LSP messages is left to the `MessageHandler` class. This class routes
|
||||
incoming messages to handlers in the `Language Server Protocol` layer for
|
||||
interpretation, and packages outgoing messages for transport. This class also
|
||||
has limited knowledge of the LSP, and only has information about the three main
|
||||
classes of messages: notifications, calls, and replies.
|
||||
|
||||
#### Language Server Protocol
|
||||
|
||||
`LSPServer` handles the interpretation of the finer LSP details. This class
|
||||
registers handlers for LSP messages and then forwards to the `MLIR Language
|
||||
Server` for processing. The intent of this component is to hold all of the
|
||||
necessary glue when communicating from the MLIR world to the LSP world. In most
|
||||
cases, the LSP message handlers simply forward to the `MLIR Language Server`. In
|
||||
some cases however, the impedance mismatch between the two requires more
|
||||
complicated glue code.
|
||||
|
||||
#### MLIR Language Server
|
||||
|
||||
`MLIRServer` provides the internal MLIR-based implementation of all of LSP
|
||||
queries. This is the class that directly interacts with the MLIR C++ API,
|
||||
including parsing .mlir text files, running passes, etc.
|
||||
|
||||
## Editor Plugins
|
||||
|
||||
LSP Language plugins are available for many popular editors, and in principle
|
||||
`mlir-lsp-server` should work with any of them, though feature set and interface
|
||||
may vary. Below are a set of plugins that are known to work:
|
||||
|
||||
### Visual Studio Code
|
||||
|
||||
Provides MLIR language IDE features for VS code.
|
||||
|
||||
#### Setup
|
||||
|
||||
This extension requires the `mlir-lsp-server` language server. If not found in
|
||||
your path, you must specify the path of the server in the settings of this
|
||||
extension.
|
||||
|
||||
#### Developing in the LLVM monorepo
|
||||
|
||||
This extension is actively developed within the LLVM monorepo, at
|
||||
`mlir/utils/vscode`. When developing or deploying this extension within the LLVM
|
||||
monorepo, a few extra steps for setup are required:
|
||||
|
||||
* Copy `mlir/utils/textmate/mlir.json` to the extension directory and rename
|
||||
to `grammar.json`.
|
||||
|
||||
#### Features
|
||||
|
||||
* Syntax highlighting for .mlir files and `mlir` markdown blocks
|
||||
* go-to-definition and cross references
|
||||
* Definitions include the source file locations of operations in the .mlir
|
||||
@@ -0,0 +1 @@
|
||||
<svg version="1.1" viewBox="0.0 0.0 838.7847769028872 221.9265091863517" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><clipPath id="p.0"><path d="m0 0l838.7848 0l0 221.92651l-838.7848 0l0 -221.92651z" clip-rule="nonzero"/></clipPath><g clip-path="url(#p.0)"><path fill="#000000" fill-opacity="0.0" d="m0 0l838.7848 0l0 221.92651l-838.7848 0z" fill-rule="evenodd"/><path fill="#000000" fill-opacity="0.0" d="m564.43176 0l0.78741455 223.52756" fill-rule="evenodd"/><path stroke="#000000" stroke-width="1.0" stroke-linejoin="round" stroke-linecap="butt" stroke-dasharray="1.0,3.0" d="m564.43176 0l0.78741455 223.52756" fill-rule="evenodd"/><g filter="url(#shadowFilter-p.1)"><use xlink:href="#p.1" transform="matrix(1.0 0.0 0.0 1.0 0.0 2.0)"/></g><defs><filter id="shadowFilter-p.1" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" stdDeviation="2.0" result="blur"/><feComponentTransfer in="blur" color-interpolation-filters="sRGB"><feFuncR type="linear" slope="0" intercept="0.0"/><feFuncG type="linear" slope="0" intercept="0.0"/><feFuncB type="linear" slope="0" intercept="0.0"/><feFuncA type="linear" slope="0.5" intercept="0"/></feComponentTransfer></filter></defs><g id="p.1"><path fill="#cfe2f3" d="m593.84515 66.336006l0 0c0 -12.869511 10.4328 -23.302307 23.302307 -23.302307l158.84418 0c6.180176 0 12.107239 2.455059 16.477234 6.8250885c4.370056 4.3700294 6.8250732 10.297062 6.8250732 16.477219l0 93.20641c0 12.869507 -10.4328 23.302307 -23.302307 23.302307l-158.84418 0c-12.869507 0 -23.302307 -10.4328 -23.302307 -23.302307z" fill-rule="evenodd"/><path stroke="#000000" stroke-width="1.0" stroke-linejoin="round" stroke-linecap="butt" d="m593.84515 66.336006l0 0c0 -12.869511 10.4328 -23.302307 23.302307 -23.302307l158.84418 0c6.180176 0 12.107239 2.455059 16.477234 6.8250885c4.370056 4.3700294 6.8250732 10.297062 6.8250732 16.477219l0 93.20641c0 12.869507 -10.4328 23.302307 -23.302307 23.302307l-158.84418 0c-12.869507 0 -23.302307 -10.4328 -23.302307 -23.302307z" fill-rule="evenodd"/></g><path fill="#000000" fill-opacity="0.0" d="m637.23096 53.396324l118.677185 0l0 50.078743l-118.677185 0z" fill-rule="evenodd"/><path fill="#000000" d="m677.19305 86.716324l0 -18.125l3.65625 0l0 18.125l-3.65625 0zm7.1306763 -18.125l6.6875 0q2.265625 0 3.453125 0.34375q1.59375 0.46875 2.734375 1.671875q1.140625 1.1875 1.734375 2.9375q0.59375 1.734375 0.59375 4.28125q0 2.234375 -0.5625 3.859375q-0.671875 1.96875 -1.9375 3.203125q-0.953125 0.921875 -2.578125 1.4375q-1.203125 0.390625 -3.234375 0.390625l-6.890625 0l0 -18.125zm3.65625 3.0625l0 12.0l2.734375 0q1.53125 0 2.21875 -0.171875q0.890625 -0.21875 1.46875 -0.75q0.59375 -0.53125 0.96875 -1.75q0.375 -1.21875 0.375 -3.3125q0 -2.109375 -0.375 -3.234375q-0.375 -1.125 -1.046875 -1.75q-0.65625 -0.640625 -1.6875 -0.859375q-0.765625 -0.171875 -3.0 -0.171875l-1.65625 0zm14.650574 15.0625l0 -18.125l13.4375 0l0 3.0625l-9.78125 0l0 4.015625l9.109375 0l0 3.0625l-9.109375 0l0 4.921875l10.125 0l0 3.0625l-13.78125 0z" fill-rule="nonzero"/><path fill="#efefef" d="m639.6798 118.29937l0 0c0 -4.3139954 3.4971924 -7.81118 7.811157 -7.81118l103.05481 0c2.0716553 0 4.0584717 0.8229599 5.5233154 2.2878418c1.4649048 1.4648819 2.2878418 3.451683 2.2878418 5.5233383l0 31.243782c0 4.3139954 -3.4971924 7.8111725 -7.811157 7.8111725l-103.05481 0l0 0c-4.313965 0 -7.811157 -3.4971771 -7.811157 -7.8111725z" fill-rule="evenodd"/><path stroke="#000000" stroke-width="1.0" stroke-linejoin="round" stroke-linecap="butt" d="m639.6798 118.29937l0 0c0 -4.3139954 3.4971924 -7.81118 7.811157 -7.81118l103.05481 0c2.0716553 0 4.0584717 0.8229599 5.5233154 2.2878418c1.4649048 1.4648819 2.2878418 3.451683 2.2878418 5.5233383l0 31.243782c0 4.3139954 -3.4971924 7.8111725 -7.811157 7.8111725l-103.05481 0l0 0c-4.313965 0 -7.811157 -3.4971771 -7.811157 -7.8111725z" fill-rule="evenodd"/><path fill="#000000" d="m652.32697 140.84126l0 -13.359383l1.78125 0l0 11.781258l6.5625 0l0 1.578125l-8.34375 0zm9.860107 -4.296875l1.65625 -0.140625q0.125 1.0 0.546875 1.640625q0.4375 0.640625 1.34375 1.046875q0.921875 0.390625 2.0625 0.390625q1.0 0 1.78125 -0.296875q0.78125 -0.296875 1.15625 -0.8125q0.375 -0.53125 0.375 -1.15625q0 -0.625 -0.375 -1.09375q-0.359375 -0.46875 -1.1875 -0.796875q-0.546875 -0.203125 -2.390625 -0.640625q-1.828125 -0.453125 -2.5625 -0.84375q-0.96875 -0.5 -1.4375 -1.234375q-0.46875 -0.75 -0.46875 -1.671875q0 -1.0 0.578125 -1.875q0.578125 -0.890625 1.671875 -1.3437576q1.109375 -0.453125 2.453125 -0.453125q1.484375 0 2.609375 0.484375q1.140625 0.46875763 1.75 1.4062576q0.609375 0.921875 0.65625 2.09375l-1.6875 0.125q-0.140625 -1.265625 -0.9375 -1.90625q-0.78125 -0.65625 -2.3125 -0.65625q-1.609375 0 -2.34375 0.59375q-0.734375 0.59375 -0.734375 1.421875q0 0.71875 0.53125 1.171875q0.5 0.46875 2.65625 0.96875q2.15625 0.484375 2.953125 0.84375q1.171875 0.53125 1.71875 1.359375q0.5625 0.828125 0.5625 1.90625q0 1.0625 -0.609375 2.Line truncated
|
||||
|
After Width: | Height: | Size: 34 KiB |
Reference in new issue
Block a user