Skip to content

Commit 942c79a

Browse files
committed
Augment Vim v0.1.0
0 parents  commit 942c79a

11 files changed

Lines changed: 1201 additions & 0 deletions

File tree

LICENSE.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# License
2+
3+
This repository contains two separately licensed components:
4+
5+
## Vim Plugin
6+
7+
The Vim Plugin (all files in this repository except `dist` folder) is licensed under the MIT License:
8+
9+
MIT License
10+
11+
Copyright (c) 2025, Augment Computing, Inc.
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a copy
14+
of this software and associated documentation files (the "Software"), to deal
15+
in the Software without restriction, including without limitation the rights
16+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
copies of the Software, and to permit persons to whom the Software is
18+
furnished to do so, subject to the following conditions:
19+
20+
The above copyright notice and this permission notice shall be included in all
21+
copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
SOFTWARE.
30+
31+
32+
33+
## Server (`dist` folder)
34+
35+
The `dist` folder is licensed under the following Custom Proprietary License:
36+
37+
Custom Proprietary License for Server
38+
39+
Copyright (c) 2025, Augment Computing, Inc.
40+
41+
Permission is hereby granted to use `dist` folder solely in conjunction
42+
with the Augment Vim Plugin provided in this repository.
43+
44+
Restrictions:
45+
46+
1. Redistribution:
47+
Redistribution of the server, in part or in whole, is prohibited without prior written permission from Augment.
48+
49+
2. Modification:
50+
The server must not be reverse-engineered, decompiled, or modified.
51+
52+
3. Exclusive Use:
53+
The server may only be used with this Vim plugin and may not be integrated into other software or systems.
54+
55+
4. Commercial Use:
56+
Commercial use of the server requires a separate licensing agreement.
57+
58+
5. Distribution:
59+
The server is distributed exclusively through authorized plugin distribution channels.
60+
61+
THE SERVER (`dist` folder) IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY
62+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO
64+
EVENT SHALL AUGMENT BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY,
65+
WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF,
66+
OR IN CONNECTION WITH THE SERVER OR THE USE OR OTHER DEALINGS IN THE SERVER.
67+
68+
For licensing inquiries, please contact support@augmentcode.com.

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Augment Vim & Neovim Plugin
2+
3+
> [!WARNING]
4+
> This plugin is in early alpha development stage. Features may be incomplete,
5+
> unstable, or change without notice. While basic functionality is available,
6+
> you may encounter bugs, performance issues, or unexpected behavior. Current
7+
> platform support is limited to MacOS and Linux, with Windows to be added at a
8+
> later date.
9+
10+
## Installation
11+
12+
1. Both Vim and Neovim are supported, but the plugin may require a newer version
13+
than what's installed on your system by default.
14+
15+
- [Vim](https://github.com/vim/vim?tab=readme-ov-file#installation) version 9.1.0 or newer.
16+
17+
- [Neovim](https://github.com/neovim/neovim/tree/master?tab=readme-ov-file#install-from-package), version
18+
0.10.0 or newer.
19+
20+
1. Install [Node.js](https://nodejs.org/en/download/package-manager/all),
21+
version 22.0.0 or newer, which is a required dependency.
22+
23+
1. Install the plugin
24+
25+
- Manual installation (Vim):
26+
27+
```bash
28+
git clone git@github.com:augmentcode/augment.vim.git \
29+
~/.vim/pack/augment/start/augment.vim
30+
```
31+
32+
- Manual installation (Neovim):
33+
34+
```bash
35+
git clone git@github.com:augmentcode/augment.vim.git \
36+
~/.config/nvim/pack/augment/start/augment.vim
37+
```
38+
39+
- Vim Plug:
40+
41+
```vim
42+
Plug 'git@github.com:augmentcode/augment.vim.git'
43+
```
44+
45+
- Lazy.nvim:
46+
47+
```lua
48+
{ 'git@github.com:augmentcode/augment.vim.git' },
49+
```
50+
51+
1. Open Vim and sign in to Augment with the `:Augment signin` command.
52+
53+
## Basic Usage
54+
55+
Open a file in vim, start typing, and use tab to accept suggestions as they
56+
appear.
57+
58+
The following commands are provided:
59+
60+
```vim
61+
:Augment status " View the current status of the plugin
62+
:Augment signin " Start the sign in flow
63+
:Augment signout " Sign out of Augment
64+
:Augment enable " Globally enable suggestions (on by default)
65+
:Augment disable " Globally disable suggestions
66+
:Augment log " View the plugin log
67+
```
68+
69+
## Alternate Keybinds
70+
71+
By default, tab is used to accept a suggestion. If you want to use a
72+
different key, create a mapping that calls `augment#Accept()`. The function
73+
takes an optional arugment used to specify the fallback text to insert if no
74+
suggestion is available.
75+
76+
```vim
77+
" Use Ctrl-Y to accept a suggestion
78+
inoremap <c-y> <cmd>call augment#Accept()<cr>
79+
80+
" Use enter to accept a suggestion, falling back to a newline if no suggestion
81+
" is available
82+
inoremap <cr> <cmd>call augment#Accept("\n")<cr>
83+
```
84+
85+
The default tab mapping can be disabled by setting
86+
`g:augment_disable_tab_mapping = v:true` before the plugin is loaded.
87+
88+
## Licensing and Distribution
89+
90+
This repository includes two main components:
91+
92+
1. **Vim Plugin:** This includes all files in the repository except `dist` folder. These files are licensed under the [MIT License](LICENSE.md#vim-plugin).
93+
2. **Server (`dist` folder):** This file is proprietary and licensed under a [Custom Proprietary License](LICENSE.md#server).
94+
95+
For details on usage restrictions, refer to the [LICENSE.md](LICENSE.md) file.
96+
97+
## Reporting Issues
98+
99+
We encourage users to report any bugs or issues directly to us. Please use the [Issues](https://github.com/augmentcode/augment.vim/issues) section of this repository to share your feedback.
100+
101+
For any other questions, feel free to reach out to support@augmentcode.com.

autoload/augment.vim

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
" Copyright (c) 2025 Augment
2+
" MIT License - See LICENSE.md for full terms
3+
4+
" Handlers for autocommands and keybinds
5+
6+
" Check whether the server started. Errors to start should be reported in the
7+
" Augment-log.
8+
function! s:IsRunning() abort
9+
let client = augment#client#Client()
10+
return exists('client.client_id') || exists('client.job')
11+
endfunction
12+
13+
let s:NOT_RUNNING_MSG = 'The Augment language server is not running. See ":Augment log" for more details.'
14+
15+
" Notify the server that a buffer has been opened
16+
function! s:OpenBuffer() abort
17+
if !s:IsRunning()
18+
return
19+
endif
20+
21+
let client = augment#client#Client()
22+
if has('nvim')
23+
call luaeval('require("augment").open_buffer(_A[1], _A[2])', [client.client_id, bufnr('%')])
24+
else
25+
let uri = 'file://' . expand('%:p')
26+
let text = join(getline(1, '$'), "\n")
27+
call client.Notify('textDocument/didOpen', {
28+
\ 'textDocument': {
29+
\ 'uri': uri,
30+
\ 'languageId': &filetype,
31+
\ 'version': b:changedtick,
32+
\ 'text': text,
33+
\ },
34+
\ })
35+
endif
36+
endfunction
37+
38+
" Notify the server that a buffer has been updated
39+
function! s:UpdateBuffer() abort
40+
if !s:IsRunning()
41+
return
42+
endif
43+
44+
" The nvim lsp client does this automatically
45+
if !has('nvim')
46+
" Only send a change notification if the buffer has changed (as
47+
" tracked by b:changedtick)
48+
if exists('b:_augment_buf_tick') && b:_augment_buf_tick == b:changedtick
49+
return
50+
endif
51+
let b:_augment_buf_tick = b:changedtick
52+
53+
let uri = 'file://' . expand('%:p')
54+
let text = join(getline(1, '$'), "\n")
55+
call augment#client#Client().Notify('textDocument/didChange', {
56+
\ 'textDocument': {
57+
\ 'uri': uri,
58+
\ 'version': b:changedtick,
59+
\ },
60+
\ 'contentChanges': [{'text': text}],
61+
\ })
62+
endif
63+
endfunction
64+
65+
" Request a completion from the server
66+
function! s:RequestCompletion() abort
67+
if !s:IsRunning()
68+
return
69+
endif
70+
71+
" Don't send a request if disabled
72+
if exists('g:augment_enabled') && !g:augment_enabled
73+
return
74+
endif
75+
76+
" If there was a previous completion request with the same buffer version
77+
" (tracked by b:changedtick), don't send another
78+
if exists('b:_augment_comp_tick') && b:_augment_comp_tick == b:changedtick
79+
return
80+
endif
81+
let b:_augment_comp_tick = b:changedtick
82+
83+
let uri = 'file://' . expand('%:p')
84+
let text = join(getline(1, '$'), "\n")
85+
" TODO: remove version-- we use it elsewhere but it's not in the spec
86+
call augment#client#Client().Request('textDocument/completion', {
87+
\ 'textDocument': {
88+
\ 'uri': uri,
89+
\ 'version': b:changedtick,
90+
\ },
91+
\ 'position': {
92+
\ 'line': line('.') - 1,
93+
\ 'character': col('.') - 1,
94+
\ },
95+
\ })
96+
endfunction
97+
98+
" Show the log
99+
function! s:CommandLog() abort
100+
call augment#log#Show()
101+
endfunction
102+
103+
" Send sign-in request to the language server
104+
function! s:CommandSignIn() abort
105+
if !s:IsRunning()
106+
echohl WarningMsg
107+
echo s:NOT_RUNNING_MSG
108+
echohl None
109+
return
110+
endif
111+
112+
call augment#client#Client().Request('augment/login', {})
113+
endfunction
114+
115+
" Send sign-out request to the language server
116+
function! s:CommandSignOut() abort
117+
if !s:IsRunning()
118+
echohl WarningMsg
119+
echo s:NOT_RUNNING_MSG
120+
echohl None
121+
return
122+
endif
123+
124+
call augment#client#Client().Request('augment/logout', {})
125+
endfunction
126+
127+
function! s:CommandEnable() abort
128+
let g:augment_enabled = v:true
129+
endfunction
130+
131+
function! s:CommandDisable() abort
132+
let g:augment_enabled = v:false
133+
endfunction
134+
135+
function! s:CommandStatus() abort
136+
if !s:IsRunning()
137+
echohl WarningMsg
138+
echo s:NOT_RUNNING_MSG
139+
echohl None
140+
return
141+
endif
142+
143+
call augment#client#Client().Request('augment/status', {})
144+
endfunction
145+
146+
" Handle user commands
147+
let s:command_handlers = {
148+
\ 'log': function('s:CommandLog'),
149+
\ 'signin': function('s:CommandSignIn'),
150+
\ 'signout': function('s:CommandSignOut'),
151+
\ 'enable': function('s:CommandEnable'),
152+
\ 'disable': function('s:CommandDisable'),
153+
\ 'status': function('s:CommandStatus'),
154+
\ }
155+
156+
function! augment#Command(command) abort
157+
if empty(a:command)
158+
call s:command_handlers['status']()
159+
return
160+
endif
161+
162+
for [name, Handler] in items(s:command_handlers)
163+
" Note that ==? is case-insensitive comparison
164+
if a:command ==? name
165+
call Handler()
166+
return
167+
endif
168+
endfor
169+
170+
echohl WarningMsg
171+
echo 'Augment: Unknown command: "' . a:command . '"'
172+
echohl None
173+
endfunction
174+
175+
function! augment#CommandComplete(ArgLead, CmdLine, CursorPos) abort
176+
return keys(s:command_handlers)->join("\n")
177+
endfunction
178+
179+
" Autocommand handlers
180+
function! augment#OnVimEnter() abort
181+
call augment#client#Client()
182+
endfunction
183+
184+
function! augment#OnBufEnter() abort
185+
call s:OpenBuffer()
186+
endfunction
187+
188+
function! augment#OnTextChanged() abort
189+
call s:UpdateBuffer()
190+
endfunction
191+
192+
function! augment#OnTextChangedI() abort
193+
" Since CursorMovedI is always called before TextChangedI, the suggestion will already be cleared
194+
call s:UpdateBuffer()
195+
call s:RequestCompletion()
196+
endfunction
197+
198+
function! augment#OnCursorMovedI() abort
199+
call augment#suggestion#Clear()
200+
endfunction
201+
202+
function! augment#OnInsertEnter() abort
203+
call s:UpdateBuffer()
204+
call s:RequestCompletion()
205+
endfunction
206+
207+
function! augment#OnInsertLeavePre() abort
208+
call augment#suggestion#Clear()
209+
endfunction
210+
211+
" Accept the currently active suggestion if one is available, otherwise insert
212+
" the fallback text provided as the first argument
213+
function! augment#Accept(...) abort
214+
" If no fallback was provided, don't add any text
215+
let fallback = a:0 >= 1 ? a:1 : ''
216+
217+
if !augment#suggestion#Accept()
218+
call feedkeys(fallback, 'nt')
219+
endif
220+
endfunction

0 commit comments

Comments
 (0)