Skip to content
This repository was archived by the owner on Feb 23, 2025. It is now read-only.

Commit

Permalink
Merge pull request #441 from liquidz/dev
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
liquidz authored Sep 9, 2022
2 parents f89c57b + 06ade39 commit d53c14b
Show file tree
Hide file tree
Showing 36 changed files with 875 additions and 193 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ All notable changes to this project will be documented in this file. This change

== Unreleased (dev)

// {{{
=== Added

* Added support for virtual text in Vim9.
** Requires Vim 9.0.297 or later.
* Added bencode component using Vim9 script.
* Added `g:iced#eval#popup_align` option.
* Added spinner while code is evaluating.
** Added `g:iced#eval#popup_spinner_texts` option.
** Added `g:iced#eval#popup_spinner_interval` option.
* Added `IcedIsolatedEval` command.
* Added `IcedEvalInContextAtMark` command.

=== Changed
* Bumped iced-nrepl to 1.2.465.
* Bumped joker to 1.0.1.

=== Fixed
* Fixed neovim virtual text component to use `nvim_buf_set_extmark`.
* Fixed neovim virtual text component to clear a virtual text on the same line.
* Fixed neovim virtual text component to set virtual text on correct line.
* Fixed to clear virtual texts when code evaluation is interrupted
// }}}

== 3.11.3086 (2022-08-29)
// {{{
=== Added
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,7 @@ outdated:
.PHONY: repl
repl:
clojure -R:jackin:dev -m iced-repl

.PHONY: benchmark
benchmark:
vim -u NONE -i NONE -n -N --cmd 'source scripts/bencode_benchmark.vim'
132 changes: 132 additions & 0 deletions autoload/iced/component/bencode/bencode.vim9script
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
if !has('vim9script') | finish | endif
vim9script

def EncodeString(s: string): string
return printf('%d:%s', strlen(s), s)
enddef

def EncodeNumber(i: number): string
return printf('i%de', i)
enddef

def EncodeList(coll: list<any>): string
var result: list<string> = []
for x in coll
add(result, Encode(x))
endfor
return printf('l%se', join(result, ''))
enddef

def EncodeDictionary(dict: dict<any>): string
var result: list<string> = []
for k in keys(dict)
add(result, Encode(k))
add(result, Encode(dict[k]))
endfor
return printf('d%se', join(result, ''))
enddef

export def Encode(x: any): string
const t = type(x)
if t == v:t_string
return EncodeString(x)
elseif t == v:t_number
return EncodeNumber(x)
elseif t == v:t_list
return EncodeList(x)
elseif t == v:t_dict
return EncodeDictionary(x)
elseif t == 7 # v:none or v:null
return EncodeString('')
endif
return ''
enddef

def DecodeString(s: string): dict<any>
const i = stridx(s, ':')
if i == -1
throw 'Failed to parse string token'
endif
const len = str2nr(strpart(s, 0, i))
return {'value': strpart(s, i + 1, len), 'rest': strpart(s, i + len + 1)}
enddef

def DecodeNumber(s: string): dict<any>
const i = stridx(s, 'e')
if i == -1
throw 'Failed to parse integer token'
endif
return {'value': str2nr(strpart(s, 1, i - 1)), 'rest': strpart(s, i + 1)}
enddef

def DecodeList(s: string): dict<any>
var result: list<any> = []
var tmp = strpart(s, 1)

while tmp[0] != 'e'
const decoded = DecodeRaw(tmp)
add(result, decoded.value)
tmp = trim(decoded.rest)
endwhile

return {'value': result, 'rest': strpart(tmp, 1)}
enddef

def DecodeDictionary(s: string): dict<any>
var result: dict<any> = {}
var tmp = strpart(s, 1)

while tmp[0] != 'e'
const k = DecodeRaw(tmp)
const v = DecodeRaw(trim(k.rest))
result[k.value] = v.value
tmp = trim(v.rest)
endwhile

return {'value': result, 'rest': strpart(tmp, 1)}
enddef

def DecodeRaw(s: string): dict<any>
const c = s[0]
var result: dict<any> = {}

if c == 'i'
result = DecodeNumber(s)
elseif c =~ '[0-9]'
result = DecodeString(s)
elseif c == 'l'
result = DecodeList(s)
elseif c == 'd'
result = DecodeDictionary(s)
else
throw 'Failed to parse bencode.'
endif

return result
enddef

export def Decode(s: string): any
var result: list<any> = []
var decoding: bool = true
var tmp = s

while decoding
const decoded = DecodeRaw(tmp)
if ! has_key(decoded, 'value')
decoding = false
else
add(result, decoded.value)
tmp = trim(decoded.rest)

if tmp == ''
decoding = false
endif
endif
endwhile

if len(result) == 1
return result[0]
endif
return result
enddef
# vim:ft=vim
22 changes: 22 additions & 0 deletions autoload/iced/component/bencode/vim9.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let s:save_cpo = &cpoptions
set cpoptions&vim

let s:script_path = printf('%s/bencode.vim9script', expand('<sfile>:h'))
import s:script_path as that
let s:bencode = {}

function! s:bencode.encode(v) abort
return s:that.Encode(a:v)
endfunction

function! s:bencode.decode(s) abort
return s:that.Decode(a:s)
endfunction

