Skip to content

Commit

Permalink
Initial PoC works
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Nov 14, 2023
1 parent 19ce4c1 commit d500303
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 78 deletions.
2 changes: 1 addition & 1 deletion autoload/clap/api.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ else
endfunction
endif

function! s:api.get_screenlinesrange() abort
function! s:api.get_screen_lines_range() abort
return [win_getid(), line('w0'), line('w$')]
endfunction

Expand Down
23 changes: 20 additions & 3 deletions autoload/clap/highlighter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ set cpoptions&vim

let s:default_priority = 10

if has('nvim')
let s:tree_sitter_ns_id = nvim_create_namespace('clap_tree_sitter_highlight')
else
let s:ts_types = []
endif

if has('nvim')
" lnum is 0-based.
function! s:add_highlight_at(bufnr, lnum, col, length, hl_group) abort
call nvim_buf_add_highlight(a:bufnr, -1, a:hl_group, a:lnum, a:col, a:col+a:length)
endfunction

" lnum is 0-based.
function! s:add_ts_highlight_at(bufnr, lnum, col, length, hl_group) abort
call nvim_buf_add_highlight(a:bufnr, s:tree_sitter_ns_id, a:hl_group, a:lnum, a:col, a:col+a:length)
endfunction

" lnum and col are 0-based.
function! s:add_highlight_at_using_matchaddpos(lnum, col, hl_group) abort
return matchaddpos(a:hl_group, [[a:lnum+1, a:col+1, 1]])
Expand Down Expand Up @@ -132,16 +143,22 @@ function! clap#highlighter#highlight_line(bufnr, lnum, token_highlights) abort
endfor
endfunction

function! clap#highlighter#add_ts_highlights(bufnr, highlights) abort
if has('nvim')
call nvim_buf_clear_namespace(a:bufnr, s:tree_sitter_ns_id, 0, -1)
else
call prop_remove({ 'types': s:ts_types, 'all': v:true, 'bufnr': a:bufnr } )
endif

function! clap#highlighter#add_line_highlights(bufnr, highlights) abort
for [line_number, highlights] in a:highlights
for [column_start, length, group_name] in highlights
if !has('nvim')
if empty(prop_type_get(group_name))
call prop_type_add(group_name, {'highlight': group_name})
call add(s:ts_types, 'clap_ts_'.group_name)
call prop_type_add('clap_ts_'.group_name, {'highlight': group_name})
endif
endif
call s:add_highlight_at(a:bufnr, line_number, column_start, length, group_name)
call s:add_ts_highlight_at(a:bufnr, line_number, column_start, length, group_name)
endfor
endfor
endfunction
Expand Down
2 changes: 1 addition & 1 deletion crates/maple_core/src/stdio_server/plugin/cursorword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Cursorword {
}

// Lines in view.
let (winid, line_start, line_end) = self.vim.get_screenlinesrange().await?;
let (winid, line_start, line_end) = self.vim.get_screen_lines_range().await?;

let maybe_new_highlights = if self.vim.bufmodified(bufnr).await? {
let lines = self.vim.getbufline(bufnr, line_start, line_end).await?;
Expand Down
6 changes: 6 additions & 0 deletions crates/maple_core/src/stdio_server/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ impl Toggle {
}
}

pub fn turn_on(&mut self) {
if self.is_off() {
*self = Self::On;
}
}

pub fn is_off(&self) -> bool {
matches!(self, Self::Off)
}
Expand Down
Loading

0 comments on commit d500303

Please sign in to comment.