steelbrain / linter-ui-default

Default UI for the Atom Linter package
MIT License
84 stars 47 forks source link

A new untitled document inherits all linting messages in the project #667

Closed savetheclocktower closed 1 year ago

savetheclocktower commented 1 year ago

Let's say I've got a file open with some linter annotations.

Screen Shot 2023-01-31 at 11 34 02 AM

If I do Cmd-N from here, I get a new untitled file and an empty text editor… but it's already got a gutter marker.

Screen Shot 2023-01-31 at 11 35 15 AM

And at least one display marker for the text.

Screen Shot 2023-01-31 at 11 35 21 AM

I've tracked down the culprit. The filterMessages function will not filter out any messages if TextEditor#getPath() returns undefined, as it does for a brand-new file. So the new file inherits all the messages that were present in the original file. The markers, having been asked to mark invalid ranges, instead all mark from (0, 0) to (0, 0). The marker range grows as the user types.

This issue was introduced in this commit, in which an explicit null check was changed to a “falsy” check.

If this line was changed because of an oversight, then the fix is a one-liner. If this line was changed on purpose, and there is some other reason why it can't be reverted to the original null check, then the fix is not straightforward. @aminya, if you happen to remember, please let me know. If I don't hear otherwise I'll probably contribute the simple fix in a few days.

(I am aware that Atom has been discontinued, but I continue to use this package via Pulsar. They've reverse-engineered the package repository, so I think that publishing a new version of this package for Pulsar users would be pretty straightforward.)

savetheclocktower commented 1 year ago

If anyone else is affected by this bug and has found this issue: adding this to my init.js has solved it well enough for now.

atom.workspace.observeTextEditors(textEditor => {
  // Only occurs with new (untitled) documents.
  if (textEditor.getPath() !== undefined) { return; }
  setTimeout(() => {
    let decorations = textEditor.getDecorations();
    let toBeDeleted = decorations.filter(d => {
      if (d.properties.gutterName === 'linter-ui-default') { return true; }
      if (d.properties.class.includes('linter')) { return true; }
      return false;
    });
    for (let d of toBeDeleted) {
      d.destroy();
    }
  }, 50);
});
vegajdr commented 1 year ago

@savetheclocktower Thank you for the quick fix, works great for me, hopefully changing the one line will be sufficient

asiloisad commented 1 year ago

@savetheclocktower thank you for the temporary fix, but I hope the fix will published at pulsar package repository

aminya commented 1 year ago

PRs are welcome

asiloisad commented 1 year ago

https://github.com/steelbrain/linter-ui-default/pull/666