diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 050211a..f8ed013 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -49,7 +49,7 @@ jobs: - name: Push Changes uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "docs(vimdoc): Auto-generate user / API documentation + vimtags" + commit_message: "docs: Auto-generate user / API documentation + vimtags" commit_user_name: "github-actions[bot]" commit_user_email: "github-actions[bot]@users.noreply.github.com" commit_author: "github-actions[bot] " diff --git a/README.md b/README.md index 3d5fb36..151928a 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Acts as a user friendly replacement of command mode - messages loop and as a handy scratch pad to store and test your code gists. -***Update: although it originated as a tool for Lua development, it has now evolved into supporting other languages too. See [`evaluating other languages`](#evaluating-other-languages).*** +**Update:** although it originated as a tool for Lua development, it has now evolved into supporting other languages too. See [`evaluating other languages`](#evaluating-other-languages). -
+
## 💡 Motivation diff --git a/doc/demo.gif b/doc/demo.gif deleted file mode 100644 index 646ada0..0000000 Binary files a/doc/demo.gif and /dev/null differ diff --git a/doc/demo.jpg b/doc/demo.jpg deleted file mode 100644 index a8a7712..0000000 Binary files a/doc/demo.jpg and /dev/null differ diff --git a/lua/lua-console.lua b/lua/lua-console.lua index 9cda634..2d4c177 100644 --- a/lua/lua-console.lua +++ b/lua/lua-console.lua @@ -21,6 +21,8 @@ local get_or_create_buffer = function() injections.set_highlighting() vim.api.nvim_set_option_value('filetype', 'lua', { buf = buf }) + vim.api.nvim_set_option_value('syntax', 'lua', { buf = buf }) + vim.diagnostic.enable(false, { bufnr = buf }) mappings.set_console_mappings(buf) diff --git a/lua/lua-console/injections.lua b/lua/lua-console/injections.lua index 9c9b478..a5b7822 100644 --- a/lua/lua-console/injections.lua +++ b/lua/lua-console/injections.lua @@ -6,23 +6,31 @@ M.set_highlighting = function() local lang_prefix = config.external_evaluators.lang_prefix local lang_pattern = ('^%s([^\\n]-)\\n.+$'):format(lang_prefix) - vim.treesitter.query.add_directive('indent!', function(_, _, _, predicate, metadata) + vim.treesitter.query.add_directive('deindent!', function(_, _, _, predicate, metadata) -- remove indentaion in the region local capture_id = predicate[2] if not metadata[capture_id].range then return end metadata[capture_id].range[2] = tonumber(predicate[3]) -- set indent col to 0 end, { all = true, force = true }) + local function extend_query(query) + local extended = '' + vim.tbl_map(function(path) + extended = extended .. io.open(path):read("*a") .. '\n' + end, vim.treesitter.query.get_files('lua', 'injections')) + + return extended .. query + end + local query = ([[ ;query - ; extends - (string - content: (string_content) @injection.language @injection.content + ((string_content) @injection.language @injection.content (#lua-match? @injection.language "^@1") (#gsub! @injection.language "@2" "%1") (#offset! @injection.content 1 0 0 0) - (#indent! @injection.content 0)) + (#deindent! @injection.content 0)) ]]):gsub('@1', lang_prefix):gsub('@2', lang_pattern) + query = extend_query(query) vim.treesitter.query.set('lua', 'injections', query) end diff --git a/lua/lua-console/utils.lua b/lua/lua-console/utils.lua index 8d44217..099d992 100644 --- a/lua/lua-console/utils.lua +++ b/lua/lua-console/utils.lua @@ -19,8 +19,14 @@ local to_string = function(tbl, sep, trim) return line end -local to_table = function(str) - return vim.split(str or '', '\n', { trimempty = true }) +---@param obj string|string[] +---@return string[] +local to_table = function(obj) + obj = type(obj) == 'string' and { obj } or obj + + return vim.iter(obj):map(function(line) + return vim.split(line or '', '\n', { trimempty = true }) + end):flatten():totable() end local function remove_indentation(tbl) @@ -141,11 +147,14 @@ local append_current_buffer = function(buf, lines) local lnum = vim.fn.line('.') local prefix = config.buffer.result_prefix + local empty_results = { 'nil', '', '""', "''" } local virtual_text - if lines[#lines] == 'nil' then + local line = lines[#lines] + + if vim.tbl_contains(empty_results, line) then table.remove(lines) - virtual_text = 'nil' + virtual_text = line end local assignment_value = get_assignment(vim.fn.getbufline(buf, lnum, lnum)) @@ -181,7 +190,7 @@ local pretty_print = function(...) result = to_table(result) vim.list_extend(print_buffer, result) - return result + -- return result end local function remove_empty_lines(tbl) @@ -424,14 +433,16 @@ local load_messages = function(buf) ---This way we catch the output of messages command, in case it was overriden by some other plugin, like Noice vim.ui_attach(ns, { ext_messages = true }, function(event, entries) ---@diagnostic disable-line if event ~= 'msg_history_show' then return end + local messages = vim.tbl_map(function(e) return e[2][1][2] end, entries) + if #messages == 0 then return end vim.schedule(function() - append_current_buffer(buf, messages) vim.api.nvim_input('') -- forcing to redraw buffer + append_current_buffer(buf, to_table(messages)) end) end)