Skip to content

Commit a731213

Browse files
committed
specs: update
1 parent 46d0273 commit a731213

File tree

17 files changed

+81
-364
lines changed

17 files changed

+81
-364
lines changed

.busted

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/test_develop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: develop
2+
name: Tests
33
on:
44
pull_request: ~
55
push:

.github/workflows/test_main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: main
2+
name: Tests
33
on:
44
pull_request: ~
55
push:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.todo.md
2+
.tests

Makefile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
set_lua_paths = eval $$(luarocks path --lua-version 5.1 --bin)
2-
busted = $$(find /usr/local/lib/luarocks/*/busted/* -name busted)
3-
set_luals_path = PATH="$$PATH:/home/yaro/.local/share/nvim/mason/bin/lua-language-server"
4-
5-
test_unit = busted --run=unit
6-
test_nvim = nvim --headless -i NONE -n -u spec/minimal_init.lua -l $(busted) --run=unit
1+
test=nvim -l tests/minit.lua tests -o utfTerminal -Xoutput --color -v
2+
#--shuffle-tests
73

84
tag ?= wip
95
watch = '*.lua'
@@ -19,19 +15,19 @@ llscheck:
1915
@$(set_luals_path) && llscheck --configpath .luarc.json .
2016

2117
luacheck:
22-
luacheck lua spec scripts
18+
luacheck lua tests scripts
2319

2420
stylua:
2521
stylua --check lua scripts spec
2622

2723
test:
28-
@$(set_lua_paths); $(test_unit)
24+
@$(test)
2925

3026
watch:
31-
@$(set_lua_paths); while sleep 0.1; do find . -name $(watch) | entr -d -c $(test_unit); done
27+
@while sleep 0.1; do find . -name $(watch) | entr -d -c $(test); done
3228

3329
watch_tag:
34-
@$(set_lua_paths); while sleep 0.1; do find . -name $(watch) | entr -d -c $(test_unit) --tags=$(tag); done
30+
@while sleep 0.1; do find . -name $(watch) | entr -d -c $(test) --tags=$(tag); done
3531

3632
test_nvim:
3733
@$(test_nvim) spec/unit

README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 💻 Lua console ![main](https://github.com/yarospace/lua-console.nvim/actions/workflows/test_main.yml/badge.svg?branch=main) ![develop](https://github.com/yarospace/lua-console.nvim/actions/workflows/test_develop.yml/badge.svg?branch=develop) [![LuaRocks](https://img.shields.io/luarocks/v/YaroSpace/lua-console.nvim?logo=lua&color=purple)](https://luarocks.org/modules/YaroSpace/lua-console.nvim)
22

3-
**lua-console.nvim** - is a REPL / scratch pad / debug console for Neovim. Supports Lua natively and can be extended for other languages.
3+
**lua-console.nvim** - is a REPL / scratch pad / debug console for Neovim.
4+
Supports Lua natively and can be extended for other languages.
45

56
<br/><img src="https://github.com/YaroSpace/assets/blob/main/lua-console.nvim/demo.gif">
67

@@ -16,8 +17,6 @@
1617
- Use as a scratch pad for code gists
1718
- Attach code evaluators to any buffer
1819

19-
<br>
20-
2120
## 📦 Installation
2221

2322
With [lazy.nvim](https://github.com/folke/lazy.nvim):
@@ -46,8 +45,8 @@ require('lua-console').setup { your_custom_options }
4645
> [!NOTE]
4746
> All settings are self explanatory, but please read below about [`preserve_context`](#-notes-on-globals-locals-and-preserving-execution-context) option.
4847
49-
Mappings are local to the console, except the ones for toggling the console - `` ` `` and attaching to a buffer - ``<Leader>` ``. All mappings can be overridden in your custom
50-
config. If you want to delete a mapping - set its value to `false`.
48+
Mappings are local to the console, except the ones for toggling the console - `` ` `` and attaching to a buffer - ``<Leader>` ``.
49+
All mappings can be overridden in your custom config. If you want to delete a mapping - set its value to `false`.
5150

5251
<details><summary>Default Settings</summary>
5352

@@ -93,8 +92,6 @@ opts = {
9392

9493
</details>
9594

96-
<br>
97-
9895
## 🚀 Basic usage (with default mappings)
9996

10097
- Install, press the mapped key `` ` `` and start exploring.
@@ -124,10 +121,11 @@ opts = {
124121
> [!IMPORTANT]
125122
> By default, the option `preserve_context` is on, which means that the execution context is preserved between evaluations.
126123
127-
All the code executed in the console is evaluated in isolated environment, which means that any global variables that you declare will not be persisted
128-
in Neovim's global environment. If you purposefully want to alter the global state, use `_G.My_variable = ..`.
124+
All the code executed in the console is evaluated in isolated environment, which means that any global variables that you declare will not be persisted in Neovim's global environment.
125+
If you purposefully want to alter the global state, use `_G.My_variable = ..`.
129126

130127
The option `preserve_context` implies that variables without `local` will be stored in the console's local context and preserved between executions.
128+
131129
So, if you first execute `a = 1`, then `a = a + 1` and then `a` - you will get `2`.
132130

133131
Also, by default, the option `strip_local` is on, which means that `local` modifier is stripped from top-level variable declarations and these variables are also stored in the context.
@@ -139,8 +137,6 @@ There are two functions available within the console:
139137
- `_ctx` - will print the contents of the context
140138
- `_ctx_clear()` - clears the context
141139

142-
<br>
143-
144140
## ⭐ Extra features
145141

146142
### Attaching code evaluator to other buffers

lua/lua-console/utils.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,18 @@ local function strip_local(lines)
359359
local ts = vim.treesitter
360360
local ret = {}
361361

362-
local start_row = vim.fn.line('.') - 1 - #lines
362+
local start_row = math.max(0, vim.fn.line('.') - 1 - #lines)
363363

364364
for i, line in ipairs(lines) do
365-
local col = line:find('^%s*local%s+')
365+
local cs, ce = 1, 1
366366

367-
if col then
368-
local node = ts.get_node { pos = { start_row + i, col } }
369-
line = node and node:parent():type() == 'chunk' and line:gsub('^%s*local%s+', '') or line
367+
while cs do
368+
cs, ce = line:find('local%s', ce)
369+
370+
if cs then
371+
local node = ts.get_node { pos = { start_row + i - 1, cs } }
372+
if node and node:parent():type() == 'chunk' then line = line:sub(1, cs - 1) .. line:sub(ce + 1) end
373+
end
370374
end
371375

372376
table.insert(ret, line)
@@ -470,6 +474,7 @@ local get_external_evaluator = function(buf, lang)
470474
local fun = opts.on_exit
471475
opts.on_exit = function(system_completed)
472476
vim.schedule(function()
477+
if not vim.api.nvim_buf_is_valid(buf) then return end
473478
vim.api.nvim_buf_del_extmark(buf, ns, 10)
474479
_ = fun and fun(system_completed)
475480
end)

spec/log.lua

Lines changed: 0 additions & 46 deletions
This file was deleted.

spec/minimal_init.lua

Lines changed: 0 additions & 2 deletions
This file was deleted.

spec/nvim-shim.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)