From: Robin Krens Date: Thu, 2 Jan 2025 19:01:57 +0000 (+0100) Subject: add initial ClaudeWhat X-Git-Url: https://robinkrens.nl/gitweb/?a=commitdiff_plain;h=07f2474369dfeb2aaca27c5e5f0f519977fcfe33;p=vim-claudy add initial ClaudeWhat --- diff --git a/claudy.vim b/claudy.vim index 042d6d8..931435a 100644 --- a/claudy.vim +++ b/claudy.vim @@ -150,13 +150,50 @@ function! s:SendMessage() " Add response put = l:response " call append('$', 'Claude: ' . l:response) - put = repeat('-', 80) . '\n' + put = repeat('-', 80) + put = '' " Move cursor to new line normal! G startinsert! endfunction +function! ClaudyWhat() range + let l:start_line = line("'<") + let l:end_line = line("'>") + let l:selected_text = join(getline(l:start_line, l:end_line)) + + let l:json_data = { + \ 'model': 'claude-3-5-sonnet-20241022', + \ 'max_tokens': 1024, + \ 'messages': [ + \ { + \ 'role': 'user', + \ 'content': "What is this code doing? explain with a one-liner: " . l:selected_text + \ } + \ ] + \ } + + let l:response = ClaudyRequest(l:json_data) + + " Create popup window + let l:popup_opts = { + \ 'line': 'cursor+1', + \ 'col': 'cursor', + \ 'pos': 'topleft', + \ 'padding': [0,1,0,1], + \ 'border': [], + \ 'close': 'click', + \ 'moved': 'any', + \ 'maxwidth': 50, + \ 'minwidth': 50, + \ 'wrap': 1 + \ } + + call popup_create(l:response, l:popup_opts) +endfunction + vnoremap c :call ClaudyRefactor() vnoremap i :call ClaudyImplement() +vnoremap w :call ClaudyWhat() vnoremap b :call ClaudyTest()