vscode-ibmi icon indicating copy to clipboard operation
vscode-ibmi copied to clipboard

Improved source date support

Open worksofliam opened this issue 3 years ago • 3 comments
trafficstars

Instead of tracking user changes, use a diff tool to determine what lines have changed to rebuild the source dates.

https://github.com/micnil/vscode-diff

worksofliam avatar Aug 18 '22 15:08 worksofliam

I wonder what the concept is for this. What will be diffed against what? If you have a clear idea how this would work and how it would be a definitive improvement, by all means give it a try. I have to say I have my doubts. I don't think any diff algorithm, no matter how sophisticated, is going to capture what source line dates in SEU capture. In fact, I see any diff-based scheme as basically a step toward ignoring dates (and just using Git) rather than preserving them. But you have exceeded expectations and proved people wrong plenty of times before; maybe this will be one of those times.

jkyeung avatar Aug 18 '22 16:08 jkyeung

Some progress on testing added lines:

image
  /**
   * @param {string} alias 
   * @param {vscode.TextDocument} currentDoc 
   */
  static calcNewSourceDates(alias, currentDoc) {
    const baseDates = allSourceDates[alias].slice();
    const oldSource = baseSource[alias];

    const eol = (currentDoc.eol === vscode.EndOfLine.LF ? `\n` : `\r\n`);

    const diffComputer = new DiffComputer(oldSource.split(eol), currentDoc.getText().split(eol), diffOptions);
    const diff = diffComputer.computeDiff();

    const currentDate = this.currentStamp();

    diff.changes.forEach(change => {
      const startIndex = change.modifiedStartLineNumber - 1;
      const removedLines = (change.originalEndLineNumber === 0 ? 0 : (change.modifiedEndLineNumber - change.modifiedStartLineNumber + 1)); 
      const changedLines = (change.modifiedEndLineNumber - change.modifiedStartLineNumber) + 1;
      baseDates.splice(startIndex, 0, ...Array(changedLines).fill(currentDate));
    });

    return baseDates;
  }

worksofliam avatar Aug 20 '22 16:08 worksofliam

@jkyeung If the PR gets approved, I would feel more comfy with enabling source dates by default in the future I think.

worksofliam avatar Aug 21 '22 22:08 worksofliam