CodinGame / monaco-vscode-api

VSCode public API plugged on the monaco editor
MIT License
226 stars 31 forks source link

Local file diff worker access for create diff decorators #411

Closed BusinessDuck closed 5 months ago

BusinessDuck commented 5 months ago

Diff decoration af you may know its an field before line with blue, green or red icons to determine modified/deleted and added statements between saved and local file. image

In browsers we don't have integrated git system, but we can highlight unsaved changes like a charm with diff inline decorators.

In vscode we have a web worker src/vs/base/worker/workerMain.ts that worker can return a diff data between registered models which can be recieved from DiffComputer class. Te recieve that data we need send a special command to web worker and get the result with deltas described by ILineChange interface. All of this changes can be transofrmed to human readable object by algo:

const serializeLineChange = (change: ILineChange): EditorChange => {
    const isAdded = change.originalEndLineNumber === 0;
    const isRemoved = change.modifiedEndLineNumber === 0;
    const isModified = !isAdded && !isRemoved;

    return {
        isAdded,
        isRemoved,
        isModified,
        originalStartLineNumber: change.originalStartLineNumber,
        originalEndLineNumber: change.originalEndLineNumber,
        modifiedStartLineNumber: change.modifiedStartLineNumber,
        modifiedEndLineNumber: change.modifiedEndLineNumber,
    };
};

And we can visualise all changes here (for unsaved files):

image image

To achieve that feature we need: 1) Access to existing web worker with DiffComputer 2) Register original and unsaved models ad different before computation 3) Create or re-use current worker command (that actiually already used by DiffEditor to get deltas for editor visualisation)

CGNonofr commented 5 months ago

I'm sorry, what is the issue exactly?

BusinessDuck commented 5 months ago

Its not an issue, just feature discuss

CGNonofr commented 5 months ago

Then can you please explain once again in a more concise way what you want to achieve?

BusinessDuck commented 5 months ago

screencast 2024-04-17 18-23-30

I want to suggest integrate a diff decorators without a git. Just between saved and unsaved state of the file. Or virtual versioning systems that depends from the env

CGNonofr commented 5 months ago

Are you talking about a feature that doesn't exist on VSCode and you want to see implemented here?

What prevents you from implementing it as a VSCode extension?

You are referring to Git and everything related to Git in VSCode is an extension so I assume what you are trying to achieve is doable via an extension

BusinessDuck commented 5 months ago

Lets discuss it here, if i want to implement the extension for monaco-vscode-api based on git decorators (but adapted to current file system) is it OK way?

CGNonofr commented 5 months ago

As always I'm not sure to follow

the extension for monaco-vscode-api

monaco-vscode-api just uses VSCode extensions

based on git decorators

What are "git decorators"? are you talking about the decorator added by the git extensions?

but adapted to current file system

What is "current" filesystem? Why does anything need to be "adapted"?