Skip to content

Commit 6fd5142

Browse files
Merge pull request #326 from voideditor/model-selection
Small (or empty) file editing
2 parents 47998e4 + f75b4f3 commit 6fd5142

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

src/vs/workbench/contrib/void/browser/editCodeService.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,14 @@ class EditCodeService extends Disposable implements IEditCodeService {
11721172
}
11731173
else if (opts.from === 'ClickApply') {
11741174
if (this._settingsService.state.globalSettings.enableFastApply) {
1175-
res = await this._initializeSearchAndReplaceStream(opts) // fast apply
1175+
const numCharsInFile = this._fileLengthOfGivenURI(opts.uri)
1176+
if (numCharsInFile === null) return null
1177+
if (numCharsInFile < 1000) { // slow apply for short files (especially important for empty files)
1178+
res = await this._initializeWriteoverStream(opts)
1179+
}
1180+
else {
1181+
res = await this._initializeSearchAndReplaceStream(opts) // fast apply
1182+
}
11761183
}
11771184
else {
11781185
res = await this._initializeWriteoverStream(opts) // rewrite
@@ -1311,7 +1318,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
13111318
let ctrlKZoneIfQuickEdit: CtrlKZone | null = null
13121319

13131320
if (from === 'ClickApply') {
1314-
const uri_ = this._getActiveEditorURI()
1321+
const uri_ = this._uriOfGivenURI(opts.uri)
13151322
if (!uri_) return
13161323
uri = uri_
13171324
startRange = 'fullFile'
@@ -1505,19 +1512,29 @@ class EditCodeService extends Disposable implements IEditCodeService {
15051512

15061513

15071514

1508-
1509-
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
1510-
const { from, applyStr, uri: givenURI, } = opts
1511-
let uri: URI
1512-
1515+
_uriOfGivenURI(givenURI: URI | 'current') {
15131516
if (givenURI === 'current') {
15141517
const uri_ = this._getActiveEditorURI()
15151518
if (!uri_) return
1516-
uri = uri_
1517-
}
1518-
else {
1519-
uri = givenURI
1519+
return uri_
15201520
}
1521+
return givenURI
1522+
}
1523+
_fileLengthOfGivenURI(givenURI: URI | 'current') {
1524+
const uri = this._uriOfGivenURI(givenURI)
1525+
if (!uri) return null
1526+
const { model } = this._voidModelService.getModel(uri)
1527+
if (!model) return null
1528+
const numCharsInFile = model.getValueLength(EndOfLinePreference.LF)
1529+
return numCharsInFile
1530+
}
1531+
1532+
1533+
private async _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }): Promise<[DiffZone, Promise<void>] | undefined> {
1534+
const { from, applyStr, uri: givenURI, } = opts
1535+
1536+
const uri = this._uriOfGivenURI(givenURI)
1537+
if (!uri) return
15211538

15221539
await this._voidModelService.initializeModel(uri)
15231540
const { model } = this._voidModelService.getModel(uri)

src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ export const SidebarChat = () => {
20202020
const proposed = toolNameSoFar && toolNames.includes(toolNameSoFar as ToolName) ? titleOfToolName[toolNameSoFar as ToolName]?.proposed : toolNameSoFar
20212021
const toolTitle = typeof proposed === 'function' ? proposed(null) : proposed
20222022
const currStreamingToolHTML = toolIsLoading ?
2023-
<ToolHeaderWrapper key={getChatBubbleId(currentThread.id, streamingChatIdx + 1)} title={toolTitle} desc1={<span className='flex items-center'>writing<IconLoading /></span>} />
2023+
<ToolHeaderWrapper key={getChatBubbleId(currentThread.id, streamingChatIdx + 1)} title={toolTitle} desc1={<span className='flex items-center'>Getting parameters<IconLoading /></span>} />
20242024
: null
20252025

20262026
const allMessagesHTML = [...previousMessagesHTML, currStreamingMessageHTML, currStreamingToolHTML]

src/vs/workbench/contrib/void/browser/react/src/void-command-bar-tsx/VoidCommandBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ const VoidCommandBar = ({ uri, editor }: VoidCommandBarProps) => {
271271
<div className="flex flex-col gap-1">
272272
{/* Changes in file */}
273273
<div className={`${!isADiffZoneInThisFile ? 'hidden' : ''} flex items-center ${upDownDisabled ? 'opacity-50' : ''}`}>
274-
{downButton}
275274
{upButton}
275+
{downButton}
276276
<span className="min-w-16 px-2 text-xs">
277277
{isADiffInThisFile ?
278278
`Diff ${(currDiffIdx ?? 0) + 1} of ${sortedDiffIds.length}`

src/vs/workbench/contrib/void/common/prompt/prompts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ ${mode === 'agent' ? `\
165165
- 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.
166166
- ALWAYS use tools to take actions. For example, if you would like to edit a file, you MUST use a tool.`
167167
: mode === 'gather' ? `\
168-
- Your primary use of tools should be to gather information to help the user understand the codebase and answer their query.`
168+
- Your primary use of tools should be to gather information to help the user understand the codebase and answer their query.
169+
- You should extensively read files, types, etc and gather relevant context.`
169170
: ''}
170171
- 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.
171172
- 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.

0 commit comments

Comments
 (0)