Merge pull request #326 from voideditor/model-selection

Small (or empty) file editing
This commit is contained in:
Andrew Pareles 2025-03-22 00:40:17 -07:00 committed by GitHub
commit 6fd514230c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 14 deletions

View file

@ -1172,7 +1172,14 @@ class EditCodeService extends Disposable implements IEditCodeService {
}
else if (opts.from === 'ClickApply') {
if (this._settingsService.state.globalSettings.enableFastApply) {
res = await this._initializeSearchAndReplaceStream(opts) // fast apply
const numCharsInFile = this._fileLengthOfGivenURI(opts.uri)
if (numCharsInFile === null) return null
if (numCharsInFile < 1000) { // slow apply for short files (especially important for empty files)
res = await this._initializeWriteoverStream(opts)
}
else {
res = await this._initializeSearchAndReplaceStream(opts) // fast apply
}
}
else {
res = await this._initializeWriteoverStream(opts) // rewrite
@ -1311,7 +1318,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
let ctrlKZoneIfQuickEdit: CtrlKZone | null = null
if (from === 'ClickApply') {
const uri_ = this._getActiveEditorURI()
const uri_ = this._uriOfGivenURI(opts.uri)
if (!uri_) return
uri = uri_
startRange = 'fullFile'
@ -1505,19 +1512,29 @@ class EditCodeService extends Disposable implements IEditCodeService {
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
const { from, applyStr, uri: givenURI, } = opts
let uri: URI
_uriOfGivenURI(givenURI: URI | 'current') {
if (givenURI === 'current') {
const uri_ = this._getActiveEditorURI()
if (!uri_) return
uri = uri_
}
else {
uri = givenURI
return uri_
}
return givenURI
}
_fileLengthOfGivenURI(givenURI: URI | 'current') {
const uri = this._uriOfGivenURI(givenURI)
if (!uri) return null
const { model } = this._voidModelService.getModel(uri)
if (!model) return null
const numCharsInFile = model.getValueLength(EndOfLinePreference.LF)
return numCharsInFile
}
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
const { from, applyStr, uri: givenURI, } = opts
const uri = this._uriOfGivenURI(givenURI)
if (!uri) return
await this._voidModelService.initializeModel(uri)
const { model } = this._voidModelService.getModel(uri)

View file

@ -2020,7 +2020,7 @@ export const SidebarChat = () => {
const proposed = toolNameSoFar && toolNames.includes(toolNameSoFar as ToolName) ? titleOfToolName[toolNameSoFar as ToolName]?.proposed : toolNameSoFar
const toolTitle = typeof proposed === 'function' ? proposed(null) : proposed
const currStreamingToolHTML = toolIsLoading ?
<ToolHeaderWrapper key={getChatBubbleId(currentThread.id, streamingChatIdx + 1)} title={toolTitle} desc1={<span className='flex items-center'>writing<IconLoading /></span>} />
<ToolHeaderWrapper key={getChatBubbleId(currentThread.id, streamingChatIdx + 1)} title={toolTitle} desc1={<span className='flex items-center'>Getting parameters<IconLoading /></span>} />
: null
const allMessagesHTML = [...previousMessagesHTML, currStreamingMessageHTML, currStreamingToolHTML]

View file

@ -271,8 +271,8 @@ const VoidCommandBar = ({ uri, editor }: VoidCommandBarProps) => {
<div className="flex flex-col gap-1">
{/* Changes in file */}
<div className={`${!isADiffZoneInThisFile ? 'hidden' : ''} flex items-center ${upDownDisabled ? 'opacity-50' : ''}`}>
{downButton}
{upButton}
{downButton}
<span className="min-w-16 px-2 text-xs">
{isADiffInThisFile ?
`Diff ${(currDiffIdx ?? 0) + 1} of ${sortedDiffIds.length}`

View file

@ -165,7 +165,8 @@ ${mode === 'agent' ? `\
- Only use tools if they help you accomplish the user's goal. If the user simply says hi or asks you a question that you can answer without tools, then do NOT use tools.
- ALWAYS use tools to take actions. For example, if you would like to edit a file, you MUST use a tool.`
: mode === 'gather' ? `\
- Your primary use of tools should be to gather information to help the user understand the codebase and answer their query.`
- Your primary use of tools should be to gather information to help the user understand the codebase and answer their query.
- You should extensively read files, types, etc and gather relevant context.`
: ''}
- If you think you should use tools, you do not need to ask for permission. Feel free to call tools whenever you'd like. You can use them to understand the codebase, ${mode === 'agent' ? 'run terminal commands, edit files, ' : 'gather relevant files and information, '}etc.
- NEVER refer to a tool by name when speaking with the user (NEVER say something like "I'm going to use \`tool_name\`"). Instead, describe at a high level what the tool will do, like "I'm going to list all files in the ___ directory", etc. Also do not refer to "pages" of results, just say you're getting more results.