Skip to content

Commit

Permalink
feat: improve vim extension user experience (TabbyML#71)
Browse files Browse the repository at this point in the history
* chore: checkin dist file for vim extension

* use getbufline

* do not invoke tabby if file type is unknown

* update readme

* Update README.md

* Update README.md

* Update README.md

* Update tabby.vim
  • Loading branch information
wsxiaoys authored Apr 9, 2023
1 parent d5f5bed commit 2c3fee4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 29 deletions.
39 changes: 13 additions & 26 deletions clients/vim/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
# How to Use This VIM Plugin
# Tabby VIM extension

## Requirements

1. VIM 9.0+ with `+job` and `+textprop` features enabled. NeoVIM is not supported at the moment.
2. Node.js 16.0+, with `yarn` or `npm` installed.

## Setup

1. Build node scripts in `node_scripts/` directory. Use `yarn` as example. You can also use `npm` instead.
```bash
cd node_scripts
yarn && yarn build
cd ..
```

2. Copy this directory to your VIM plugin directory.
```bash
cp -r . ~/.vim/pack/plugins/start/tabby.vim
```

3. (Optional) Set Tabby server URL in your `vimrc` file. If you do not set a URL, the default value is `http://127.0.0.1:5000`.
```vim
let g:tabby_server_url = 'http://127.0.0.1:5000'
```

4. (Optional) Turn on `filetype` plugin for better compatibility.
```vim
filetype plugin on
```
2. Node.js 16.0+.

## Getting started

### Plug
```
; Make sure that the filetype plugin has been enabled.
filetype plugin on
Plug 'TabbyML/tabby', {'rtp': 'clients/vim'}
let g:tabby_server_url = 'http://127.0.0.1:5000'
```

## Usage

Expand Down
9 changes: 7 additions & 2 deletions clients/vim/autoload/tabby.vim
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,16 @@ function! s:GetCompletion(id)
if !tabby#Running()
return
endif

let l:language = s:GetLanguage()
if l:language == 'unknown'
return
endif
call ch_sendexpr(s:tabby, #{
\ func: 'getCompletion',
\ args: [#{
\ prompt: s:GetPrompt(),
\ language: s:GetLanguage(),
\ language: l:language,
\ }],
\ }, #{
\ callback: function('s:HandleCompletion', [a:id]),
Expand Down Expand Up @@ -305,7 +310,7 @@ function! tabby#Accept(fallback)
let s:text_to_insert = lines[0]
let insertion = "\<C-R>\<C-O>=tabby#ComsumeInsertion()\<CR>"
else
let current_line = getbufoneline('%', line('.'))
let current_line = getbufline('%', line('.'), line('.'))[0]
let suffix_chars_to_replace = len(current_line) - col('.') + 1
let s:text_to_insert = join(lines, "\n")
let insertion = repeat("\<Del>", suffix_chars_to_replace) . "\<C-R>\<C-O>=tabby#ComsumeInsertion()\<CR>"
Expand Down
1 change: 0 additions & 1 deletion clients/vim/node_scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules
dist
2 changes: 2 additions & 0 deletions clients/vim/node_scripts/dist/tabby.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions clients/vim/node_scripts/dist/tabby.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*!
* mime-db
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015-2022 Douglas Christopher Wilson
* MIT Licensed
*/

/*!
* mime-types
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/

0 comments on commit 2c3fee4

Please sign in to comment.