-
Notifications
You must be signed in to change notification settings - Fork 328
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
Add support for middleware in onProgress #690
Conversation
The type is only syntactic sugar that helps the TS compiler with type inference. Since |
@dbaeumer tried that, but still didn't work. I tried adding explicit types to all of them, but it still fails (seems like it might not like a handler for only a specific set of types for
I tried many combinations of types in the args, but can't seem to make it pass. I've added I don't think there's anything else outstanding (besides removing the (also rebased on latest master). |
@DanTup I checked-out our code and I don't see any compile errors. Neither in the watch, compile task or the TS server. |
I see (as any) |
The problem seems to be that type inference doesn't work with properties (which in on or the other way makes sense). So all I can think about for now that in the middleware we make this more explicit. (we don't have a general request middleware either). So I opt we add instead the following method: handleWorkDoneProgress?: (this: void, type: typeof WorkDoneProgress.type, token: ProgressToken, params: WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd, next: HandleProgressSignature<WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd>) => void; When VS Code will support partial result progress we will add another method. |
And then in the test middleware.handleWorkDoneProgress = (type, token, params, next) => {
if (token === progressToken) {
middlewareEvents.push(params);
if (params.kind === 'end')
{setImmediate(resolve);}
}
return next(type, token, params);
}; |
@dbaeumer Yeah, I added the I'll try your suggestions shortly, thanks! btw - I haven't yet tested this "for real" in my project (only the test here), though I would like to - but I couldn't figure out how to correctly build the package in a way I can use it from my extension.. Is there an easy way to do that? |
And even better. Now that the method is explict you can remove the |
And we should rename |
@dbaeumer then what should |
Yes, that makes sense. |
@dbaeumer ok, assuming I understood correctly, I have a remaining type error here: I believe this is because my |
Still has one remaining type error.
Actually, it seems like
I've pushed the changes so far (which have types errors) if you want to have a poke - I'm not sure where to go next. Thanks! |
@DanTup the if needs to be |
That's what seemed right to me, though I got the message above.
Thanks! Let me know if you want me to do any more :-) |
OK. Here you go: Change the export namespace WorkDoneProgress {
export const type = new ProgressType<WorkDoneProgressBegin | WorkDoneProgressReport | WorkDoneProgressEnd>();
export function is(value: ProgressType<any>): value is typeof type {
return value === type;
}
} However the compiler still complains of calling something that is types as handleWorkDoneProgress(token, params, () => handler(params as unknown as P)); See the cast to That makes it work for me. |
And I for change the |
@dbaeumer looks like that did it, thanks! I've pushed the changes. Is there an easy way for me to build/reference this package in my local extension to verify it does everything I need without needing it to be published? I've run Thanks! |
Looks like at some point I committed some formatting changes - I think they're probably for the better (I usually have format-on-save enabled), but if you'd prefer they weren't in this PR let me know and I'll undo the changes that aren't related to this! |
The format changes look ok to me. |
Great! Did you see the other question in the previous comment about using the package locally? The folder structure looked slightly different to what's in my existing node_modules, so I wasn't sure if that's the right way. It'd come in handy for testing my other PR too. Thanks! :-) |
Regarding
Couple of options:
|
Let me know when you think the PR is ready to be merged. |
@dbaeumer I couldn't get I have one issue when running it in my real project/server, and that is that only the first progress seems to fire the middleware. However, I'm unsure whether this is my server behaving incorrectly. I'm creating the token once, and then sending begin/end and then another begin/end. Is this valid? Should I be able to reuse the same token even after it "ended", or am I supposed to re-create it. If I'm supposed to be able to reuse it, something seems wrong (though I'm not sure where) and I'll try to do some digging later. Thanks! |
Actually a token obtained by a create shouldn't be used after an end anymore. As you can see here the progress part is removed after a end has been received. |
I clarified this in the spec. |
@dbaeumer aha, that explains it. Changing the server to re-create the tokens seems to fix it - my middleware is firing exaactly as expected: So if you're happy with this, it's good to merge. Thanks! |
Actually, I just triggered this error. Just trying to track it down. In the LSP log it seems like I always did create->begin->end, so this is probably related to my changes.
|
@dbaeumer I found another issue in the server that's making it difficult for me to debug the above, so might not get to the bottom of this today. Please hold off merging this, and I'll ping you when I've figured out what's happening (I think it's a bug here, though it's possible it's a server timing issue - my server tests are failing in strange ways too). |
+ remove standard handler as the WorkDoneProgressCreateRequest call installs its own
@dbaeumer I tracked down the issue in my server - I was reusing a token ID for the events, but because it was async, I wasn't correctly waiting for the old ones I have pushed a slight change to the tests here though, so the servers sample progress now creates a token. This also meant removing the (non-middleware) onProgress handler (because the library registers its own when the token is created). Let me know if you think this is ok or we should revise it. Otherwise, this appears to be all working correctly for me and it's good to go. |
Thanks a lot for providing the PR. Highly appreciated. |
@dbaeumer I think this is working as expected now, however I have some type errors I can't figure out how to resolve: