152fad38dSRiver Riddle# MLIR : Language Server Protocol 252fad38dSRiver Riddle 352fad38dSRiver Riddle[TOC] 452fad38dSRiver Riddle 552fad38dSRiver RiddleThis document describes the tools and utilities related to supporting 652fad38dSRiver Riddle[LSP](https://microsoft.github.io/language-server-protocol/) IDE language 7731dfca8SRiver Riddleextensions for various MLIR-related languages. An LSP language extension is 852fad38dSRiver Riddlegenerally comprised of two components; a language client and a language server. 952fad38dSRiver RiddleA language client is a piece of code that interacts with the IDE that you are 1052fad38dSRiver Riddleusing, such as VSCode. A language server acts as the backend for queries that 1152fad38dSRiver Riddlethe client may want to perform, such as "Find Definition", "Find References", 1252fad38dSRiver Riddleetc. 1352fad38dSRiver Riddle 1452fad38dSRiver Riddle## MLIR LSP Language Server : `mlir-lsp-server` 1552fad38dSRiver Riddle 16731dfca8SRiver RiddleMLIR provides an implementation of an LSP language server for `.mlir` text files 17731dfca8SRiver Riddlein the form of the `mlir-lsp-server` tool. This tool interacts with the MLIR C++ 18731dfca8SRiver RiddleAPI to support rich language queries, such as "Find Definition". 1952fad38dSRiver Riddle 20ed7dce23SMehdi Amini### Supporting custom dialects 2152fad38dSRiver Riddle 2252fad38dSRiver Riddle`mlir-lsp-server`, like many other MLIR based tools, relies on having the 2352fad38dSRiver Riddleappropriate dialects registered to be able to parse in the custom assembly 2452fad38dSRiver Riddleformats used in the textual .mlir files. The `mlir-lsp-server` found within the 25ed7dce23SMehdi Aminimain MLIR repository provides support for all of the upstream MLIR dialects. 26ed7dce23SMehdi AminiDownstream and out-of-tree users will need to provide a custom 2752fad38dSRiver Riddle`mlir-lsp-server` executable that registers the entities that they are 2852fad38dSRiver Riddleinterested in. The implementation of `mlir-lsp-server` is provided as a library, 29ed7dce23SMehdi Aminimaking it easy for downstream users to register their dialect and simply 3052fad38dSRiver Riddlecall into the main implementation. A simple example is shown below: 3152fad38dSRiver Riddle 3252fad38dSRiver Riddle```c++ 3352fad38dSRiver Riddle#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" 3452fad38dSRiver Riddle 3552fad38dSRiver Riddleint main(int argc, char **argv) { 3652fad38dSRiver Riddle mlir::DialectRegistry registry; 3752fad38dSRiver Riddle registerMyDialects(registry); 38bb979599SRiver Riddle return mlir::failed(mlir::MlirLspServerMain(argc, argv, registry)); 3952fad38dSRiver Riddle} 4052fad38dSRiver Riddle``` 4152fad38dSRiver Riddle 42731dfca8SRiver RiddleSee the [Editor Plugins](#editor-plugins) section below for details on how to 43731dfca8SRiver Riddlesetup support in a few known LSP clients, such as vscode. 44731dfca8SRiver Riddle 45bb979599SRiver Riddle### Features 46bb979599SRiver Riddle 47bb979599SRiver RiddleThis section details a few of the features that the MLIR language server 48bb979599SRiver Riddleprovides. The screenshots are shown in [VSCode](https://code.visualstudio.com/), 49bb979599SRiver Riddlebut the exact feature set available will depend on your editor client. 50bb979599SRiver Riddle 51731dfca8SRiver Riddle[mlir features]: # 52731dfca8SRiver Riddle 53bb979599SRiver Riddle#### Diagnostics 54bb979599SRiver Riddle 55731dfca8SRiver RiddleThe language server actively runs verification on the IR as you type, showing 56731dfca8SRiver Riddleany generated diagnostics in-place. 57bb979599SRiver Riddle 58bb979599SRiver Riddle 59bb979599SRiver Riddle 60ed344c88SRiver Riddle##### Automatically insert `expected-` diagnostic checks 61ed344c88SRiver Riddle 62ed344c88SRiver RiddleMLIR provides 63ed344c88SRiver Riddle[infrastructure](https://mlir.llvm.org/docs/Diagnostics/#sourcemgr-diagnostic-verifier-handler) 64ed344c88SRiver Riddlefor checking expected diagnostics, which is heavily utilized when defining IR 65ed344c88SRiver Riddleparsing and verification. The language server provides code actions for 66ed344c88SRiver Riddleautomatically inserting the checks for diagnostics it knows about. 67ed344c88SRiver Riddle 68ed344c88SRiver Riddle 69ed344c88SRiver Riddle 70b64a2863SRiver Riddle#### Code completion 71b64a2863SRiver Riddle 72b64a2863SRiver RiddleThe language server provides suggestions as you type, offering completions for 73b64a2863SRiver Riddledialect constructs (such as attributes, operations, and types), block names, SSA 74b64a2863SRiver Riddlevalue names, keywords, and more. 75b64a2863SRiver Riddle 76b64a2863SRiver Riddle 77b64a2863SRiver Riddle 78bb979599SRiver Riddle#### Cross-references 79bb979599SRiver Riddle 80bb979599SRiver RiddleCross references allow for navigating the use/def chains of SSA values (i.e. 81bb979599SRiver Riddleoperation results and block arguments), [Symbols](../SymbolsAndSymbolTables.md), 82bb979599SRiver Riddleand Blocks. 83bb979599SRiver Riddle 84bb979599SRiver Riddle##### Find definition 85bb979599SRiver Riddle 86bb979599SRiver RiddleJump to the definition of the IR entity under the cursor. A few examples are 87bb979599SRiver Riddleshown below: 88bb979599SRiver Riddle 89731dfca8SRiver Riddle- SSA Values 90bb979599SRiver Riddle 91bb979599SRiver Riddle 92bb979599SRiver Riddle 93731dfca8SRiver Riddle- Symbol References 94bb979599SRiver Riddle 95bb979599SRiver Riddle 96bb979599SRiver Riddle 97bb979599SRiver RiddleThe definition of an operation will also take into account the source location 98bb979599SRiver Riddleattached, allowing for navigating into the source file that generated the 99bb979599SRiver Riddleoperation. 100bb979599SRiver Riddle 101bb979599SRiver Riddle 102bb979599SRiver Riddle 103bb979599SRiver Riddle##### Find references 104bb979599SRiver Riddle 105bb979599SRiver RiddleShow all references of the IR entity under the cursor. 106bb979599SRiver Riddle 107bb979599SRiver Riddle 108bb979599SRiver Riddle 109bb979599SRiver Riddle#### Hover 110bb979599SRiver Riddle 111bb979599SRiver RiddleHover over an IR entity to see more information about it. The exact information 112bb979599SRiver Riddledisplayed is dependent on the type of IR entity under the cursor. For example, 113bb979599SRiver Riddlehovering over an `Operation` may show its generic format. 114bb979599SRiver Riddle 115bb979599SRiver Riddle 116bb979599SRiver Riddle 117bb979599SRiver Riddle#### Navigation 118bb979599SRiver Riddle 119bb979599SRiver RiddleThe language server will also inform the editor about the structure of symbol 120bb979599SRiver Riddletables within the IR. This allows for jumping directly to the definition of a 121731dfca8SRiver Riddlesymbol, such as a `func.func`, within the file. 122bb979599SRiver Riddle 123bb979599SRiver Riddle 124bb979599SRiver Riddle 12518f954e7SRiver Riddle#### Bytecode Editing and Inspection 12618f954e7SRiver Riddle 12718f954e7SRiver RiddleThe language server provides support for interacting with MLIR bytecode files, 12818f954e7SRiver Riddleenabling IDEs to transparently view and edit bytecode files in the same way 12918f954e7SRiver Riddleas textual `.mlir` files. 13018f954e7SRiver Riddle 13118f954e7SRiver Riddle 13218f954e7SRiver Riddle 133731dfca8SRiver Riddle## PDLL LSP Language Server : `mlir-pdll-lsp-server` 13452fad38dSRiver Riddle 135731dfca8SRiver RiddleMLIR provides an implementation of an LSP language server for `.pdll` text files 136731dfca8SRiver Riddlein the form of the `mlir-pdll-lsp-server` tool. This tool interacts with the 137731dfca8SRiver RiddlePDLL C++ API to support rich language queries, such as code completion and "Find 138731dfca8SRiver RiddleDefinition". 13952fad38dSRiver Riddle 140731dfca8SRiver Riddle### Compilation Database 141731dfca8SRiver Riddle 142731dfca8SRiver RiddleSimilarly to 143731dfca8SRiver Riddle[`clangd`](https://clang.llvm.org/docs/JSONCompilationDatabase.html), and 144731dfca8SRiver Riddlelanguage servers for various other programming languages, the PDLL language 145731dfca8SRiver Riddleserver relies on a compilation database to provide build-system information for 146731dfca8SRiver Riddle`.pdll` files. This information includes, for example, the include directories 147731dfca8SRiver Riddleavailable for that file. This database allows for the server to interact with 148731dfca8SRiver Riddle`.pdll` files using the same configuration as when building. 149731dfca8SRiver Riddle 150731dfca8SRiver Riddle#### Format 151731dfca8SRiver Riddle 152731dfca8SRiver RiddleA PDLL compilation database is a YAML file, conventionally named 153731dfca8SRiver Riddle`pdll_compile_commands.yml`, that contains a set of `FileInfo` documents 154731dfca8SRiver Riddleproviding information for individiual `.pdll` files. 155731dfca8SRiver Riddle 156731dfca8SRiver RiddleExample: 157731dfca8SRiver Riddle 158731dfca8SRiver Riddle```yaml 159731dfca8SRiver Riddle--- !FileInfo: 160abc362a1SJakub Kuderski filepath: "/home/user/llvm/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.pdll" 161abc362a1SJakub Kuderski includes: "/home/user/llvm/mlir/lib/Dialect/Arith/IR;/home/user/llvm/mlir/include" 162731dfca8SRiver Riddle``` 163731dfca8SRiver Riddle 164731dfca8SRiver Riddle- filepath: <string> - Absolute file path of the file. 16518f954e7SRiver Riddle- includes: <string> - Semi-colon delimited list of absolute include 16618f954e7SRiver Riddle directories. 167731dfca8SRiver Riddle 168731dfca8SRiver Riddle#### Build System Integration 169731dfca8SRiver Riddle 170731dfca8SRiver RiddlePer convention, PDLL compilation databases should be named 171731dfca8SRiver Riddle`pdll_compile_commands.yml` and placed at the top of the build directory. When 172731dfca8SRiver Riddleusing CMake and `mlir_pdll`, a compilation database is generally automatically 173731dfca8SRiver Riddlebuilt and placed in the appropriate location. 174731dfca8SRiver Riddle 175731dfca8SRiver Riddle### Features 176731dfca8SRiver Riddle 177731dfca8SRiver RiddleThis section details a few of the features that the PDLL language server 178731dfca8SRiver Riddleprovides. The screenshots are shown in [VSCode](https://code.visualstudio.com/), 179731dfca8SRiver Riddlebut the exact feature set available will depend on your editor client. 180731dfca8SRiver Riddle 181731dfca8SRiver Riddle[pdll features]: # 182731dfca8SRiver Riddle 183731dfca8SRiver Riddle#### Diagnostics 184731dfca8SRiver Riddle 185731dfca8SRiver RiddleThe language server actively runs verification as you type, showing any 186731dfca8SRiver Riddlegenerated diagnostics in-place. 187731dfca8SRiver Riddle 188731dfca8SRiver Riddle 189731dfca8SRiver Riddle 190731dfca8SRiver Riddle#### Code completion and signature help 191731dfca8SRiver Riddle 192731dfca8SRiver RiddleThe language server provides suggestions as you type based on what constraints, 193731dfca8SRiver Riddlerewrites, dialects, operations, etc are available in this context. The server 194731dfca8SRiver Riddlealso provides information about the structure of constraint and rewrite calls, 195731dfca8SRiver Riddleoperations, and more as you fill them in. 196731dfca8SRiver Riddle 197731dfca8SRiver Riddle 198731dfca8SRiver Riddle 199731dfca8SRiver Riddle#### Cross-references 200731dfca8SRiver Riddle 201731dfca8SRiver RiddleCross references allow for navigating the code base. 202731dfca8SRiver Riddle 203731dfca8SRiver Riddle##### Find definition 204731dfca8SRiver Riddle 205731dfca8SRiver RiddleJump to the definition of a symbol under the cursor: 206731dfca8SRiver Riddle 207731dfca8SRiver Riddle 208731dfca8SRiver Riddle 209731dfca8SRiver RiddleIf ODS information is available, we can also jump to the definition of operation 210731dfca8SRiver Riddlenames and more: 211731dfca8SRiver Riddle 212731dfca8SRiver Riddle 213731dfca8SRiver Riddle 214731dfca8SRiver Riddle##### Find references 215731dfca8SRiver Riddle 216731dfca8SRiver RiddleShow all references of the symbol under the cursor. 217731dfca8SRiver Riddle 218731dfca8SRiver Riddle 219731dfca8SRiver Riddle 220731dfca8SRiver Riddle#### Hover 221731dfca8SRiver Riddle 222731dfca8SRiver RiddleHover over a symbol to see more information about it, such as its type, 223731dfca8SRiver Riddledocumentation, and more. 224731dfca8SRiver Riddle 225731dfca8SRiver Riddle 226731dfca8SRiver Riddle 227731dfca8SRiver RiddleIf ODS information is available, we can also show information directly from the 228731dfca8SRiver Riddleoperation definitions: 229731dfca8SRiver Riddle 230731dfca8SRiver Riddle 231731dfca8SRiver Riddle 232731dfca8SRiver Riddle#### Navigation 233731dfca8SRiver Riddle 234731dfca8SRiver RiddleThe language server will also inform the editor about the structure of symbols 235731dfca8SRiver Riddlewithin the IR. 236731dfca8SRiver Riddle 237731dfca8SRiver Riddle 238731dfca8SRiver Riddle 239731dfca8SRiver Riddle#### View intermediate output 240731dfca8SRiver Riddle 241731dfca8SRiver RiddleThe language server provides support for introspecting various intermediate 242731dfca8SRiver Riddlestages of compilation, such as the AST, the `.mlir` containing the generated 243731dfca8SRiver RiddlePDL, and the generated C++ glue. This is a custom LSP extension, and is not 244731dfca8SRiver Riddlenecessarily provided by all IDE clients. 245731dfca8SRiver Riddle 246731dfca8SRiver Riddle 247731dfca8SRiver Riddle 2485919eab5SRiver Riddle#### Inlay hints 2495919eab5SRiver Riddle 2505919eab5SRiver RiddleThe language server provides additional information inline with the source code. 2515919eab5SRiver RiddleEditors usually render this using read-only virtual text snippets interspersed 2525919eab5SRiver Riddlewith code. Hints may be shown for: 2535919eab5SRiver Riddle 25418f954e7SRiver Riddle- types of local variables 25518f954e7SRiver Riddle- names of operand and result groups 25618f954e7SRiver Riddle- constraint and rewrite arguments 2575919eab5SRiver Riddle 2585919eab5SRiver Riddle 2595919eab5SRiver Riddle 2601b501cbcSRiver Riddle## TableGen LSP Language Server : `tblgen-lsp-server` 2611b501cbcSRiver Riddle 2621b501cbcSRiver RiddleMLIR provides an implementation of an LSP language server for `.td` text files 2631b501cbcSRiver Riddlein the form of the `tblgen-lsp-server` tool. This tool interacts with the 2641b501cbcSRiver RiddleTableGen C++ API to support rich language queries, such as "Find Definition". 2651b501cbcSRiver Riddle 2661b501cbcSRiver Riddle### Compilation Database 2671b501cbcSRiver Riddle 2681b501cbcSRiver RiddleSimilarly to 2691b501cbcSRiver Riddle[`clangd`](https://clang.llvm.org/docs/JSONCompilationDatabase.html), and 2701b501cbcSRiver Riddlelanguage servers for various other programming languages, the TableGen language 2711b501cbcSRiver Riddleserver relies on a compilation database to provide build-system information for 2721b501cbcSRiver Riddle`.td` files. This information includes, for example, the include directories 2731b501cbcSRiver Riddleavailable for that file. This database allows for the server to interact with 2741b501cbcSRiver Riddle`.td` files using the same configuration as when building. 2751b501cbcSRiver Riddle 2761b501cbcSRiver Riddle#### Format 2771b501cbcSRiver Riddle 2781b501cbcSRiver RiddleA TableGen compilation database is a YAML file, conventionally named 2791b501cbcSRiver Riddle`tablegen_compile_commands.yml`, that contains a set of `FileInfo` documents 2801b501cbcSRiver Riddleproviding information for individiual `.td` files. 2811b501cbcSRiver Riddle 2821b501cbcSRiver RiddleExample: 2831b501cbcSRiver Riddle 2841b501cbcSRiver Riddle```yaml 2851b501cbcSRiver Riddle--- !FileInfo: 286abc362a1SJakub Kuderski filepath: "/home/user/llvm/mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td" 287abc362a1SJakub Kuderski includes: "/home/user/llvm/mlir/lib/Dialect/Arith/IR;/home/user/llvm/mlir/include" 2881b501cbcSRiver Riddle``` 2891b501cbcSRiver Riddle 2901b501cbcSRiver Riddle- filepath: <string> - Absolute file path of the file. 29118f954e7SRiver Riddle- includes: <string> - Semi-colon delimited list of absolute include 29218f954e7SRiver Riddle directories. 2931b501cbcSRiver Riddle 2941b501cbcSRiver Riddle#### Build System Integration 2951b501cbcSRiver Riddle 2961b501cbcSRiver RiddlePer convention, TableGen compilation databases should be named 2971b501cbcSRiver Riddle`tablegen_compile_commands.yml` and placed at the top of the build directory. 2981b501cbcSRiver RiddleWhen using CMake and `mlir_tablegen`, a compilation database is generally 2991b501cbcSRiver Riddleautomatically built and placed in the appropriate location. 3001b501cbcSRiver Riddle 3011b501cbcSRiver Riddle### Features 3021b501cbcSRiver Riddle 3031b501cbcSRiver RiddleThis section details a few of the features that the TableGen language server 3041b501cbcSRiver Riddleprovides. The screenshots are shown in [VSCode](https://code.visualstudio.com/), 3051b501cbcSRiver Riddlebut the exact feature set available will depend on your editor client. 3061b501cbcSRiver Riddle 3071b501cbcSRiver Riddle[tablegen features]: # 3081b501cbcSRiver Riddle 3091b501cbcSRiver Riddle#### Diagnostics 3101b501cbcSRiver Riddle 3111b501cbcSRiver RiddleThe language server actively runs verification as you type, showing any 3121b501cbcSRiver Riddlegenerated diagnostics in-place. 3131b501cbcSRiver Riddle 3141b501cbcSRiver Riddle 3151b501cbcSRiver Riddle 3161b501cbcSRiver Riddle#### Cross-references 3171b501cbcSRiver Riddle 3181b501cbcSRiver RiddleCross references allow for navigating the code base. 3191b501cbcSRiver Riddle 3201b501cbcSRiver Riddle##### Find definition 3211b501cbcSRiver Riddle 3221b501cbcSRiver RiddleJump to the definition of a symbol under the cursor: 3231b501cbcSRiver Riddle 3241b501cbcSRiver Riddle 3251b501cbcSRiver Riddle 3261b501cbcSRiver Riddle##### Find references 3271b501cbcSRiver Riddle 3281b501cbcSRiver RiddleShow all references of the symbol under the cursor. 3291b501cbcSRiver Riddle 3301b501cbcSRiver Riddle 3311b501cbcSRiver Riddle 3323e2ad376SRiver Riddle#### Hover 3333e2ad376SRiver Riddle 3343e2ad376SRiver RiddleHover over a symbol to see more information about it, such as its type, 3353e2ad376SRiver Riddledocumentation, and more. 3363e2ad376SRiver Riddle 3373e2ad376SRiver Riddle 3383e2ad376SRiver Riddle 3393e2ad376SRiver RiddleHovering over an overridden field will also show you information such as 3403e2ad376SRiver Riddledocumentation from the base value: 3413e2ad376SRiver Riddle 3423e2ad376SRiver Riddle 3433e2ad376SRiver Riddle 344731dfca8SRiver Riddle## Language Server Design 345731dfca8SRiver Riddle 346731dfca8SRiver RiddleThe design of the various language servers provided by MLIR are effectively the 347731dfca8SRiver Riddlesame, and are largely comprised of three different components: 348731dfca8SRiver Riddle 349731dfca8SRiver Riddle- Communication and Transport (via JSON-RPC) 350731dfca8SRiver Riddle- Language Server Protocol 351731dfca8SRiver Riddle- Language-Specific Server 35252fad38dSRiver Riddle 35352fad38dSRiver Riddle 35452fad38dSRiver Riddle 355731dfca8SRiver Riddle### Communication and Transport 35652fad38dSRiver Riddle 357731dfca8SRiver RiddleThe language server, such as `mlir-lsp-server`, communicates with the language 358731dfca8SRiver Riddleclient via JSON-RPC over stdin/stdout. In the code, this is the `JSONTransport` 359731dfca8SRiver Riddleclass. This class knows nothing about the Language Server Protocol, it only 360731dfca8SRiver Riddleknows that JSON-RPC messages are coming in and JSON-RPC messages are going out. 361731dfca8SRiver RiddleThe handling of incoming and outgoing LSP messages is left to the 362731dfca8SRiver Riddle`MessageHandler` class. This class routes incoming messages to handlers in the 363731dfca8SRiver Riddle`Language Server Protocol` layer for interpretation, and packages outgoing 364731dfca8SRiver Riddlemessages for transport. This class also has limited knowledge of the LSP, and 365731dfca8SRiver Riddleonly has information about the three main classes of messages: notifications, 366731dfca8SRiver Riddlecalls, and replies. 36752fad38dSRiver Riddle 368731dfca8SRiver Riddle### Language Server Protocol 36952fad38dSRiver Riddle 37052fad38dSRiver Riddle`LSPServer` handles the interpretation of the finer LSP details. This class 371731dfca8SRiver Riddleregisters handlers for LSP messages and then forwards to the 372731dfca8SRiver Riddle[`Language-Specific Server`](#language-specific-server) for processing. The 373731dfca8SRiver Riddleintent of this component is to hold all of the necessary glue when communicating 374731dfca8SRiver Riddlefrom the LSP world to the language-specific world (e.g. MLIR, PDLL, etc.). In 375731dfca8SRiver Riddlemost cases, the LSP message handlers simply forward directly to the 376731dfca8SRiver Riddle`Language-Specific Server`. In some cases, however, the impedance mismatch 377731dfca8SRiver Riddlebetween the two requires more complicated glue code. 37852fad38dSRiver Riddle 379731dfca8SRiver Riddle### Language-Specific Server 38052fad38dSRiver Riddle 381731dfca8SRiver RiddleThe language specific server, such as `MLIRServer` or `PDLLServer`, provides the 382731dfca8SRiver Riddleinternal implementation of all of LSP queries for a specific language. These are 383731dfca8SRiver Riddlethe classes that directly interacts with the C++ API for the language, including 384731dfca8SRiver Riddleparsing text files, interpreting definition/reference information, etc. 38552fad38dSRiver Riddle 38652fad38dSRiver Riddle## Editor Plugins 38752fad38dSRiver Riddle 38852fad38dSRiver RiddleLSP Language plugins are available for many popular editors, and in principle 389731dfca8SRiver Riddlethe language servers provided by MLIR should work with any of them, though 390731dfca8SRiver Riddlefeature sets and interfaces may vary. Below are a set of plugins that are known 391731dfca8SRiver Riddleto work: 39252fad38dSRiver Riddle 39352fad38dSRiver Riddle### Visual Studio Code 39452fad38dSRiver Riddle 395a4fbe31fSDavid SpickettThe [MLIR extension](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.vscode-mlir) 396a4fbe31fSDavid Spickettprovides language IDE features for [MLIR](https://mlir.llvm.org/) related 3971b501cbcSRiver Riddlelanguages: [MLIR](#mlir---mlir-textual-assembly-format), 3981b501cbcSRiver Riddle[PDLL](#pdll---mlir-pdll-pattern-files), and [TableGen](#td---tablegen-files) 399fcecfcb9SRiver Riddle 400731dfca8SRiver Riddle#### `.mlir` - MLIR textual assembly format: 40152fad38dSRiver Riddle 402731dfca8SRiver RiddleThe MLIR extension adds language support for the 403731dfca8SRiver Riddle[MLIR textual assembly format](https://mlir.llvm.org/docs/LangRef/): 40452fad38dSRiver Riddle 405731dfca8SRiver Riddle##### Features 406731dfca8SRiver Riddle 407731dfca8SRiver Riddle- Syntax highlighting for `.mlir` files and `mlir` markdown blocks 408731dfca8SRiver Riddle- go-to-definition and cross references 409731dfca8SRiver Riddle- Detailed information when hovering over IR entities 410731dfca8SRiver Riddle- Outline and navigation of symbols and symbol tables 411b64a2863SRiver Riddle- Code completion 412731dfca8SRiver Riddle- Live parser and verifier diagnostics 413731dfca8SRiver Riddle 414731dfca8SRiver Riddle[mlir-vscode features]: # 415731dfca8SRiver Riddle 416731dfca8SRiver Riddle##### Setup 417731dfca8SRiver Riddle 418731dfca8SRiver Riddle###### `mlir-lsp-server` 419731dfca8SRiver Riddle 420731dfca8SRiver RiddleThe various `.mlir` language features require the 421731dfca8SRiver Riddle[`mlir-lsp-server` language server](https://mlir.llvm.org/docs/Tools/MLIRLSP/#mlir-lsp-language-server--mlir-lsp-server). 422731dfca8SRiver RiddleIf `mlir-lsp-server` is not found within your workspace path, you must specify 423731dfca8SRiver Riddlethe path of the server via the `mlir.server_path` setting. The path of the 424731dfca8SRiver Riddleserver may be absolute or relative within your workspace. 425731dfca8SRiver Riddle 426731dfca8SRiver Riddle#### `.pdll` - MLIR PDLL pattern files: 427731dfca8SRiver Riddle 428731dfca8SRiver RiddleThe MLIR extension adds language support for the 429731dfca8SRiver Riddle[PDLL pattern language](https://mlir.llvm.org/docs/PDLL/). 430731dfca8SRiver Riddle 431731dfca8SRiver Riddle##### Features 432731dfca8SRiver Riddle 433731dfca8SRiver Riddle- Syntax highlighting for `.pdll` files and `pdll` markdown blocks 434731dfca8SRiver Riddle- go-to-definition and cross references 435731dfca8SRiver Riddle- Types and documentation on hover 436731dfca8SRiver Riddle- Code completion and signature help 437731dfca8SRiver Riddle- View intermediate AST, MLIR, or C++ output 438731dfca8SRiver Riddle 439731dfca8SRiver Riddle[pdll-vscode features]: # 440731dfca8SRiver Riddle 441731dfca8SRiver Riddle##### Setup 442731dfca8SRiver Riddle 443731dfca8SRiver Riddle###### `mlir-pdll-lsp-server` 444731dfca8SRiver Riddle 445731dfca8SRiver RiddleThe various `.pdll` language features require the 446731dfca8SRiver Riddle[`mlir-pdll-lsp-server` language server](https://mlir.llvm.org/docs/Tools/MLIRLSP/#pdll-lsp-language-server--mlir-pdll-lsp-server). 447731dfca8SRiver RiddleIf `mlir-pdll-lsp-server` is not found within your workspace path, you must 448731dfca8SRiver Riddlespecify the path of the server via the `mlir.pdll_server_path` setting. The path 449731dfca8SRiver Riddleof the server may be absolute or relative within your workspace. 450731dfca8SRiver Riddle 451731dfca8SRiver Riddle###### Project setup 452731dfca8SRiver Riddle 453731dfca8SRiver RiddleTo properly understand and interact with `.pdll` files, the language server must 454731dfca8SRiver Riddleunderstand how the project is built (compile flags). 455731dfca8SRiver Riddle[`pdll_compile_commands.yml` files](https://mlir.llvm.org/docs/Tools/MLIRLSP/#compilation-database) 456731dfca8SRiver Riddlerelated to your project should be provided to ensure files are properly 457731dfca8SRiver Riddleprocessed. These files can usually be generated by the build system, and the 458731dfca8SRiver Riddleserver will attempt to find them within your `build/` directory. If not 459731dfca8SRiver Riddleavailable in or a unique location, additional `pdll_compile_commands.yml` files 460731dfca8SRiver Riddlemay be specified via the `mlir.pdll_compilation_databases` setting. The paths of 461731dfca8SRiver Riddlethese databases may be absolute or relative within your workspace. 46252fad38dSRiver Riddle 4631b501cbcSRiver Riddle#### `.td` - TableGen files: 4641b501cbcSRiver Riddle 4651b501cbcSRiver RiddleThe MLIR extension adds language support for the 4661b501cbcSRiver Riddle[TableGen language](https://llvm.org/docs/TableGen/ProgRef.html). 4671b501cbcSRiver Riddle 4681b501cbcSRiver Riddle##### Features 4691b501cbcSRiver Riddle 4701b501cbcSRiver Riddle- Syntax highlighting for `.td` files and `tablegen` markdown blocks 4711b501cbcSRiver Riddle- go-to-definition and cross references 472f90c2acbSRiver Riddle- Types and documentation on hover 4731b501cbcSRiver Riddle 4741b501cbcSRiver Riddle[tablegen-vscode features]: # 4751b501cbcSRiver Riddle 4761b501cbcSRiver Riddle##### Setup 4771b501cbcSRiver Riddle 4781b501cbcSRiver Riddle###### `tblgen-lsp-server` 4791b501cbcSRiver Riddle 4801b501cbcSRiver RiddleThe various `.td` language features require the 4811b501cbcSRiver Riddle[`tblgen-lsp-server` language server](https://mlir.llvm.org/docs/Tools/MLIRLSP/#tablegen-lsp-language-server--tblgen-lsp-server). 4821b501cbcSRiver RiddleIf `tblgen-lsp-server` is not found within your workspace path, you must specify 4831b501cbcSRiver Riddlethe path of the server via the `mlir.tablegen_server_path` setting. The path of 4841b501cbcSRiver Riddlethe server may be absolute or relative within your workspace. 4851b501cbcSRiver Riddle 4861b501cbcSRiver Riddle###### Project setup 4871b501cbcSRiver Riddle 4881b501cbcSRiver RiddleTo properly understand and interact with `.td` files, the language server must 4891b501cbcSRiver Riddleunderstand how the project is built (compile flags). 4901b501cbcSRiver Riddle[`tablegen_compile_commands.yml` files](https://mlir.llvm.org/docs/Tools/MLIRLSP/#compilation-database-1) 4911b501cbcSRiver Riddlerelated to your project should be provided to ensure files are properly 4921b501cbcSRiver Riddleprocessed. These files can usually be generated by the build system, and the 4931b501cbcSRiver Riddleserver will attempt to find them within your `build/` directory. If not 4941b501cbcSRiver Riddleavailable in or a unique location, additional `tablegen_compile_commands.yml` 4951b501cbcSRiver Riddlefiles may be specified via the `mlir.tablegen_compilation_databases` setting. 4961b501cbcSRiver RiddleThe paths of these databases may be absolute or relative within your workspace. 4971b501cbcSRiver Riddle 498fcecfcb9SRiver Riddle#### Contributing 49952fad38dSRiver Riddle 500fcecfcb9SRiver RiddleThis extension is actively developed within the 501731dfca8SRiver Riddle[LLVM monorepo](https://github.com/llvm/llvm-project), at 502731dfca8SRiver Riddle[`mlir/utils/vscode`](https://github.com/llvm/llvm-project/tree/main/mlir/utils/vscode). 503731dfca8SRiver RiddleAs such, contributions should follow the 504d3c895a8SRiver Riddle[normal LLVM guidelines](https://llvm.org/docs/Contributing.html), with code 505d3c895a8SRiver Riddlereviews sent to 506*1716c5b6SDavid Spickett[GitHub](https://llvm.org/docs/Contributing.html#how-to-submit-a-patch). 507d3c895a8SRiver Riddle 508d3c895a8SRiver RiddleWhen developing or deploying this extension within the LLVM monorepo, a few 509d3c895a8SRiver Riddleextra setup steps are required: 51052fad38dSRiver Riddle 511731dfca8SRiver Riddle- Copy `mlir/utils/textmate/mlir.json` to the extension directory and rename to 512731dfca8SRiver Riddle `grammar.json`. 513731dfca8SRiver Riddle- Copy `llvm/utils/textmate/tablegen.json` to the extension directory and rename 5145de12bb7SRiver Riddle to `tablegen-grammar.json`. 515731dfca8SRiver Riddle- Copy 5163e590649SRiver Riddle `https://mlir.llvm.org//LogoAssets/logo/PNG/full_color/mlir-identity-03.png` 5173e590649SRiver Riddle to the extension directory and rename to `icon.png`. 51852fad38dSRiver Riddle 519fcecfcb9SRiver RiddlePlease follow the existing code style when contributing to the extension, we 520fcecfcb9SRiver Riddlerecommend to run `npm run format` before sending a patch. 521