Compile your code and explore assembly from Neovim using the
compiler-explorer REST API. Supercharged by vim.ui
,
vim.notify
and vim.diagnostic
.
Features • Dependencies • Install • Commands • Configuration
This is what the interface looks like using the vim.ui
provided
by dressing.nvim with the
fzf-lua backend and the vim.notify
provided by nvim-notify.
- Compile code asynchronously using
vim.loop
. - Select compiler interactively using
vim.ui.select
or pass it as a vim command parameter. - Compile visual selections.
- Send compiler warnings and errors to the quickfix list.
- Highlight matching lines between source code and assembly.
- Show binary output (opcodes and address) using virtual text.
- Format code.
- Add libraries.
- Show tooltips about specific instructions.
- Jump to label definitions.
- Load example code.
- Open the website with the local state (source code and compilers).
You can verify these dependencies by running :checkhealth compiler-explorer
require('packer').startup(function()
use {'krady21/compiler-explorer.nvim'}
end
require("paq") {
{'krady21/compiler-explorer.nvim'};
}
Plug 'krady21/compiler-explorer.nvim'
The suggested way to use
compiler-explorer.nvim is
through the vim commands provided. You can refer to :h compiler-explorer-commands
or the table below:
Command | Description | Called from |
---|---|---|
:CECompile |
Compile the source code in the current buffer and dump assembly output to a new window. Also accepts a visual selection. | source code buffer |
:CECompileLive |
Same as :CECompile , but it will also try to recompile the source code every time the buffer is saved. |
source code buffer |
:CEFormat |
Format the source code. | source code buffer |
:CEAddLibrary |
Add a library to be used by future calls of :CECompile . |
source code buffer |
:CELoadExample |
Load an existing code example to a new tab. | any buffer |
:CEOpenWebsite |
Open the website using the source code and compilers from previous :CECompile calls. |
any buffer |
:CEDeleteCache |
Clear the json cache where the compilers and languages are stored. | any buffer |
:CEShowTooltip |
Show information about a specific instruction under cursor. | assembly buffer |
:CEGotoLabel |
Jump to the label definition under cursor. | assembly buffer |
Examples
:CECompile
will prompt the user to select the compiler and flags interactively usingvim.ui.select
andvim.ui.input
.:CECompile compiler=g121 flags=-O2 flags=-Wall
specify the compiler and flags as command arguments.':<,'>CECompile
will compile a visual selection.:CECompile!
will open the assembly output in a new window. Not adding bang (!) will reuse the last assembly window.:CECompile inferLang=false
do not infer possible language (based on file extension). Will prompt user to select the language before selecting the compiler.:CECompile binary=true
show binary opcodes and address using virtual text.:CECompile intel=false
use AT&T syntax instead of intel.:CECompileLive
creates an autcommand that runs:CECompile
every time the buffer is saved (BufWritePost
).
compiler-explorer.nvim
works out of the box without configuration. If you want to change some of its
options (like using a local instance of compiler-explorer), you can do so
through the setup()
function.
Default options
require("compiler-explorer").setup({
url = "https://godbolt.org",
infer_lang = true, -- Try to infer possible language based on file extension.
line_match = {
highlight = false, -- highlight the matching line(s) in the other buffer.
jump = false, -- move the cursor in the other buffer to the first matching line.
},
open_qflist = false, -- Open qflist after compilation if there are diagnostics.
split = "split", -- How to split the window after the second compile (split/vsplit).
compiler_flags = "", -- Default flags passed to the compiler.
job_timeout_ms = 25000, -- Timeout for libuv job in milliseconds.
languages = { -- Language specific default compiler/flags
--c = {
-- compiler = "g121",
-- compiler_flags = "-O2 -Wall",
--},
},
})
-
GET /api/languages
-
GET /api/compilers/<lang-id>
-
GET /api/libraries/<lang-id>
-
GET /api/shortlinkinfo/<link-id>
-
POST /api/compiler/<compiler-id>/compile
-
GET /api/formats
-
POST /api/format/<formatter>
-
GET /api/asm/<instruction-set>/<instruction>
-
GET /source/builtin/list
-
GET /source/builtin/load/<lang-id>/<example-id>
-
GET /clientstate/<base64>
You can find the full API docs here.
- The async.lua and alert.lua modules are inspired from gitsigns.nvim .
- The base64.lua module is taken from lbase64