Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved source date support #819

Closed
worksofliam opened this issue Aug 18, 2022 · 3 comments
Closed

Improved source date support #819

worksofliam opened this issue Aug 18, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@worksofliam
Copy link
Contributor

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 worksofliam added the enhancement New feature or request label Aug 18, 2022
@jkyeung
Copy link

jkyeung commented Aug 18, 2022

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.

@worksofliam
Copy link
Contributor Author

worksofliam commented Aug 20, 2022

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants