From 46545bbdb6a6a29bba722b2fb79d1701fd8a1cf9 Mon Sep 17 00:00:00 2001 From: MarcHamamji Date: Fri, 7 Apr 2023 23:01:37 +0300 Subject: [PATCH 1/6] Add ability to set shell_handler position using telescope --- README.md | 10 ++++++++-- lua/runner/handlers/helpers.lua | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2afe201..5e67581 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,9 @@ A customizable Neovim plugin to run code inside the editor Runner comes with the following defaults: ```lua require('runner').setup({ - position = 'right', -- position of the terminal window when using the shell_handler - can be: top, left, right, bottom + position = 'right', -- position of the terminal window when using the shell_handler + -- can be: top, left, right, bottom + -- will be overwritten when using the telescope mapping to open horizontally or vertically width = 80, -- width of window when position is left or right height = 10, -- height of window when position is top or bottom }) @@ -104,7 +106,11 @@ A customizable Neovim plugin to run code inside the editor - #### `shell_handler(command, editable)` Runs a command in a shell by opening it in a new split window, with a terminal buffer. - + + + The split window's position will be determined by the `position` value from the config. It will be overwritten when using the telescope mapping to open horizontally or vertically. + + | Argument name | Description | Type | |---------------- | --------------- | --------------- | | `command` | The shell command to run when the handler is called | `string` | diff --git a/lua/runner/handlers/helpers.lua b/lua/runner/handlers/helpers.lua index f787eed..e46233e 100644 --- a/lua/runner/handlers/helpers.lua +++ b/lua/runner/handlers/helpers.lua @@ -5,6 +5,7 @@ local action_state = require('telescope.actions.state') local sorters = require('telescope.sorters') local themes = require('telescope.themes') +local config = require('runner.config') local utils = require('runner.handlers.utils') local M = {} @@ -60,6 +61,26 @@ M.choice = function(handlers) local handler_name = action_state.get_selected_entry()[1] handlers[handler_name](buffer) end) + actions.select_horizontal:replace(function() + local default_position = config.options.position + config.options.position = 'bottom'; + + actions.close(prompt_bufnr) + local handler_name = action_state.get_selected_entry()[1] + handlers[handler_name](buffer) + + config.options.position = default_position; + end) + actions.select_vertical:replace(function() + local default_position = config.options.position + config.options.position = 'top'; + + actions.close(prompt_bufnr) + local handler_name = action_state.get_selected_entry()[1] + handlers[handler_name](buffer) + + config.options.position = default_position; + end) return true end, } From c2deea1515a0d8e17aded0048232b3bdb26c4483 Mon Sep 17 00:00:00 2001 From: MarcHamamji Date: Fri, 7 Apr 2023 23:08:49 +0300 Subject: [PATCH 2/6] Lint --- lua/runner/handlers/helpers.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/runner/handlers/helpers.lua b/lua/runner/handlers/helpers.lua index e46233e..7f3e91a 100644 --- a/lua/runner/handlers/helpers.lua +++ b/lua/runner/handlers/helpers.lua @@ -63,23 +63,23 @@ M.choice = function(handlers) end) actions.select_horizontal:replace(function() local default_position = config.options.position - config.options.position = 'bottom'; + config.options.position = 'bottom' actions.close(prompt_bufnr) local handler_name = action_state.get_selected_entry()[1] handlers[handler_name](buffer) - config.options.position = default_position; + config.options.position = default_position end) actions.select_vertical:replace(function() local default_position = config.options.position - config.options.position = 'top'; + config.options.position = 'top' actions.close(prompt_bufnr) local handler_name = action_state.get_selected_entry()[1] handlers[handler_name](buffer) - config.options.position = default_position; + config.options.position = default_position end) return true end, From 05ff43760a67ce5b5e56099d274ef5d091db3194 Mon Sep 17 00:00:00 2001 From: MarcHamamji Date: Fri, 7 Apr 2023 23:19:02 +0300 Subject: [PATCH 3/6] Update docs --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5e67581..b3e0862 100644 --- a/README.md +++ b/README.md @@ -107,9 +107,10 @@ A customizable Neovim plugin to run code inside the editor Runs a command in a shell by opening it in a new split window, with a terminal buffer. - The split window's position will be determined by the `position` value from the config. It will be overwritten when using the telescope mapping to open horizontally or vertically. - + - `select_horizontal` (defaults to ``): Opens the window at the bottom of the screen. + - `select_vertical` (defaults to ``): Opens the window at the right of the screen. +
| Argument name | Description | Type | |---------------- | --------------- | --------------- | From 4a6d3b805050425e8a7a2b89cb63b7a1456387ee Mon Sep 17 00:00:00 2001 From: MarcHamamji Date: Sat, 8 Apr 2023 12:37:39 +0300 Subject: [PATCH 4/6] Make the pre-commit hook use the stylua binary installed on the system --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 79b58bc..b707f60 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,4 +2,4 @@ repos: - repo: https://github.com/JohnnyMorganz/StyLua rev: v0.17.1 hooks: - - id: stylua-github + - id: stylua-system From df4b4d674ff3b4c2169dcd2058fb256f63a3667c Mon Sep 17 00:00:00 2001 From: MarcHamamji Date: Sat, 8 Apr 2023 12:57:19 +0300 Subject: [PATCH 5/6] Add more docs for contributing --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b3e0862..48d23e2 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,27 @@ A customizable Neovim plugin to run code inside the editor ## Contribution - If you find that some handlers for a specific language are missing, feel free to open a pull request by adding them in the [lua/runner/handlers/init.lua](lua/runner/handlers/init.lua) file. + This project uses [StyLua](https://github.com/JohnnyMorganz/StyLua) for enforcing code style, and has a [pre-commit](https://pre-commit.com/) hook setup for running it automatically. `runner.nvim` also has a Github Action that runs the linter on every Pull request. If a check doesn't pass on a specific Pull request, please lint the code and commit it again. + + For running them locally, you have to have them installed on your system: + - [StyLua Installation](https://github.com/JohnnyMorganz/StyLua#installation) + - [pre-commit Installation](https://pre-commit.com/#install) + + #### Some useful commands: + + - Install the pre-commit hook + ```bash + pre-commit install + ``` + + - Check for StyLua errors + ```bash + stylua --check lua/ + ``` + + - Fix StyLua errors + ```bash + stylua lua/ + ``` Licensed under the [MIT license](./LICENSE). From e7a0b920382c3688ebaaaceb74c82261c3d3d016 Mon Sep 17 00:00:00 2001 From: MarcHamamji Date: Sat, 8 Apr 2023 13:06:52 +0300 Subject: [PATCH 6/6] Add docs for `run` function --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48d23e2..53e276a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ A customizable Neovim plugin to run code inside the editor ## Usage ```lua - require('runner').run() + require('runner').run() -- Can also be called with the buffer number where the code is -- To set a mapping vim.keymap.set('n', '', require('runner').run)