Git Product home page Git Product logo

compiler-explorer.nvim's Introduction

compiler-explorer.nvim

License: MIT

Compile your code and explore assembly from Neovim using the compiler-explorer REST API. Supercharged by vim.ui, vim.notify and vim.diagnostic.

FeaturesDependenciesInstallCommandsConfiguration

Demo

Preview 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.

Features

  • 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).

Dependencies

You can verify these dependencies by running :checkhealth compiler-explorer

Recommended
dressing.nvim or another plugin that overrides vim.ui
Optional
nvim-notify or another plugin that overrides vim.notify

Installation

packer

require('packer').startup(function()
  use {'krady21/compiler-explorer.nvim'}
end

paq

require("paq") {
  {'krady21/compiler-explorer.nvim'};
}

vim-plug

Plug 'krady21/compiler-explorer.nvim'

Commands

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 using vim.ui.select and vim.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).

Configuration

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",
    --},
  },
})

API Coverage:

  • 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.

Related projects

Inspiration

  • The async.lua and alert.lua modules are inspired from gitsigns.nvim .
  • The base64.lua module is taken from lbase64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.