-
Notifications
You must be signed in to change notification settings - Fork 167
[WIP] feat(diagnostics): ability to ignore some codes #172
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
[WIP] feat(diagnostics): ability to ignore some codes #172
Conversation
8cb903b
to
4c240bd
Compare
const { file, diagnostics: diagnosticsFromServer } = event.body; | ||
|
||
// `d.code` can be undefined | ||
const isDiagnosticAllowed = (d: tsp.Diagnostic) => !d.code || this.ignoredDiagnosticCodes.indexOf(d.code) === -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[].includes()
instead of indexOf
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used Array.every
in my first version but that's why it wasn't working in neovim.
/lib/diagnostic-queue.js:50 const isDiagnosticAllowed = (d) => this.ignoredDiagnosticCodes.every(c => d.code !== c);
TypeError: this.ignoredDiagnosticCodes.every is not a function
I'm not sure what's going on there, maybe an older nodeJS runtime; but I figured I'd do away with the headache and just stick to es5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.includes is supported since node 6 though so it won't be a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This project currently targets es6 (or 2015), and it looks like Array.includes
is only available for es7 (2016) compilation targets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Then never mind me although that target should probably be updated in a separate PR. That target is very old.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess targeting an older standard has the added benefit of maximizing compatibility, if for some reason you're stuck with an older node version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But ES7 is supported from Node7 (or Node 8 if you prefer "stable" release). It would be reasonable to require at least Node 8 as that is already 3 or 4 years old.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that targeting the current LTS version would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd lean toward getting the target bumped prior to this PR if either of you are interested. Based on https://nodejs.org/en/about/releases/ we should probably support Node v10 and up
Edit: Created #173 to keep track of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree bumping deps and updating the target JS version is high priority, but it's unrelated to the changes in this PR and shouldn't be a blocker for merging this imo.
const diagnosticsForThisFile = diagnostics.filter(d => d!.uri === doc.uri); | ||
assert.equal(diagnosticsForThisFile.length, 1, JSON.stringify(diagnostics)); | ||
const fileDiagnostics = diagnosticsForThisFile[0]!.diagnostics; | ||
assert.equal(fileDiagnostics.length, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test passes but only because the sample TS code does not generate a diagnostic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm, I'm not getting the same diagnostic error. I wonder what's up
But, switching the code to
x() {
return Promise.resolve(1).then(a => a + 1);
}
Does give me a diagnostic error:
fileDiagnostics: [
{
range: [Object],
message: "Cannot find name 'x'.",
severity: 1,
code: 2304,
source: 'typescript',
relatedInformation: undefined
}
]
}
Which I can ignore by setting ignoredDiagnosticCodes: [2304],
and that makes the tests pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll edit the test for this then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it has to do with the typescript version in use, or the target; I'm unclear as to which settings are used in the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed the test change on this fixup commit
4c240bd
to
d1529af
Compare
seems like should pass as workspace config instead of commandline. or could support both |
Good point IMO. And I would not introduce a command-line option for something like that. Command-line options should be reserved for toggling things that can't be changed once the server is started or are global in nature that can't be controlled with workspace settings. |
Agreed that this would be better, does typescript-language-server already support such configuration option (via an external config file) ? If not I think this is outside the scope of this PR. Thanks. |
The client can provide settings through the |
(there is also workspace/configuration which is more dynamic and can be set in more granular way in IDEs but since that's not currently supported, it would be out of scope to add it.) |
vim-lsp supports it too. You can change it via vimrc. |
I've re-implemented this PR in a slightly different way in #272 so closing this one. Thanks! |
Two things remain:
Fixed.
Regarding 1. It's working, but I'm failing at configuring neovim's LSP to spawn ts-lang-server with the new cli switch:fails to spawn ts-lang-server entirely; removing my new options and it's back to normal.Regarding 2., I can't make them fail :D the file snippet does not trigger the expected diagnostic for some reason I'm not clear why.
Will resolve #166 when merged.