Skip to content

Commit 97418c9

Browse files
Augment Vim v0.25.1
1 parent a50e362 commit 97418c9

File tree

9 files changed

+288
-113
lines changed

9 files changed

+288
-113
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Augment Vim Plugin Changelog
2+
3+
This file documents the notable changes for each stable version of the Augment
4+
Vim plugin. The following list is not necessarily comprehensive, but should
5+
include any changes that may impact the user experience.
6+
7+
## 0.25.1
8+
9+
- Deprecate the `Enable` and `Disable` commands in favor of the
10+
`g:augment_disable_completions` option which disables inline completions but
11+
not the chat feature. See `:help g:augment_disable_completions` for more
12+
details.
13+
- Check for the `winfixbuf` option before setting it to avoid an error on older
14+
versions of Vim.
15+
- Perform a runtime compatibility check on startup to warn users if they are
16+
running an unsupported version of Node.js.
17+
- Improve the auth flow by significantly shortening the auth URL (addressing
18+
issues with truncated URLs) and improving the error messages on failure.
19+
- Add support for filepaths containing spaces.

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,21 @@ accept a suggestion, or keep typing to refine the suggestions. To ask questions
1515
about your codebase or request specific changes, use the `:Augment chat` command
1616
to start a chat conversation.
1717

18-
## Installation
18+
## Getting Started
1919

