-
Notifications
You must be signed in to change notification settings - Fork 1.9k
vscode: migrate to request type api #3299
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
vscode: migrate to request type api #3299
Conversation
| * This file mirrors `crates/rust-analyzer/src/req.rs` declarations. | ||
| */ | ||
|
|
||
| import { RequestType, TextDocumentIdentifier, Position, Range, TextDocumentPositionParams, Location, NotificationType, WorkspaceEdit } from "vscode-languageclient"; |
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.
import * as lc?
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.
Followed the same import pattern we have in req.rs
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.
Okay, done
| @@ -0,0 +1,117 @@ | |||
| /** | |||
| * This file mirrors `crates/rust-analyzer/src/req.rs` declarations. | |||
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.
it's unfortunate that the files are named differently, but I also actively dislike both names :)
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.
As an aside I really dislike req.rs... it should probably be custom_requests.rs or something with only the imports required to support that file. We end up importing a lot from that file in handlers and conv.
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.
The name is awesome, unless come up with better!
| tokenSource.token | ||
| ) | ||
| return sendRequestWithRetry(this.ctx.client, ra.inlayHints, request, tokenSource.token) | ||
| .catch(_ => null) |
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.
Might as well swtich to client.logFailedRequest here and elsewhere?
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.
Repeating client.logFailedRequest everywhere would be very annoying. What if we add the function that wraps sendRequest and logs on failure or wrap the client with our own RaClient?
class RustAnalyzerClient {
inner: lc.LanguageClient;
async sendRequest(...params) {
return this.inner.sendRequest(...params).catch(err => {
this.inner.logFailedRequest(...);
throw err;
});
}
async sendRequestWithRetry(...params) { ... }
get p2c() { return this.inner.protocol2CodeConverter; }
get c2p() { return this.inner.code2ProtocolConverter; }
/* stuff */
}| } | ||
|
|
||
| interface InlayHint { | ||
| range: vscode.Range; |
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.
@SomeoneToIgnore what was the reason to declare vscode.Range instead of lc.Range here? It worked all the time since their shape is structurally the same, but we may not rely on this, so I explicitly added protocol2CodeConverter.asRange() call here...
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.
No particular reason, pick the one that suits better and works still.
|
|
||
| type Option<T> = null | T; | ||
| type Vec<T> = T[]; | ||
| type FxHashMap<K extends PropertyKey, V> = Record<K, V>; |
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.
Cheatsheet for Rust -> TS transformations...
| (_error: any) => { | ||
| // FIXME: switch to the more modern (?) typed request infrastructure | ||
| // client.logFailedRequest(OnEnterRequest.type, error); | ||
| return Promise.resolve(null); |
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.
FYI: @matklad there is no need to wrap the return value into a promise in the then(onfulfilled, onrejected)/catch(onrejected) handlers.
| if (!editor || editor.document.languageId !== 'rust') return; | ||
| if (!ctx.config.highlightingOn) return; | ||
| const client = ctx.client; | ||
| if (!client) return; |
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.
We should get rid of these if statements, since the client is not nullable today...
But this deserves a separate PR.
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.
yup, there's FIXME about this in main.ts
kjeremy
left a comment
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.
Makes sense.
|
bors r+ |
Build succeeded |
More type-safety to the god of type-safety.