minor changes

This commit is contained in:
Andrew Pareles 2024-12-23 00:16:37 -08:00
parent ffb0549c7c
commit ee8b98ff74
2 changed files with 60 additions and 52 deletions

View file

@ -29,6 +29,7 @@
// import { URI } from '../../../../base/common/uri.js';
// import { LLMFeatureSelection, ServiceSendLLMMessageParams } from '../../../../platform/void/common/llmMessageTypes.js';
// import { ILLMMessageService } from '../../../../platform/void/common/llmMessageService.js';
// import { IZoneStyleService } from './helperServices/zoneStyleService.js';
// const configOfBG = (color: Color) => {
@ -132,6 +133,7 @@
// @IUndoRedoService private readonly _undoRedoService: IUndoRedoService, // undoRedo service is the history of pressing ctrl+z
// @ILanguageService private readonly _langService: ILanguageService,
// @ILLMMessageService private readonly _llmMessageService: ILLMMessageService,
// @IZoneStyleService private readonly _zoneStyleService: IZoneStyleService,
// ) {
// super();
@ -150,20 +152,16 @@
// // it's as if we just called _write, now all we need to do is realign and refresh
// if (this._weAreWriting) return
// const uri = model.uri
// // realign
// for (const change of e.changes) { this._realignAllDiffAreasLines(uri, change.text, change.range) }
// // refresh
// this._refreshDiffsInURI(uri)
// })
// )
// }
// // initialize all existing models
// // initialize all existing models + initialize when a new model mounts
// for (let model of this._modelService.getModels()) { initializeModel(model) }
// // initialize whenever a new model mounts
// this._register(this._modelService.onModelAdded(model => initializeModel(model)));
// // this function adds listeners to refresh styles when editor changes tab
// let initializeEditor = (editor: ICodeEditor) => {
// const uri = editor.getModel()?.uri ?? null
@ -175,11 +173,9 @@
// if (e.newModelUrl) this._refreshDiffsInURI(e.newModelUrl)
// }))
// }
// // add listeners for all existing editors
// // add listeners for all existing editors + listen for editor being added
// for (let editor of this._editorService.listCodeEditors()) { initializeEditor(editor) }
// // add listeners when an editor is created
// this._register(this._editorService.onCodeEditorAdd(editor => { console.log('ADD EDITOR'); initializeEditor(editor) }))
// this._register(this._editorService.onCodeEditorRemove(editor => { console.log('REMOVE EDITOR'); initializeEditor(editor) }))
// this._register(this._editorService.onCodeEditorAdd(editor => { initializeEditor(editor) }))
// }
@ -227,14 +223,16 @@
// }
// private _addDiffStylesToEditor = (editor: ICodeEditor, diff: Diff) => {
// private _addDiffStylesToURI = (uri: URI, diff: Diff) => {
// const { type, diffid } = diff
// const disposeInThisEditorFns: (() => void)[] = []
// const model = this._modelService.getModel(uri)
// // green decoration and minimap decoration
// if (type !== 'deletion') {
// const fn = this._addLineDecoration(editor.getModel(), diff.startLine, diff.endLine, 'void-greenBG', {
// const fn = this._addLineDecoration(model, diff.startLine, diff.endLine, 'void-greenBG', {
// minimap: { color: { id: 'minimapGutter.addedBackground' }, position: 2 },
// overviewRuler: { color: { id: 'editorOverviewRuler.addedForeground' }, position: 7 }
// })
@ -244,47 +242,55 @@
// // red in a view zone
// if (type !== 'insertion') {
// editor.changeViewZones(accessor => {
// const consistentZoneId = this._zoneStyleService.addConsistentZoneToURI(
// const domNode = document.createElement('div');
// domNode.className = 'void-redBG'
// uri,
// const renderOptions = RenderOptions.fromEditor(editor);
// // applyFontInfo(domNode, renderOptions.fontInfo)
// (editor) => {
// const domNode = document.createElement('div');
// domNode.className = 'void-redBG'
// // Compute view-lines based on redText
// const redText = diff.originalCode
// const lines = redText.split('\n');
// const lineTokens = lines.map(line => LineTokens.createFromTextAndMetadata([{ text: line, metadata: 0 }], this._langService.languageIdCodec));
// const source = new LineSource(lineTokens, lines.map(() => null), false, false)
// const result = renderLines(source, renderOptions, [], domNode);
// const renderOptions = RenderOptions.fromEditor(editor);
// // applyFontInfo(domNode, renderOptions.fontInfo)
// const viewZone: IViewZone = {
// // afterLineNumber: computedDiff.startLine - 1,
// afterLineNumber: type === 'edit' ? diff.endLine : diff.startLine - 1,
// heightInLines: result.heightInLines,
// minWidthInPx: result.minWidthInPx,
// domNode: domNode,
// marginDomNode: document.createElement('div'), // displayed to left
// suppressMouseDown: true,
// };
// // Compute view-lines based on redText
// const redText = diff.originalCode
// const lines = redText.split('\n');
// const lineTokens = lines.map(line => LineTokens.createFromTextAndMetadata([{ text: line, metadata: 0 }], this._langService.languageIdCodec));
// const source = new LineSource(lineTokens, lines.map(() => null), false, false)
// const result = renderLines(source, renderOptions, [], domNode);
// const viewZone: IViewZone = {
// // afterLineNumber: computedDiff.startLine - 1,
// afterLineNumber: type === 'edit' ? diff.endLine : diff.startLine - 1,
// heightInLines: result.heightInLines,
// minWidthInPx: result.minWidthInPx,
// domNode: domNode,
// marginDomNode: document.createElement('div'), // displayed to left
// suppressMouseDown: true,
// };
// return viewZone
// },
// (editor) => {
// // Accept | Reject widget
// const buttonsWidget = new AcceptRejectWidget({
// editor,
// onAccept: () => { this.acceptDiff({ diffid }) },
// onReject: () => { this.rejectDiff({ diffid }) },
// diffid: diffid.toString(),
// startLine: diff.startLine,
// })
// return () => buttonsWidget.dispose()
// }
// )
// disposeInThisEditorFns.push(() => { this._zoneStyleService.removeConsistentZoneFromURI(consistentZoneId) })
// const zoneId = accessor.addZone(viewZone)
// disposeInThisEditorFns.push(() => { editor.changeViewZones(accessor => { if (zoneId) accessor.removeZone(zoneId) }) })
// });
// }
// // Accept | Reject widget
// const buttonsWidget = new AcceptRejectWidget({
// editor,
// onAccept: () => { this.acceptDiff({ diffid }) },
// onReject: () => { this.rejectDiff({ diffid }) },
// diffid: diffid.toString(),
// startLine: diff.startLine,
// })
// disposeInThisEditorFns.push(() => { buttonsWidget.dispose() })
// const disposeInEditor = () => { disposeInThisEditorFns.forEach(f => f()) }
// return disposeInEditor;
@ -499,7 +505,6 @@
// this._clearAllDiffsAndStyles(uri)
// // 2. recompute all diffs on each editor with this URI
// const editors = this._editorService.listCodeEditors().filter(editor => editor.getModel()?.uri.fsPath === uri.fsPath)
// const fullFileText = this._readURI(uri) ?? ''
@ -520,10 +525,8 @@
// diffareaid: diffArea.diffareaid,
// }
// for (let editor of editors) {
// const fn = this._addDiffStylesToEditor(editor, newDiff)
// this.removeStylesFnsOfURI[uri.fsPath].add(() => fn())
// }
// const fn = this._addDiffStylesToURI(uri, newDiff)
// this.removeStylesFnsOfURI[uri.fsPath].add(fn)
// this.diffOfId[diffid] = newDiff
// diffArea._diffOfId[diffid] = newDiff

