coc-mlir

0.0.12-rc2 • Public • Published

MLIR

Ported from vscode-mlir.

Because some APIs of vscode are missing in coc.nvim, disable some features temporarily:

  • command mlir.viewPDLLOutput: miss vscode.workspace.openTextDocument({language, content})
  • custom editor mlir.bytecode: miss vscode.window.registerCustomEditorProvider()
  • filesystem mlir.bytecode-mlir: miss vscode.workspace.registerFileSystemProvider()
  • use chokidar.watch() to detect the changes of the paths of language servers: miss vscode.Disposable.constructor()

Install

" command line
CocInstall coc-mlir
" or add the following code to your vimrc
let g:coc_global_extensions = ['coc-mlir', 'other coc-plugins']

Provides language IDE features for MLIR related languages: MLIR, PDLL, and TableGen

.mlir - MLIR textual assembly format:

The MLIR extension adds language support for the MLIR textual assembly format:

Features

  • Syntax highlighting for .mlir files and mlir markdown blocks
  • go-to-definition and cross references
  • Detailed information when hovering over IR entities
  • Outline and navigation of symbols and symbol tables
  • Code completion
  • Live parser and verifier diagnostics

Diagnostics

The language server actively runs verification on the IR as you type, showing any generated diagnostics in-place.

IMG

Automatically insert expected- diagnostic checks

MLIR provides infrastructure for checking expected diagnostics, which is heavily utilized when defining IR parsing and verification. The language server provides code actions for automatically inserting the checks for diagnostics it knows about.

IMG

Code completion

The language server provides suggestions as you type, offering completions for dialect constructs (such as attributes, operations, and types), block names, SSA value names, keywords, and more.

IMG

Cross-references

Cross references allow for navigating the use/def chains of SSA values (i.e. operation results and block arguments), Symbols, and Blocks.

Find definition

Jump to the definition of the IR entity under the cursor. A few examples are shown below:

  • SSA Values

SSA

  • Symbol References

Symbols

The definition of an operation will also take into account the source location attached, allowing for navigating into the source file that generated the operation.

External Locations

Find references

Show all references of the IR entity under the cursor.

IMG

Hover

Hover over an IR entity to see more information about it. The exact information displayed is dependent on the type of IR entity under the cursor. For example, hovering over an Operation may show its generic format.

IMG

Navigation

The language server will also inform the editor about the structure of symbol tables within the IR. This allows for jumping directly to the definition of a symbol, such as a func.func, within the file.

IMG

Bytecode Editing and Inspection

The language server provides support for interacting with MLIR bytecode files, enabling IDEs to transparently view and edit bytecode files in the same way as textual .mlir files.

IMG

Setup

mlir-lsp-server

The various .mlir language features require the mlir-lsp-server language server. If mlir-lsp-server is not found within your workspace path, you must specify the path of the server via the mlir.server_path setting. The path of the server may be absolute or relative within your workspace.

.pdll - MLIR PDLL pattern files:

The MLIR extension adds language support for the PDLL pattern language.

Features

  • Syntax highlighting for .pdll files and pdll markdown blocks
  • go-to-definition and cross references
  • Types and documentation on hover
  • Code completion and signature help
  • View intermediate AST, MLIR, or C++ output

Diagnostics

The language server actively runs verification as you type, showing any generated diagnostics in-place.

IMG

Code completion and signature help

The language server provides suggestions as you type based on what constraints, rewrites, dialects, operations, etc are available in this context. The server also provides information about the structure of constraint and rewrite calls, operations, and more as you fill them in.

IMG

Cross-references

Cross references allow for navigating the code base.

Find definition

Jump to the definition of a symbol under the cursor:

IMG

If ODS information is available, we can also jump to the definition of operation names and more:

IMG

Find references

Show all references of the symbol under the cursor.

IMG

Hover

Hover over a symbol to see more information about it, such as its type, documentation, and more.

IMG

If ODS information is available, we can also show information directly from the operation definitions:

IMG

Navigation

The language server will also inform the editor about the structure of symbols within the IR.

IMG

View intermediate output

The language server provides support for introspecting various intermediate stages of compilation, such as the AST, the .mlir containing the generated PDL, and the generated C++ glue. This is a custom LSP extension, and is not necessarily provided by all IDE clients.

IMG

Inlay hints

The language server provides additional information inline with the source code. Editors usually render this using read-only virtual text snippets interspersed with code. Hints may be shown for:

  • types of local variables
  • names of operand and result groups
  • constraint and rewrite arguments

IMG

Setup

mlir-pdll-lsp-server

The various .pdll language features require the mlir-pdll-lsp-server language server. If mlir-pdll-lsp-server is not found within your workspace path, you must specify the path of the server via the mlir.pdll_server_path setting. The path of the server may be absolute or relative within your workspace.

Project setup

To properly understand and interact with .pdll files, the language server must understand how the project is built (compile flags). pdll_compile_commands.yml files related to your project should be provided to ensure files are properly processed. These files can usually be generated by the build system, and the server will attempt to find them within your build/ directory. If not available in or a unique location, additional pdll_compile_commands.yml files may be specified via the mlir.pdll_compilation_databases setting. The paths of these databases may be absolute or relative within your workspace.

.td - TableGen files:

The MLIR extension adds language support for the TableGen language.

Features

  • Syntax highlighting for .td files and tablegen markdown blocks
  • go-to-definition and cross references
  • Types and documentation on hover

Diagnostics

The language server actively runs verification as you type, showing any generated diagnostics in-place.

IMG

Cross-references

Cross references allow for navigating the code base.

Find definition

Jump to the definition of a symbol under the cursor:

IMG

Find references

Show all references of the symbol under the cursor.

IMG

Hover

Hover over a symbol to see more information about it, such as its type, documentation, and more.

IMG

Hovering over an overridden field will also show you information such as documentation from the base value:

IMG

Setup

tblgen-lsp-server

The various .td language features require the tblgen-lsp-server language server. If tblgen-lsp-server is not found within your workspace path, you must specify the path of the server via the mlir.tablegen_server_path setting. The path of the server may be absolute or relative within your workspace.

Project setup

To properly understand and interact with .td files, the language server must understand how the project is built (compile flags). tablegen_compile_commands.yml files related to your project should be provided to ensure files are properly processed. These files can usually be generated by the build system, and the server will attempt to find them within your build/ directory. If not available in or a unique location, additional tablegen_compile_commands.yml files may be specified via the mlir.tablegen_compilation_databases setting. The paths of these databases may be absolute or relative within your workspace.

Contributing

This extension is actively developed within the LLVM monorepo, at mlir/utils/vscode. As such, contributions should follow the normal LLVM guidelines, with code reviews sent to phabricator.

When developing or deploying this extension within the LLVM monorepo, a few extra setup steps are required:

  • Copy mlir/utils/textmate/mlir.json to the extension directory and rename to grammar.json.
  • Copy llvm/utils/textmate/tablegen.json to the extension directory and rename to tablegen-grammar.json.
  • Copy https://mlir.llvm.org//LogoAssets/logo/PNG/full_color/mlir-identity-03.png to the extension directory and rename to icon.png.

Please follow the existing code style when contributing to the extension, we recommend to run npm run format before sending a patch.

Package Sidebar

Install

npm i coc-mlir

Weekly Downloads

1

Version

0.0.12-rc2

License

none

Unpacked Size

191 kB

Total Files

9

Last publish

Collaborators

  • freedwu