diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e7ed9bc..6a325da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,83 +1,96 @@ name: CI on: push: { branches: ["0.x"] } pull_request: { branches: ["0.x"] } jobs: commits: name: Commitlint runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 1000 - name: Lint commits uses: docker://registry.k1.zportal.co.uk/practically-oss/conventional-tools:0.x with: args: conventional-tools commitlint -l1 -f39febd82e236a9c79f5b408e98cbd20410f11e9e luacheck: name: Luacheck runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Install luarocks run: sudo apt update && sudo apt install -y luarocks - name: Install luacheck run: sudo luarocks install luacheck - name: Run luacheck run: luacheck . + stylua: + name: StyLua + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run stylua + uses: JohnnyMorganz/stylua-action@1.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --check . + clang-format: name: Clang Format runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Install Dependencies run: sudo apt-get update && sudo apt-get install --no-install-recommends -y clang-format findutils - name: Run clang format run: find ./cpp -name "*.cpp" -o -name "*.hpp" | xargs clang-format -Werror --dry-run cargo-format: name: Cargo Format runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Run cargo format uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check test: name: Build and test runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Install rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable - name: Install dependencies run: sudo apt update && sudo apt install -y luajit build-essential - name: Build run: cargo build --release - name: Test run: find lua -name "*_test.lua" | xargs luajit scripts/test.lua diff --git a/lua/ivy/controller.lua b/lua/ivy/controller.lua index 0fe3b5c..306acb0 100644 --- a/lua/ivy/controller.lua +++ b/lua/ivy/controller.lua @@ -1,83 +1,83 @@ local window = require "ivy.window" local prompt = require "ivy.prompt" local controller = {} controller.items = nil controller.callback = nil controller.run = function(name, items, callback) controller.callback = callback controller.items = items window.initialize() - window.set_items { { content = "-- Loading ---" } } + window.set_items { { content = "-- Loading ---" } } vim.api.nvim_buf_set_name(window.get_buffer(), name) controller.input "" end controller.input = function(char) prompt.input(char) controller.update(prompt.text()) end controller.search = function(value) prompt.set(value) controller.update(prompt.text()) end controller.update = function(text) vim.schedule(function() window.set_items(controller.items(text)) - vim.cmd("syntax clear IvyMatch") + vim.cmd "syntax clear IvyMatch" vim.cmd("syntax match IvyMatch '[(" .. text .. ")]'") end) end controller.complete = function() vim.api.nvim_set_current_win(window.origin) controller.callback(window.get_current_selection()) controller.destroy() end controller.checkpoint = function() vim.api.nvim_set_current_win(window.origin) controller.callback(window.get_current_selection()) vim.api.nvim_set_current_win(window.window) end controller.next = function() local max = vim.api.nvim_buf_line_count(window.buffer) - 1 if window.index == max then return end window.index = window.index + 1 window.update() end controller.previous = function() if window.index == 0 then return end window.index = window.index - 1 window.update() end controller.origin = function() return vim.api.nvim_win_get_buf(window.origin) end controller.destroy = function() controller.items = nil controller.callback = nil window.destroy() prompt.destroy() end return controller diff --git a/lua/ivy/libivy.lua b/lua/ivy/libivy.lua index 0377b2e..f1267f5 100644 --- a/lua/ivy/libivy.lua +++ b/lua/ivy/libivy.lua @@ -1,34 +1,34 @@ local library_path = (function() local dirname = string.sub(debug.getinfo(1).source, 2, #"/fzf_lib.lua" * -1) return dirname .. "/../../target/release/libivyrs.so" end)() local ffi = require "ffi" local ivy_c = ffi.load(library_path) ffi.cdef [[ void ivy_init(const char*); char* ivy_cwd(); int ivy_match(const char*, const char*); char* ivy_files(const char*, const char*); ]] local libivy = {} libivy.ivy_init = function(dir) ivy_c.ivy_init(dir) end -libivy.ivy_cwd = function () - return ffi.string(ivy_c.ivy_cwd()) +libivy.ivy_cwd = function() + return ffi.string(ivy_c.ivy_cwd()) end libivy.ivy_match = function(pattern, text) return ivy_c.ivy_match(pattern, text) end libivy.ivy_files = function(pattern, base_dir) return ffi.string(ivy_c.ivy_files(pattern, base_dir)) end return libivy diff --git a/lua/ivy/libivy_test.lua b/lua/ivy/libivy_test.lua index 519361a..4f4426f 100644 --- a/lua/ivy/libivy_test.lua +++ b/lua/ivy/libivy_test.lua @@ -1,18 +1,18 @@ local libivy = require "ivy.libivy" it("should run a simple match", function(t) local score = libivy.ivy_match("term", "I am a serch term") if score <= 0 then t.error("Score should not be less than 0 found " .. score) end end) -it("should find a dot file", function (t) +it("should find a dot file", function(t) local current_dir = libivy.ivy_cwd() - local matches = libivy.ivy_files("ci.yml", current_dir); + local matches = libivy.ivy_files("ci.yml", current_dir) if matches ~= ".github/workflows/ci.yml\n" then t.error("Invalid matches: " .. matches) end -end); +end) diff --git a/lua/ivy/window.lua b/lua/ivy/window.lua index 0a45a46..ea94ec3 100644 --- a/lua/ivy/window.lua +++ b/lua/ivy/window.lua @@ -1,142 +1,142 @@ -- Constent options that will be used for the keymaps local opts = { noremap = true, silent = true, nowait = true } -- All of the base chars that will be used for an "input" operation on the -- prompt -- stylua: ignore local chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "<", ">", "`", "@", "#", "~", "!", "\"", "$", "%", "^", "&", "/", "(", ")", "=", "+", "*", "-", "_", ".", ",", ";", ":", "?", "\\", "|", "'", "{", "}", "[", "]", " ", } local function string_to_table(lines) local matches = {} for line in lines:gmatch "[^\r\n]+" do table.insert(matches, { content = line }) end return matches end local window = {} window.index = 0 window.origin = nil window.window = nil window.buffer = nil window.initialize = function() window.make_buffer() end window.make_buffer = function() window.origin = vim.api.nvim_get_current_win() vim.api.nvim_command "botright split new" window.buffer = vim.api.nvim_win_get_buf(0) window.window = vim.api.nvim_get_current_win() vim.api.nvim_win_set_option(window.window, "number", false) vim.api.nvim_win_set_option(window.window, "relativenumber", false) vim.api.nvim_win_set_option(window.window, "signcolumn", "no") vim.api.nvim_buf_set_option(window.buffer, "filetype", "ivy") vim.api.nvim_buf_set_var(window.buffer, "bufftype", "nofile") for index = 1, #chars do local char = chars[index] if char == "'" then char = "\\'" end if char == "\\" then char = "\\\\\\\\" end vim.api.nvim_buf_set_keymap(window.buffer, "n", chars[index], "lua vim.ivy.input('" .. char .. "')", opts) end vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.destroy()", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.search('')", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.next()", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.previous()", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.next(); vim.ivy.checkpoint()", opts) vim.api.nvim_buf_set_keymap( window.buffer, "n", "", "lua vim.ivy.previous(); vim.ivy.checkpoint()", opts ) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.complete()", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.input('BACKSPACE')", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.input('LEFT')", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.input('RIGHT')", opts) vim.api.nvim_buf_set_keymap(window.buffer, "n", "", "lua vim.ivy.input('DELETE_WORD')", opts) end window.get_current_selection = function() local line = vim.api.nvim_buf_get_lines(window.buffer, window.index, window.index + 1, true) if line == nil then line = { "" } end return line[1] end window.get_buffer = function() if window.buffer == nil then window.make_buffer() end return window.buffer end window.update = function() vim.api.nvim_win_set_cursor(window.window, { window.index + 1, 0 }) end window.set_items = function(items) if type(items) == "string" then items = string_to_table(items) end -- TODO(ade): Validate the items are in the correct format. This also need to -- come with some descriptive messages and possible help. -- Display no items text if there are no items to dispaly if #items == 0 then - items = { { content = "-- No Items --" } } + items = { { content = "-- No Items --" } } end local items_length = #items window.index = items_length - 1 for index = 1, items_length do vim.api.nvim_buf_set_lines(window.buffer, index - 1, -1, false, { items[index].content }) end -- Limit the results window size to 10 so when there are lots of results the -- window does not take up the hole terminal local line_count = items_length if line_count > 10 then line_count = 10 end vim.api.nvim_win_set_height(window.window, line_count) window.update() end window.destroy = function() if type(window.buffer) == "number" then vim.api.nvim_buf_delete(window.buffer, { force = true }) end window.buffer = nil window.window = nil window.origin = nil window.index = 0 end return window