Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit d417558

Browse files
committed
Implement custom find implementations extension
List all implementation block for traits, structs, and enums. Fails for traits which are implemented using derive Listed under wishlist #142 Requires the find-impls branch of https://github.com/jonasbb/rls_vscode
1 parent 2e5ba48 commit d417558

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

contributing.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,29 @@ the RLS.
301301

302302
The RLS uses some custom extensions to the Language Server Protocol.
303303

304-
* `rustDocument/diagnosticsBegin`: notification, no arguments. Sent from the RLS
305-
to a client before a build starts and before any diagnostics from a build are sent.
306-
* `rustDocument/diagnosticsEnd`: notification, no arguments. Sent from the RLS
307-
to a client when a build is complete (successfully or not, or even skipped)
308-
and all post-build analysis by the RLS is complete.
304+
#### RLS to LSP Client
305+
306+
These are all sent from the RLS to an LSP client and are only used to improve
307+
the user experience by showing progress indicators.
308+
309+
* `rustDocument/diagnosticsBegin`: notification, no arguments. Sent before a
310+
build starts and before any diagnostics from a build are sent.
311+
* `rustDocument/diagnosticsEnd`: notification, no arguments. Sent when a build
312+
is complete (successfully or not, or even skipped) and all post-build analysis
313+
by the RLS is complete.
309314
* `rustWorkspace/deglob`: message sent from the client to the RLS to initiate a
310315
deglob refactoring.
316+
317+
#### LSP Client to RLS
318+
319+
The following request is to support Rust specific features.
320+
321+
* `rustDocument/implementations`: request
322+
params: [`TextDocumentPositionParams`]
323+
result: [`Location`]`[]`
324+
325+
List all implementation blocks for a trait, struct, or enum denoted by the
326+
given text document position.
327+
328+
[`TextDocumentPositionParams`]: (https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#textdocumentpositionparams)
329+
[`Location`]: (https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#location)

src/actions/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,32 @@ impl ActionHandler {
253253
});
254254
}
255255

256+
pub fn find_impls<O: Output>(&self, id: usize, params: TextDocumentPositionParams, out: O) {
257+
let t = thread::current();
258+
let file_path = parse_file_path!(&params.text_document.uri, "find_impls");
259+
let span = self.convert_pos_to_span(file_path, params.position);
260+
let type_id = self.analysis.id(&span).expect("Analysis: Getting typeid from span");
261+
let analysis = self.analysis.clone();
262+
263+
let handle = thread::spawn(move || {
264+
let result = analysis.find_impls(type_id).map(|spans| {
265+
spans.into_iter().map(|x| ls_util::rls_to_location(&x)).collect()
266+
});
267+
t.unpark();
268+
result
269+
});
270+
thread::park_timeout(Duration::from_millis(::COMPILER_TIMEOUT));
271+
272+
let result = handle.join();
273+
trace!("find_impls: {:?}", result);
274+
match result {
275+
Ok(Ok(r)) => out.success(id, ResponseData::Locations(r)),
276+
_ => out.failure_message(id, ErrorCode::InternalError, "Find Implementations failed to complete successfully"),
277+
}
278+
}
279+
256280
pub fn on_open<O: Output>(&self, open: DidOpenTextDocumentParams, _out: O) {
257281
trace!("on_open: {:?}", open.text_document.uri);
258-
259282
let file_path = parse_file_path!(&open.text_document.uri, "on_open");
260283

261284
self.vfs.set_file(&file_path, &open.text_document.text);

src/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ messages! {
290290
"textDocument/codeAction" => CodeAction(CodeActionParams);
291291
"workspace/executeCommand" => ExecuteCommand(ExecuteCommandParams);
292292
"rustWorkspace/deglob" => Deglob(Location);
293+
"rustDocument/implementations" => FindImpls(TextDocumentPositionParams);
293294
}
294295
notifications {
295296
"initialized" => Initialized;
@@ -518,6 +519,7 @@ impl<O: Output> LsService<O> {
518519
Deglob(params) => { action: deglob };
519520
ExecuteCommand(params) => { action: execute_command };
520521
CodeAction(params) => { action: code_action };
522+
FindImpls(params) => { action: find_impls };
521523
}
522524
notifications {
523525
Initialized => {{ self.handler.inited().initialized(self.output.clone()) }};

0 commit comments

Comments
 (0)