MLIR VSCode Extension

A little while ago I presented on a vscode extension that brings IDE features (like go-to-definition) to the .mlir textual format, as well as syntax highlighting (including markdown code blocks!). I’d like to announce now that the extension has been published to the vscode marketplace, and should now be publicly accessible (MLIR: published by LLVM Extensions). If you have the chance, give it a go! Please feel free to send additional feature requests for things you’d like to see, or send a patch to implement them yourself :slight_smile: .

– River


Wow, cool!

Update: For those testing it out, I would encourage building your lsp server after this fix (which was missed during a recent general MLIR change). Otherwise, you may get a chance to test how many threads your CPU/OS can handle at one time.

– River


This is awesome River! Is there a quickstart doc for how to make your own lsp-server binary? I assume it’s just a “LspMain” call, but I would appreciate some boilerplate to copy from :slight_smile:

You should be able to follow this snippet: MLIR : Language Server Protocol - MLIR

(That is essentially what we do for the upstream variant:

Registering passes isn’t really important ATM (i.e. no existing features rely on it), but may some day.

– River


Awesome. Here is my PR in case somebody wants a more in-depth thing to rip off:

Wow, thanks for this! Does this function with llvm IR?

Could I use customed lsp-server code for my dialect?
I make it to a stand-alone project, And I’d like to use it on an open source project.

Yes, see Sean’s post above for how to set it up.

LLVM dialect in MLIR yes, else no.

1 Like

I can confirm now that this extension (v 0.0.2) installed via the marketplace works correctly on Fedora 34 (code-1.57.0-1623259809.el8.x86_64)! (I earlier had an issue with the extension silently not working even after a manual installation with no errors.)

Based on @River707 's code, I added a visualization layer on top of it using Webview & React.js. For POC, I implemented the follow features:

  1. Visualize each symbol in the .mlir file as a node in the graph.
  2. If the user click on the node in the graph, the cursor in the editor will jump automatically to the corresponding location in the text file.
  3. Vice versa, if the user click the symbol in text, the graph will recenter at the corresponding node in the graph.

I am still wrapping up the codebase, since I still need to find a good approach to handle the asynchrony between the LSP and the Webview.
Once that is done, I’ll send a patch and people can use it as a boilerplate to extend more visualization features.

Thanks again for @River707 's effort. This is indeed revolutionary to an engineer working with .mlir everyday.


1 Like

Well, I tried to download the visx file, but failed…