Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping selections for code higlighting #36

Open
GordianDziwis opened this issue May 8, 2023 · 3 comments
Open

Wrapping selections for code higlighting #36

GordianDziwis opened this issue May 8, 2023 · 3 comments

Comments

@GordianDziwis
Copy link
Contributor

I have wrapped AIChatRun calls with those functions for getting a nicer prompt:

function! CodeReviewFn(range) range
  let l:lines = trim(join(getline(a:firstline, a:lastline), "\n"))
  let l:initial_prompt = ['>>> system', 'As a clean coding expert, review the code with the highest standards. Make the code more expressive and concise, using comments only when necessary. Also, consider the best practices for ' . &filetype . '.']
  let l:prompt = '```' . &filetype  . "\n" . l:lines . "\n```"
  let l:config = {
  \  'options': {
  \    'initial_prompt': l:initial_prompt,
  \  },
  \}
  '<,'>call vim_ai#AIChatRun(v:false, l:config, l:prompt)
endfunction
command! -range AIChatCodeReview <line1>,<line2>call CodeReviewFn(<range>)

function! g:vim_ai_mod.AIChatWrapper(range, ...) range
  let l:lines = trim(join(getline(a:firstline, a:lastline), "\n"))
  let l:instruction = a:0 ? a:1 : ''
  let l:prompt = l:instruction . "\n```" . &filetype  . "\n" . l:lines . "\n```"
  '<,'>call vim_ai#AIChatRun(v:false, {}, l:prompt)
endfunction
command! -range -nargs=? AIChatWrapper <line1>,<line2>call g:vim_ai_mod.AIChatWrapper(<range>, <f-args>)

And by the way with treesitter there is no need to define embedded syntaxes, this is already included.

@madox2
Copy link
Owner

madox2 commented May 8, 2023

Looks nice, you could do similar thing but without &filetype annotation with a selection boundary:

let g:vim_ai_chat = {
\  "options": {
\    "selection_boundary":  "```",
\  },
\}

@GordianDziwis
Copy link
Contributor Author

This is nicer, but it is not possible to add &filetype for syntax highlighting. Maybe having a pre_selection_boundary and a post_selection_boundary could be the solution?

@madox2
Copy link
Owner

madox2 commented May 9, 2023

In this case I can imagine making it a little bit smarter - if the boundary is ```, it is considered a standard markdown boundary and the filetype is added automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants