angelozerr / tslint-language-service

TypeScript 2.2.1 plugin for tslint
MIT License
188 stars 22 forks source link

TSLint LS changes the original diagnostics array #41

Closed anstarovoyt closed 7 years ago

anstarovoyt commented 7 years ago

Hi. There is a problem with the code: https://github.com/angelozerr/tslint-language-service/blob/master/src/index.ts#L304

It uses the original diagnostics object from the parent LS (doesn't copy it). The parent LS caches the object so every time when I call getSemanticDiagnostics (and the file wasn't changed so the parent LS can use the cache) it adds more and more tslint errors.

There is no way to reproduce the error in VSCode because it doesn't call getSemanticDiagnosticsSync.

we can fix the problem by adding this code:

if (prior === undefined) {
   prior = [];
} else {
   prior = prior.slice();
}

I guess you can also use a cache as the parent LS does it.

angelozerr commented 7 years ago

Thanks @anstarovoyt for your suggestion, is there any change to have a PR?