20-
1. Both Vim and Neovim are supported, but the plugin may require a newer version
21-
than what's installed on your system by default.
20+
1. Sign up for a free trial of Augment at
21+
[augmentcode.com](https://augmentcode.com).
2222

23-
- [Vim](https://github.com/vim/vim?tab=readme-ov-file#installation) version 9.1.0 or newer.
23+
1. Ensure you have a compatible editor version installed. Both Vim and Neovim
24+
are supported, but the plugin may require a newer version than what is
25+
installed on your system by default.
2426

25-
- [Neovim](https://github.com/neovim/neovim/tree/master?tab=readme-ov-file#install-from-package), version
26-
0.10.0 or newer.
27+
- For [Vim](https://github.com/vim/vim?tab=readme-ov-file#installation),
28+
version 9.1.0 or newer.
29+
30+
- For
31+
[Neovim](https://github.com/neovim/neovim/tree/master?tab=readme-ov-file#install-from-package),
32+
version 0.10.0 or newer.
2733

2834
1. Install [Node.js](https://nodejs.org/en/download/package-manager/all),
2935
version 22.0.0 or newer, which is a required dependency.
@@ -71,8 +77,6 @@ The following commands are provided:
7177
:Augment status " View the current status of the plugin
7278
:Augment signin " Start the sign in flow
7379
:Augment signout " Sign out of Augment
74-
:Augment enable " Globally enable suggestions (on by default)
75-
:Augment disable " Globally disable suggestions
7680
:Augment log " View the plugin log
7781
:Augment chat " Send a chat message to Augment AI
7882
:Augment chat-new " Start a new chat conversation
@@ -167,6 +171,10 @@ inoremap <cr> <cmd>call augment#Accept("\n")<cr>
167171
The default tab mapping can be disabled by setting
168172
`g:augment_disable_tab_mapping = v:true` before the plugin is loaded.
169173
174+
Completions can be disabled entirely by setting
175+
`g:augment_disable_completions = v:true` in your vimrc or at any time during
176+
editing.
177+
170178
If another plugin uses tab in insert mode, the Augment tab mapping may be
171179
overridden depending on the order in which the plugins are loaded. If tab isn't
172180
working for you, the `imap <tab>` command can be used to check if the mapping is

autoload/augment.vim

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function! s:RequestCompletion() abort
7373
return
7474
endif
7575

76-
" Don't send a request if disabled
77-
if exists('g:augment_enabled') && !g:augment_enabled
76+
" Don't send a request if completions are disabled
77+
if exists('g:augment_disable_completions') && g:augment_disable_completions
7878
return
7979
endif
8080

@@ -85,7 +85,16 @@ function! s:RequestCompletion() abort
8585
endif
8686
let b:_augment_comp_tick = b:changedtick
8787

88-
let uri = 'file://' . expand('%:p')
88+
if has('nvim')
89+
" NOTE(mpauly): On neovim, we use the built-in lsp client which
90+
" requires the uri to be in the format defined by
91+
" vim.uri_from_fname(). There isn't a straightforward way to format
92+
" the uri on vim and it isn't causing any issues, so punting on it for
93+
" now.
94+
let uri = v:lua.vim.uri_from_fname(expand('%:p'))
95+
else
96+
let uri = 'file://' . expand('%:p')
97+
endif
8998
let text = join(getline(1, '$'), "\n")
9099
" TODO: remove version-- we use it elsewhere but it's not in the spec
91100
call augment#client#Client().Request('textDocument/completion', {
@@ -129,15 +138,21 @@ function! s:CommandSignOut(...) abort
129138
call augment#client#Client().Request('augment/logout', {})
130139
endfunction
131140

141+
" NOTE: The enable/disable commands are deprecated
132142
function! s:CommandEnable(...) abort
133-
let g:augment_enabled = v:true
143+
call augment#DisplayError('The `Enable` and `Disable` commands are deprecated in favor of the `g:augment_disable_completions` option. See `:help g:augment_disable_completions` for more details.')
134144
endfunction
135145

136146
function! s:CommandDisable(...) abort
137-
let g:augment_enabled = v:false
147+
call augment#DisplayError('The `Enable` and `Disable` commands are deprecated in favor of the `g:augment_disable_completions` option. See `:help g:augment_disable_completions` for more details.')
138148
endfunction
139149

140150
function! s:CommandStatus(...) abort
151+
if !exists('g:augment_initialized') || !g:augment_initialized
152+
call augment#DisplayError('The Augment plugin failed to initialize. See ":Augment log" for more details.')
153+
return
154+
endif
155+
141156
if !s:IsRunning()
142157
echohl WarningMsg
143158
echo s:NOT_RUNNING_MSG
@@ -149,13 +164,6 @@ function! s:CommandStatus(...) abort
149164
endfunction
150165

151166
function! s:CommandChat(range, args) abort
152-
if exists('g:augment_enabled') && !g:augment_enabled
153-
echohl WarningMsg
154-
echo 'Augment: Not enabled. Run ":Augment enable" to enable the plugin.'
155-
echohl None
156-
return
157-
endif
158-
159167
if !s:IsRunning()
160168
echohl WarningMsg
161169
echo s:NOT_RUNNING_MSG
@@ -244,7 +252,14 @@ function! augment#Command(range, args) abort range
244252
return
245253
endif
246254

255+
" If the plugin failed to initialize, only allow status and log commands
247256
let command = split(a:args)[0]
257+
if (!exists('g:augment_initialized') || !g:augment_initialized)
258+
\ && command !=# 'status' && command !=# 'log'
259+
call augment#DisplayError('The Augment plugin failed to initialize. Only `:Augment status` and `:Augment log` commands are available.')
260+
return
261+
endif
262+
248263
for [name, Handler] in items(s:command_handlers)
249264
" Note that ==? is case-insensitive comparison
250265
if command ==? name
@@ -309,3 +324,22 @@ function! augment#Accept(...) abort
309324
call feedkeys(fallback, 'nt')
310325
endif
311326
endfunction
327+
328+
" Display an error message to the user in addition to logging it
329+
function! augment#DisplayError(message) abort
330+
" If we have already entered the editor, display the error message
331+
" immediately. Otherwise, wait for VimEnter.
332+
if v:vim_did_enter
333+
echohl ErrorMsg | echom 'Augment: ' . a:message | echohl None
334+
else
335+
" Shadow the message argument with a script-local variable. This means
336+
" that subsequent calls will override the previous message, which
337+
" should be fine for our use case.
338+
let s:error_message = a:message
339+
augroup augment_error
340+
autocmd!
341+
autocmd VimEnter * echohl ErrorMsg | echom 'Augment: ' . s:error_message | echohl None
342+
augroup END
343+
endif
344+
call augment#log#Error(a:message)
345+
endfunction

autoload/augment/chat.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ function! augment#chat#OpenChatPanel() abort
5151
setlocal buftype=nofile " Buffer will never be written to a file
5252
setlocal nomodifiable " Prevent any modifications
5353
setlocal noswapfile " Don't create a swapfile
54-
setlocal winfixbuf " Keep buffer in window when splitting
54+
" NOTE(mpauly): winfixbuf is not available in some subversions of vim 9.1
55+
if exists('&winfixbuf')
56+
setlocal winfixbuf " Keep buffer in window when splitting
57+
endif
5558
setlocal bufhidden=hide " When buffer is abandoned, hide it
5659
setlocal nobuflisted " Hide from :ls
5760
setlocal wrap " Wrap long lines

autoload/augment/client.vim

Lines changed: 65 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33

44
" Client for interacting with the server process
55

6+
" Custom LSP response error codes
7+
let s:AUGMENT_ERROR_UNAUTHORIZED = 401
8+
69
let s:client = {}
710

8-
" If provided, launch the server from a user-provided command
9-
if exists('g:augment_job_command')
10-
let s:job_command = g:augment_job_command
11-
else
12-
let server_file = expand('<sfile>:h:h:h') . '/dist/server.js'
11+
function! augment#client#GetJobCommand() abort
12+
" If provided, launch the server from a user-provided command
13+
if exists('g:augment_job_command')
14+
return g:augment_job_command
15+
endif
16+
17+
let server_file = expand('<script>:h:h:h') . '/dist/server.js'
1318

1419
" If provided, use a user-provided node command
1520
if exists('g:augment_node_command')
1621
let s:node_command = g:augment_node_command
1722
else
1823
let s:node_command = 'node'
1924
endif
20-
21-
let s:job_command = [s:node_command, server_file, '--stdio']
22-
endif
25+
return [s:node_command, server_file, '--stdio']
26+
endfunction
2327

2428
function! s:VimNotify(method, params) dict abort
2529
let message = {
@@ -55,12 +59,27 @@ function! s:NvimRequest(method, params) dict abort
5559
" For nvim tracking the request methods and params is handled in the lua code
5660
endfunction
5761

58-
" Handle a chat chunk notification
62+
" Handle the augment/chatChunk notification
5963
function! s:HandleChatChunk(client, params) abort
6064
let text = a:params.text
6165
call augment#chat#AppendText(text)
6266
endfunction
6367

68+
" Handle the window/logMessage notification
69+
function! s:HandleLogMessage(client, params) abort
70+
if a:params.type == 1 " Error
71+
call augment#log#Error(a:params.message)
72+
elseif a:params.type == 2 " Warning
73+
call augment#log#Warn(a:params.message)
74+
elseif a:params.type == 3 || a:params.type == 4 " Info, Log
75+
call augment#log#Info(a:params.message)
76+
elseif a:params.type == 5 " Debug
77+
call augment#log#Debug(a:params.message)
78+
else
79+
call augment#log#Warn('Unknown log message type: ' . string(a:params.type) . '. Message: ' . string(a:params.message))
80+
endif
81+
endfunction
82+
6483
" Handle the initialize response
6584
function! s:HandleInitialize(client, params, result, err) abort
6685
if a:err isnot v:null
@@ -74,6 +93,11 @@ endfunction
7493
" Handle the textDocument/completion response
7594
function! s:HandleCompletion(client, params, result, err) abort
7695
if a:err isnot v:null
96+
" If the user is not logged in, ignore the error
97+
if a:err.code == s:AUGMENT_ERROR_UNAUTHORIZED
98+
return
99+
endif
100+
77101
call augment#log#Error('Recieved error ' . string(a:err) . ' for completion with params: ' . string(a:params))
78102
return
79103
endif
@@ -130,7 +154,7 @@ endfunction
130154
function! s:HandleToken(client, params, result, err) abort
131155
if a:err isnot v:null
132156
echohl ErrorMsg
133-
echom 'Augment: Error signing in, please try again.'
157+
echom 'Augment: Error signing in: ' . a:err.message
134158
echohl None
135159
call augment#log#Error('augment/token response error: ' . string(a:err))
136160
return
@@ -157,7 +181,7 @@ function! s:HandleStatus(client, params, result, err) abort
157181
endif
158182

159183
let loggedIn = a:result.loggedIn
160-
let enabled = exists('g:augment_enabled') ? g:augment_enabled : v:true
184+
let disabled = exists('g:augment_disable_completions') && g:augment_disable_completions
161185
if has_key(a:result, 'syncPercentage')
162186
let syncPercentage = a:result.syncPercentage == 100 ? 'fully' : printf('%d%%', a:result.syncPercentage)
163187
let syncText = printf(' (workspace %s synced)', syncPercentage)
@@ -167,16 +191,20 @@ function! s:HandleStatus(client, params, result, err) abort
167191

168192
if !loggedIn
169193
echom 'Augment: Not signed in. Run ":Augment signin" to start the sign in flow or ":h augment" for more information on the plugin.'
170-
elseif !enabled
171-
echom printf('Augment%s: Signed in, disabled.', syncText)
194+
elseif disabled
195+
echom printf('Augment%s: Signed in, completions disabled.', syncText)
172196
else
173-
echom printf('Augment%s: Signed in, enabled.', syncText)
197+
echom printf('Augment%s: Signed in.', syncText)
174198
endif
175199
endfunction
176200

177201
" Handle the augment/chat response
178202
function! s:HandleChat(client, params, result, err) abort
179203
if a:err isnot v:null
204+
" NOTE(mpauly): For chat we want to show the error to the user even if
205+
" they're not logged in. This helps disambiguate between a
206+
" network/slow response error and an authentication error.
207+
180208
call augment#log#Error('augment/chat response error: ' . string(a:err))
181209
return
182210
endif
@@ -290,13 +318,27 @@ function! s:GetWorkspaceFolders() abort
290318
return []
291319
endif
292320

321+
" Validate the the workspace folders are a list
322+
if type(g:augment_workspace_folders) == v:t_list
323+
let folders_list = g:augment_workspace_folders
324+
elseif type(g:augment_workspace_folders) == v:t_string
325+
let folders_list = [g:augment_workspace_folders]
326+
else
327+
call augment#log#Error('Workspace folders set to invalid value: ' . string(g:augment_workspace_folders) . '. See `:h g:augment_workspace_folders` for configuration instructions.')
328+
return []
329+
endif
330+
293331
let valid_folders = []
294-
for folder in g:augment_workspace_folders
295-
let abs_path = fnamemodify(folder, ':p')
296-
if !isdirectory(abs_path)
297-
call augment#log#Error('The following workspace folder does not exist: ' . abs_path)
332+
for folder in folders_list
333+
if type(folder) != v:t_string
334+
call augment#log#Error('Expected workspace folder type to be string. Got: ' . string(folder))
298335
else
299-
call add(valid_folders, folder)
336+
let abs_path = fnamemodify(folder, ':p')
337+
if !isdirectory(abs_path)
338+
call augment#log#Error('The following workspace folder does not exist: ' . abs_path)
339+
else
340+
call add(valid_folders, folder)
341+
endif
300342
endif
301343
endfor
302344

@@ -324,6 +366,7 @@ function! s:New() abort
324366
" Set the message handlers
325367
let notification_handlers = {
326368
\ 'augment/chatChunk': function('s:HandleChatChunk'),
369+
\ 'window/logMessage': function('s:HandleLogMessage'),
327370
\ }
328371
let response_handlers = {
329372
\ 'initialize': function('s:HandleInitialize'),
@@ -342,17 +385,11 @@ function! s:New() abort
342385
\ 'response_handlers': response_handlers,
343386
\ }
344387

345-
346-
" Check that the runtime environment is installed. If not, return a partially initialized client
347-
if executable(s:job_command[0]) == 0
348-
call augment#log#Error('The Augment runtime (' . s:job_command[0] . ') was not found. If node is available on your system under a different name, you can set the `g:augment_node_command` variable. See `:help g:augment_node_command` for more details.')
349-
return client
350-
endif
351-
352388
" Convert any workspace folders to URIs for the language server
353389
let workspace_folders = s:GetWorkspaceFolders()
354390

355391
" Start the server and send the initialize request
392+
let job_command = augment#client#GetJobCommand()
356393
if has('nvim')
357394
" Nvim-specific client setup
358395
call extend(client, {
@@ -365,7 +402,7 @@ function! s:New() abort
365402

366403
" If the client exits, lua will notify NvimOnExit()
367404
let client.client_id = luaeval('require("augment").start_client(_A[1], _A[2], _A[3])',
368-
\ [s:job_command, notification_methods, workspace_folders])
405+
\ [job_command, notification_methods, workspace_folders])
369406
else
370407
" Vim-specific client setup
371408
call extend(client, {
@@ -375,7 +412,7 @@ function! s:New() abort
375412
\ 'Request': function('s:VimRequest'),
376413
\ })
377414

378-
let client.job = job_start(s:job_command, {
415+
let client.job = job_start(job_command, {
379416
\ 'noblock': 1,
380417
\ 'stoponexit': 'term',
381418
\ 'in_mode': 'lsp',

autoload/augment/version.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
" MIT License - See LICENSE.md for full terms
33

44
function! augment#version#Version() abort
5-
return '0.14.1'
5+
return '0.25.1'
66
endfunction

dist/server.js

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)