mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58: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(
|
this._register(
|
||||||
model.onDidChangeContent(e => {
|
model.onDidChangeContent(e => {
|
||||||
// it's as if we just called _write, now all we need to do is realign and refresh
|
// 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
|
if (this.weAreWriting) return
|
||||||
|
const uri = model.uri
|
||||||
this._onUserChangeContent(uri, e)
|
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 } }) {
|
private _onInternalChangeContent(uri: URI, { shouldRealign }: { shouldRealign: false | { newText: string, oldRange: IRange } }) {
|
||||||
if (shouldRealign) {
|
if (shouldRealign) {
|
||||||
const { newText, oldRange } = shouldRealign
|
const { newText, oldRange } = shouldRealign
|
||||||
|
console.log('realiging', newText, oldRange)
|
||||||
this._realignAllDiffAreasLines(uri, newText, oldRange)
|
this._realignAllDiffAreasLines(uri, newText, oldRange)
|
||||||
}
|
}
|
||||||
this._refreshStylesAndDiffsInURI(uri)
|
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
|
// if streaming, use diffs to figure out where to write new code
|
||||||
// these are two different coordinate systems - new and old line number
|
// 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)
|
let originalCodeStartLine: number // get original[oldStartingPoint...] (line in the original code, so starts at 1)
|
||||||
|
|
||||||
const lastDiff = computedDiffs.pop()
|
const lastDiff = computedDiffs.pop()
|
||||||
|
|
||||||
if (!lastDiff) {
|
if (!lastDiff) {
|
||||||
|
console.log('!lastDiff')
|
||||||
// if the writing is identical so far, display no changes
|
// if the writing is identical so far, display no changes
|
||||||
originalCodeStartLine = 1
|
originalCodeStartLine = 1
|
||||||
newFileEndLine = diffZone.startLine
|
newCodeEndLine = 1
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// add diffZone.startLine to convert to right coordinate system (line in file, not in diffarea)
|
|
||||||
originalCodeStartLine = lastDiff.originalStartLine
|
originalCodeStartLine = lastDiff.originalStartLine
|
||||||
if (lastDiff.type === 'insertion')
|
if (lastDiff.type === 'insertion' || lastDiff.type === 'edit')
|
||||||
newFileEndLine = (diffZone.startLine - 1) + lastDiff.endLine
|
newCodeEndLine = lastDiff.endLine
|
||||||
else if (lastDiff.type === 'deletion')
|
else if (lastDiff.type === 'deletion')
|
||||||
newFileEndLine = (diffZone.startLine - 1) + lastDiff.startLine
|
newCodeEndLine = lastDiff.startLine
|
||||||
else if (lastDiff.type === 'edit')
|
|
||||||
newFileEndLine = (diffZone.startLine - 1) + lastDiff.endLine
|
|
||||||
else
|
else
|
||||||
throw new Error(`Void: diff.type not recognized on: ${lastDiff}`)
|
throw new Error(`Void: diff.type not recognized on: ${lastDiff}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// lines are 1-indexed
|
// lines are 1-indexed
|
||||||
const newFileTop = llmText.split('\n').slice(diffZone.startLine, (newFileEndLine - 1) + 1).join('\n')
|
const newCodeTop = llmText.split('\n').slice(0, (newCodeEndLine - 1) + 1).join('\n')
|
||||||
const oldFileBottom = diffZone.originalCode.split('\n').slice((originalCodeStartLine - 1), Infinity).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,
|
this._writeText(uri, newCode,
|
||||||
{ startLineNumber: diffZone.startLine, startColumn: 1, endLineNumber: diffZone.endLine, endColumn: Number.MAX_SAFE_INTEGER, }, // 1-indexed
|
{ startLineNumber: diffZone.startLine, startColumn: 1, endLineNumber: diffZone.endLine, endColumn: Number.MAX_SAFE_INTEGER, }, // 1-indexed
|
||||||
{ shouldRealignDiffAreas: true }
|
{ shouldRealignDiffAreas: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
diffZone._streamState.line = newFileEndLine
|
// add diffZone.startLine to convert to right coordinate system (line in file, not in diffarea)
|
||||||
|
diffZone._streamState.line = (diffZone.startLine - 1) + newCodeEndLine
|
||||||
|
|
||||||
console.log('new DIFFZONE', diffZone.startLine, diffZone.endLine)
|
|
||||||
|
|
||||||
return computedDiffs
|
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 uri: URI
|
||||||
let userMessage: string
|
let userMessage: string
|
||||||
|
|
||||||
console.log('AA')
|
|
||||||
|
|
||||||
if (featureName === 'Ctrl+L') {
|
if (featureName === 'Ctrl+L') {
|
||||||
|
|
||||||
const uri_ = this._getActiveEditorURI()
|
const uri_ = this._getActiveEditorURI()
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ export const ModelDump = () => {
|
||||||
|
|
||||||
const disabled = !providerEnabled
|
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 */}
|
{/* left part is width:full */}
|
||||||
<div className={`w-full flex items-center gap-4`}>
|
<div className={`w-full flex items-center gap-4`}>
|
||||||
<span className='min-w-40'>{isNewProviderName ? displayInfoOfProviderName(providerName).title : ''}</span>
|
<span className='min-w-40'>{isNewProviderName ? displayInfoOfProviderName(providerName).title : ''}</span>
|
||||||
|
|
@ -204,7 +204,7 @@ export const ModelDump = () => {
|
||||||
</div>
|
</div>
|
||||||
{/* right part is anything that fits */}
|
{/* right part is anything that fits */}
|
||||||
<div className='w-fit flex items-center gap-4'>
|
<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
|
<VoidSwitch
|
||||||
value={disabled ? false : !isHidden}
|
value={disabled ? false : !isHidden}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue