Fixed incorrect handling of client-initiated progress reporting for "…#2546
Fixed incorrect handling of client-initiated progress reporting for "…#2546
Conversation
…onReferences" and "onExecuteCommand" handlers in language server.
|
Looks as nice as it could to me, given the circumstances. :) I suppose the library could expose some property ( |
| // is an actual client-side progress reporter or a dummy (null) progress reporter | ||
| // created by the LSP library. If it's the latter, we'll create a server-initiated | ||
| // progress reporter. | ||
| if (reporter.constructor.name !== 'NullProgressReporter') { |
There was a problem hiding this comment.
I'm not sure that this will work when we package (here or pylance), as webpack will run our code through terser which strips out names. It'd appear to work when just debugging as that runs unoptimized.
There was a problem hiding this comment.
Oh, that's a good point. Can you think of any other ways for us to do this check? If not, we may need to wait for a change in the LSP library.
There was a problem hiding this comment.
The best hack I can come up with is to call attachWorkDone to get a NullProgressReporter, then compare the constructors for identity.
const nullProgressReporter = attachWorkDone(undefined as any, undefined);
// ...
private async _getProgressReporter(reporter: WorkDoneProgressReporter, title: string, token: CancellationToken) {
if (reporter.constructor !== nullProgressReporter.constructor) { .... }
}There was a problem hiding this comment.
That's clever. Very hacky, but clever.
There was a problem hiding this comment.
Oop, no, that doesn't work.
> class Foo {}
undefined
> Foo.constructor === Foo.constructor
true
> class Bar {}
undefined
> Foo.constructor === Bar.constructor
true
There was a problem hiding this comment.
No, I'm silly. Those are the class's constructors, which are of course equal because that's object.
> (new Foo()).constructor === (new Foo()).constructor
true
> (new Foo()).constructor === (new Bar()).constructor
false
The hack should work. Sorry for the noise.
…onReferences" and "onExecuteCommand" handlers in language server.