mirror of
https://github.com/voideditor/void
synced 2026-05-23 17:38:23 +00:00
fix line indexing when streaming
This commit is contained in:
parent
a9adcad560
commit
32bfe9a111
2 changed files with 63 additions and 21 deletions
|
|
@ -210,9 +210,8 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
|||
this._register(
|
||||
model.onDidChangeContent(e => {
|
||||
// it's as if we just called _write, now all we need to do is realign and refresh
|
||||
const uri = model.uri
|
||||
|
||||
if (this.weAreWriting) return
|
||||
const uri = model.uri
|
||||
this._onUserChangeContent(uri, e)
|
||||
})
|
||||
)
|
||||
|
|
@ -244,6 +243,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
|||
private _onInternalChangeContent(uri: URI, { shouldRealign }: { shouldRealign: false | { newText: string, oldRange: IRange } }) {
|
||||
if (shouldRealign) {
|
||||
const { newText, oldRange } = shouldRealign
|
||||
console.log('realiging', newText, oldRange)
|
||||
this._realignAllDiffAreasLines(uri, newText, oldRange)
|
||||
}
|
||||
this._refreshStylesAndDiffsInURI(uri)
|
||||
|
|
@ -816,45 +816,41 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
|||
|
||||
// if streaming, use diffs to figure out where to write new code
|
||||
// these are two different coordinate systems - new and old line number
|
||||
let newFileEndLine: number // get file[diffArea.startLine...newFileEndLine] with line=newFileEndLine highlighted (line in the file, so starts at diffZone.startLine)
|
||||
let newCodeEndLine: number // get file[diffArea.startLine...newFileEndLine] with line=newFileEndLine highlighted
|
||||
let originalCodeStartLine: number // get original[oldStartingPoint...] (line in the original code, so starts at 1)
|
||||
|
||||
const lastDiff = computedDiffs.pop()
|
||||
|
||||
if (!lastDiff) {
|
||||
console.log('!lastDiff')
|
||||
// if the writing is identical so far, display no changes
|
||||
originalCodeStartLine = 1
|
||||
newFileEndLine = diffZone.startLine
|
||||
newCodeEndLine = 1
|
||||
}
|
||||
else {
|
||||
// add diffZone.startLine to convert to right coordinate system (line in file, not in diffarea)
|
||||
originalCodeStartLine = lastDiff.originalStartLine
|
||||
if (lastDiff.type === 'insertion')
|
||||
newFileEndLine = (diffZone.startLine - 1) + lastDiff.endLine
|
||||
if (lastDiff.type === 'insertion' || lastDiff.type === 'edit')
|
||||
newCodeEndLine = lastDiff.endLine
|
||||
else if (lastDiff.type === 'deletion')
|
||||
newFileEndLine = (diffZone.startLine - 1) + lastDiff.startLine
|
||||
else if (lastDiff.type === 'edit')
|
||||
newFileEndLine = (diffZone.startLine - 1) + lastDiff.endLine
|
||||
newCodeEndLine = lastDiff.startLine
|
||||
else
|
||||
throw new Error(`Void: diff.type not recognized on: ${lastDiff}`)
|
||||
}
|
||||
|
||||
|
||||
// lines are 1-indexed
|
||||
const newFileTop = llmText.split('\n').slice(diffZone.startLine, (newFileEndLine - 1) + 1).join('\n')
|
||||
const oldFileBottom = diffZone.originalCode.split('\n').slice((originalCodeStartLine - 1), Infinity).join('\n')
|
||||
const newCodeTop = llmText.split('\n').slice(0, (newCodeEndLine - 1) + 1).join('\n')
|
||||
const oldFileBottom = diffZone.originalCode.split('\n').slice((originalCodeStartLine - 1) + 1, Infinity).join('\n')
|
||||
|
||||
const newCode = `${newFileTop}\n${oldFileBottom}`
|
||||
const newCode = `${newCodeTop}\n${oldFileBottom}`
|
||||
|
||||
this._writeText(uri, newCode,
|
||||
{ startLineNumber: diffZone.startLine, startColumn: 1, endLineNumber: diffZone.endLine, endColumn: Number.MAX_SAFE_INTEGER, }, // 1-indexed
|
||||
{ shouldRealignDiffAreas: true }
|
||||
)
|
||||
|
||||
diffZone._streamState.line = newFileEndLine
|
||||
|
||||
|
||||
console.log('new DIFFZONE', diffZone.startLine, diffZone.endLine)
|
||||
// add diffZone.startLine to convert to right coordinate system (line in file, not in diffarea)
|
||||
diffZone._streamState.line = (diffZone.startLine - 1) + newCodeEndLine
|
||||
|
||||
return computedDiffs
|
||||
|
||||
|
|
@ -862,6 +858,54 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
|||
|
||||
|
||||
|
||||
// // if streaming, use diffs to figure out where to write new code
|
||||
// // these are two different coordinate systems - new and old line number
|
||||
// let newFileEndLine: number // get new[0...newStoppingPoint] with line=newStoppingPoint highlighted
|
||||
// let originalCodeStartLine: number // get original[oldStartingPoint...]
|
||||
|
||||
// const lastDiff = computedDiffs.pop()
|
||||
|
||||
// if (!lastDiff) {
|
||||
// // if the writing is identical so far, display no changes
|
||||
// newFileEndLine = diffZone.startLine
|
||||
// originalCodeStartLine = 1
|
||||
// }
|
||||
// else {
|
||||
// if (lastDiff.type === 'insertion') {
|
||||
// newFileEndLine = lastDiff.endLine
|
||||
// originalCodeStartLine = lastDiff.originalStartLine
|
||||
// }
|
||||
// else if (lastDiff.type === 'deletion') {
|
||||
// newFileEndLine = lastDiff.startLine
|
||||
// originalCodeStartLine = lastDiff.originalStartLine
|
||||
// }
|
||||
// else if (lastDiff.type === 'edit') {
|
||||
// newFileEndLine = lastDiff.endLine
|
||||
// originalCodeStartLine = lastDiff.originalStartLine
|
||||
// }
|
||||
// else {
|
||||
// throw new Error(`Void: diff.type not recognized on: ${lastDiff}`)
|
||||
// }
|
||||
// }
|
||||
|
||||
// diffZone._streamState.line = newFileEndLine
|
||||
|
||||
// // lines are 1-indexed
|
||||
// const newFileTop = llmText.split('\n').slice(diffZone.startLine, (newFileEndLine - 1)).join('\n')
|
||||
// const oldFileBottom = diffZone.originalCode.split('\n').slice((originalCodeStartLine - 1), Infinity).join('\n')
|
||||
|
||||
// const newCode = `${newFileTop}\n${oldFileBottom}`
|
||||
|
||||
// this._writeText(uri, newCode,
|
||||
// { startLineNumber: diffZone.startLine, startColumn: 1, endLineNumber: diffZone.endLine, endColumn: Number.MAX_SAFE_INTEGER, }, // 1-indexed
|
||||
// { shouldRealignDiffAreas: true }
|
||||
// )
|
||||
|
||||
|
||||
// return computedDiffs
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -934,8 +978,6 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
|||
let uri: URI
|
||||
let userMessage: string
|
||||
|
||||
console.log('AA')
|
||||
|
||||
if (featureName === 'Ctrl+L') {
|
||||
|
||||
const uri_ = this._getActiveEditorURI()
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ export const ModelDump = () => {
|
|||
|
||||
const disabled = !providerEnabled
|
||||
|
||||
return <div key={`${modelName}${providerName}`} className={`flex items-center justify-between gap-4 hover:bg-black/10 dark:hover:bg-gray-300/10 py-1 px-3 rounded-sm overflow-hidden cursor-default ${isNewProviderName ? 'mt-4' : ''}`}>
|
||||
return <div key={`${modelName}${providerName}`} className={`flex items-center justify-between gap-4 hover:bg-black/10 dark:hover:bg-gray-300/10 py-1 px-3 rounded-sm overflow-hidden cursor-default truncate ${isNewProviderName ? 'mt-4' : ''}`}>
|
||||
{/* left part is width:full */}
|
||||
<div className={`w-full flex items-center gap-4`}>
|
||||
<span className='min-w-40'>{isNewProviderName ? displayInfoOfProviderName(providerName).title : ''}</span>
|
||||
|
|
@ -204,7 +204,7 @@ export const ModelDump = () => {
|
|||
</div>
|
||||
{/* right part is anything that fits */}
|
||||
<div className='w-fit flex items-center gap-4'>
|
||||
<span className='opacity-50 whitespace-nowrap'>{isAutodetected ? '(detected locally)' : isDefault ? '' : '(custom model)'}</span>
|
||||
<span className='opacity-50'>{isAutodetected ? '(detected locally)' : isDefault ? '' : '(custom model)'}</span>
|
||||
|
||||
<VoidSwitch
|
||||
value={disabled ? false : !isHidden}
|
||||
|
|
|
|||
Loading…
Reference in a new issue