-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add Vim9 Script #7763
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
Open
DanBradbury
wants to merge
7
commits into
github-linguist:main
Choose a base branch
from
DanBradbury:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Vim9 Script #7763
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95933fa
Add Vim9 Script
DanBradbury 0d16221
update grammars to include vim9 + fix ordering for heuristics
DanBradbury 8c04fe6
update heuristic pattern to allow use of noclear
DanBradbury b2da940
Fix pedantic test failures
DanBradbury 69d8183
Add heuristics test + fixtures
DanBradbury aa87c5d
add advanced.vim example to vim9 samples
DanBradbury fe2a694
Merge branch 'main' into main
lildude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| vim9script | ||
|
|
||
| var myNumber: number = 42 | ||
| const PI: number = 3.14159 | ||
| final myList: list<string> = ['vim', 'neovim', 'vim9'] | ||
|
|
||
| def HelloWorld(): void | ||
| echo "Hello, Vim9!" | ||
| enddef | ||
|
|
||
| def Add(a: number, b: number): number | ||
| return a + b | ||
| enddef | ||
|
|
||
| def ProcessList(items: list<string>): dict<number> | ||
| var result: dict<number> = {} | ||
| for item in items | ||
| result[item] = len(item) | ||
| endfor | ||
| return result | ||
| enddef | ||
|
|
||
| var double = (n: number): number => n * 2 | ||
| var squared = (n: number): number => n * n | ||
|
|
||
| def CheckValue(val: number): string | ||
| if val > 0 | ||
| return "positive" | ||
| elseif val < 0 | ||
| return "negative" | ||
| else | ||
| return "zero" | ||
| endif | ||
| enddef | ||
|
|
||
| var name = "Vim9" | ||
| echo $"Welcome to {name}!" | ||
|
|
||
| export def PublicFunction(): void | ||
| echo "This function is exported" | ||
| enddef | ||
|
|
||
| def SafeDivide(a: number, b: number): number | ||
| try | ||
| return a / b | ||
| catch | ||
| echoerr "Division error" | ||
| return 0 | ||
| endtry | ||
| enddef | ||
|
|
||
| var isEnabled: bool = true | ||
| var isDisabled: bool = false | ||
|
|
||
| HelloWorld() | ||
| var sum = Add(10, 20) | ||
| echo $"Sum: {sum}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| vim9script | ||
| scriptencoding utf-8 | ||
|
|
||
| import autoload 'copilot_chat/auth.vim' as auth | ||
| import autoload 'copilot_chat/buffer.vim' as _buffer | ||
| import autoload 'copilot_chat/api.vim' as api | ||
|
|
||
| export def OpenChat(): void | ||
| if _buffer.HasActiveChat() && g:copilot_reuse_active_chat == 1 | ||
| _buffer.FocusActiveChat() | ||
| else | ||
| _buffer.Create() | ||
| endif | ||
| timer_start(10, (_) => auth.VerifySignin()) | ||
| enddef | ||
|
|
||
| export def StartChat(message: string): void | ||
| OpenChat() | ||
| _buffer.AppendMessage(message) | ||
| api.AsyncRequest([{'content': message, 'role': 'user'}], []) | ||
| enddef | ||
|
|
||
| export def ResetChat(): void | ||
| if g:copilot_chat_active_buffer == -1 || !bufexists(g:copilot_chat_active_buffer) | ||
| echom 'No active chat window to reset' | ||
| return | ||
| endif | ||
|
|
||
| var current_buf = bufnr('%') | ||
|
|
||
| # Switch to the active chat buffer if not already there | ||
| if current_buf != g:copilot_chat_active_buffer | ||
| execute 'buffer ' .. g:copilot_chat_active_buffer | ||
| endif | ||
|
|
||
| deletebufline('%', 1, '$') | ||
|
|
||
| _buffer.WelcomeMessage() | ||
|
|
||
| if current_buf != g:copilot_chat_active_buffer && bufexists(current_buf) | ||
| execute 'buffer ' .. current_buf | ||
| endif | ||
| enddef | ||
|
|
||
| export def SubmitMessage(): void | ||
| auth.GetTokens() | ||
| var messages = [] | ||
| var pattern = ' ━\+$' | ||
| var all_file_lists = [] | ||
| cursor(1, 1) | ||
|
|
||
| while search(pattern, 'W') > 0 | ||
| var header_line = getline('.') | ||
| var role = 'user' | ||
| # Check separator icon to determine message role | ||
| # Separator with icon indicates assistant response, otherwise user message | ||
| if stridx(header_line, ' ') != -1 | ||
| role = 'assistant' | ||
| endif | ||
| var start_line: number = line('.') + 1 | ||
| var end_line: number = search(pattern, 'W') | ||
| if end_line == 0 | ||
| end_line = line('$') | ||
| else | ||
| end_line -= 1 | ||
| cursor(line('.') - 1, col('.')) | ||
| endif | ||
|
|
||
| var lines: list<string> = getline(start_line, end_line) | ||
| var file_list: list<string> = [] | ||
|
|
||
| for i in range(len(lines)) | ||
| var line: string = lines[i] | ||
| if line =~? '^> \(\w\+\)' | ||
| var text: string = matchstr(line, '^> \(\w\+\)') | ||
| text = substitute(text, '^> ', '', '') | ||
| if has_key(g:copilot_chat_prompts, text) | ||
| lines[i] = g:copilot_chat_prompts[text] | ||
| endif | ||
| elseif line =~? '^#file: ' | ||
| var filename: string = matchstr(line, '^#file: \s*\zs.*\ze$') | ||
| add(file_list, filename) | ||
| endif | ||
| endfor | ||
| var message: string = join(lines, "\n") | ||
|
|
||
| add(messages, {'content': message, 'role': role}) | ||
| add(all_file_lists, file_list) | ||
| cursor(line('.'), col('.') + 1) | ||
| endwhile | ||
|
|
||
| # Limit message history to improve performance | ||
| # Only send the most recent messages based on configuration | ||
| var limit: number = g:copilot_chat_message_history_limit | ||
| if len(messages) > limit && limit > 0 | ||
| var start_idx: number = len(messages) - limit | ||
| messages = messages[start_idx : ] | ||
| all_file_lists = all_file_lists[start_idx : ] | ||
| endif | ||
|
|
||
| # Consolidate file lists from recent messages | ||
| # O(n) consolidation using dictionary for O(1) duplicate detection (improved from O(n²)) | ||
| var consolidated_files: list<string> = [] | ||
| var seen: dict<any> = {} | ||
| for files in all_file_lists | ||
| for file in files | ||
| if !has_key(seen, file) | ||
| seen[file] = 1 | ||
| add(consolidated_files, file) | ||
| endif | ||
| endfor | ||
| endfor | ||
|
|
||
| api.AsyncRequest(messages, consolidated_files) | ||
| enddef |
Submodule language-vim9
added at
28d320
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.