View file

@ -150,16 +150,20 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
// it's as if we just called _write, now all we need to do is realign and refresh
if (this._weAreWriting) return
const uri = model.uri
// realign
for (const change of e.changes) { this._realignAllDiffAreasLines(uri, change.text, change.range) }
// refresh
this._refreshDiffsInURI(uri)
})
)
}
// initialize all existing models + initialize when a new model mounts
// initialize all existing models
for (let model of this._modelService.getModels()) { initializeModel(model) }
// initialize whenever a new model mounts
this._register(this._modelService.onModelAdded(model => initializeModel(model)));
// this function adds listeners to refresh styles when editor changes tab
let initializeEditor = (editor: ICodeEditor) => {
const uri = editor.getModel()?.uri ?? null
@ -171,16 +175,17 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
if (e.newModelUrl) this._refreshDiffsInURI(e.newModelUrl)
}))
}
// add listeners for all existing editors + listen for editor being added
// add listeners for all existing editors
for (let editor of this._editorService.listCodeEditors()) { initializeEditor(editor) }
this._register(this._editorService.onCodeEditorAdd(editor => { initializeEditor(editor) }))
// add listeners when an editor is created
this._register(this._editorService.onCodeEditorAdd(editor => { console.log('ADD EDITOR'); initializeEditor(editor) }))
this._register(this._editorService.onCodeEditorRemove(editor => { console.log('REMOVE EDITOR'); initializeEditor(editor) }))
}
// highlight the region
private _addLineDecoration = (model: ITextModel | null, startLine: number, endLine: number, className: string, options?: Partial<IModelDecorationOptions>) => {
if (model === null) return