function! iced#component#bencode#vim9#start(_) abort
call iced#util#debug('start', 'vim9 bencode')
return s:bencode
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo
2 changes: 2 additions & 0 deletions autoload/iced/component/repl/nrepl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ let s:nrepl = {
\ 'disconnect': function('iced#nrepl#disconnect'),
\ 'env': 'nrepl',
\ 'eval_code': function('iced#nrepl#eval#code'),
\ 'eval_code_isolatedy': function('iced#nrepl#eval#code_isolatedly'),
\ 'eval_outer_top_list': function('iced#nrepl#eval#outer_top_list'),
\ 'eval_at_mark': function('iced#repl#eval_at_mark'),
\ 'eval_in_context_at_mark': function('iced#repl#eval_in_context_at_mark'),
\ 'eval_last_outer_top_list': function('iced#repl#eval_last_outer_top_list'),
\ 'eval_raw': function('iced#nrepl#eval'),
\ 'is_connected': function('iced#nrepl#is_connected'),
Expand Down
6 changes: 6 additions & 0 deletions autoload/iced/component/repl/socket_repl.vim
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
let s:save_cpo = &cpoptions
set cpoptions&vim

function! s:not_supported(...) abort
return iced#message#error('not_supported')
endfunction

let s:socket_repl = {
\ 'connect': function('iced#socket_repl#connect'),
\ 'disconnect': function('iced#socket_repl#disconnect'),
\ 'env': 'socket_repl',
\ 'eval_code': function('iced#socket_repl#eval'),
\ 'eval_code_isolatedy': funcref('s:not_supported'),
\ 'eval_outer_top_list': function('iced#socket_repl#eval_outer_top_list'),
\ 'eval_at_mark': function('iced#repl#eval_at_mark'),
\ 'eval_in_context_at_mark': function('iced#repl#eval_in_context_at_mark'),
\ 'eval_last_outer_top_list': function('iced#repl#eval_last_outer_top_list'),
\ 'is_connected': function('iced#socket_repl#is_connected'),
\ 'status': function('iced#socket_repl#status'),
Expand Down
66 changes: 66 additions & 0 deletions autoload/iced/component/spinner.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
let s:save_cpo = &cpoptions
set cpoptions&vim

let s:spinner = {
\ 'timer': '',
\ 'virtual_text': '',
\ 'working_spinners': {},
\ }

function! s:start_spinner__spinner(uniq_key, opt) abort dict
let buffer = get(a:opt, 'buffer', bufnr('%'))
let line = get(a:opt, 'line', line('.'))
let idx = get(a:opt, 'index', 0)
let texts = get(a:opt, 'texts', [' |', ' /', '-', ' \'])
let highlight = get(a:opt, 'highlight', 'Comment')
let align = get(a:opt, 'align', 'after')
let interval = get(a:opt, 'interval', 200)

let idx = idx >= len(texts) ? 0 : idx

if has_key(self.working_spinners, a:uniq_key)
call self.virtual_text.set(texts[idx], {
\ 'highlight': highlight,
\ 'align': align,
\ 'buffer': buffer,
\ 'line': line,
\ 'auto_clear': v:false,
\ 'indent': 0,
\ })

let new_opt = copy(a:opt)
let new_opt['index'] = idx + 1
let new_opt['buffer'] = buffer
let new_opt['line'] = line
return self.timer.start(
\ interval,
\ {-> call(funcref('s:start_spinner__spinner'), [a:uniq_key, new_opt], self)})
endif
endfunction

function! s:spinner.start(uniq_key, opt) abort
" NOTE: Spinner is only supported by Vim9/Neovim
if self.virtual_text.env ==# 'vim8'
return
endif

let self.working_spinners[a:uniq_key] = v:true
return self.timer.start(200, {-> call(funcref('s:start_spinner__spinner'), [a:uniq_key, a:opt], self)})
endfunction

function! s:spinner.stop(uniq_key) abort
if has_key(self.working_spinners, a:uniq_key)
unlet self.working_spinners[a:uniq_key]
endif
endfunction

function! iced#component#spinner#start(this) abort
call iced#util#debug('start', 'spinner')
let d = deepcopy(s:spinner)
let d['timer'] = a:this.timer
let d['virtual_text'] = a:this.virtual_text
return d
endfunction

let &cpoptions = s:save_cpo
unlet s:save_cpo
20 changes: 16 additions & 4 deletions autoload/iced/component/virtual_text/neovim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ let s:save_cpo = &cpoptions
set cpoptions&vim

let s:vt = {
\ 'env': 'neovim',
\ 'timer': '',
\ 'ns': nvim_create_namespace('iced_virtual_text_namespace'),
\ }

function! s:text_align_to_virt_text_pos(align) abort
return get({'after': 'eol', 'right': 'right_align'}, a:align, 'eol')
endfunction

function! s:vt.set(text, ...) abort
let opt = get(a:, 1, {})
let buf = get(opt, 'buffer', bufnr('%'))
let line = get(opt, 'line', line('.') -1)
let line = get(opt, 'line', '')
let line = empty(line) ? line('.') - 1 : line - 1
let hl = get(opt, 'highlight', 'Normal')
call nvim_buf_set_virtual_text(buf, self.ns, line, [[a:text, hl]], {})
let align = get(opt, 'align', 'after')

call nvim_buf_clear_namespace(buf, self.ns, line, line + 1)
call nvim_buf_set_extmark(buf, self.ns, line, 0, {
\ 'virt_text': [[a:text, hl]],
\ 'virt_text_pos': s:text_align_to_virt_text_pos(align)
\ })

if get(opt, 'auto_clear', v:false)
let time = get(opt, 'clear_time', 3000)
Expand All @@ -26,8 +38,8 @@ function! s:vt.clear(...) abort
if empty(opt)
call nvim_buf_clear_namespace(buf, self.ns, 1, line('$'))
else
let line = get(opt, 'line', line('.') -1)
call nvim_buf_clear_namespace(buf, self.ns, line, line + 1)
let line = get(opt, 'line', line('.') - 1)
call nvim_buf_clear_namespace(buf, self.ns, line - 1, line)
endif
endfunction

Expand Down
Loading

0 comments on commit d53c14b

Please sign in to comment.