aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--crates/ide/.DS_Storebin0 -> 6148 bytes
-rw-r--r--crates/rust-analyzer/src/config.rs9
-rw-r--r--crates/rust-analyzer/src/handlers.rs22
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs14
-rw-r--r--crates/rust-analyzer/src/main_loop.rs1
-rw-r--r--docs/dev/lsp-extensions.md29
-rw-r--r--editors/code/package.json9
-rw-r--r--editors/code/src/commands.ts21
-rw-r--r--editors/code/src/lsp_ext.ts6
-rw-r--r--editors/code/src/main.ts1
11 files changed, 105 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index b205bf3fb..7e097c015 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ crates/*/target
10generated_assists.adoc 10generated_assists.adoc
11generated_features.adoc 11generated_features.adoc
12generated_diagnostic.adoc 12generated_diagnostic.adoc
13.DS_Store
diff --git a/crates/ide/.DS_Store b/crates/ide/.DS_Store
new file mode 100644
index 000000000..a566736aa
--- /dev/null
+++ b/crates/ide/.DS_Store
Binary files differ
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 74a021dbf..372180ab5 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -398,13 +398,10 @@ impl Config {
398 } 398 }
399 399
400 if let Some(code_action) = &doc_caps.code_action { 400 if let Some(code_action) = &doc_caps.code_action {
401 match (code_action.data_support, &code_action.resolve_support) { 401 if let Some(resolve_support) = &code_action.resolve_support {
402 (Some(true), Some(resolve_support)) => { 402 if resolve_support.properties.iter().any(|it| it == "edit") {
403 if resolve_support.properties.iter().any(|it| it == "edit") { 403 self.client_caps.code_action_resolve = true;
404 self.client_caps.code_action_resolve = true;
405 }
406 } 404 }
407 _ => (),
408 } 405 }
409 } 406 }
410 } 407 }
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 95659b0db..782797e85 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1322,6 +1322,28 @@ pub(crate) fn handle_open_docs(
1322 Ok(remote.and_then(|remote| Url::parse(&remote).ok())) 1322 Ok(remote.and_then(|remote| Url::parse(&remote).ok()))
1323} 1323}
1324 1324
1325pub(crate) fn handle_open_cargo_toml(
1326 snap: GlobalStateSnapshot,
1327 params: lsp_ext::OpenCargoTomlParams,
1328) -> Result<Option<lsp_types::GotoDefinitionResponse>> {
1329 let _p = profile::span("handle_open_cargo_toml");
1330 let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
1331 let maybe_cargo_spec = CargoTargetSpec::for_file(&snap, file_id)?;
1332 if maybe_cargo_spec.is_none() {
1333 return Ok(None);
1334 }
1335
1336 let cargo_spec = maybe_cargo_spec.unwrap();
1337 let cargo_toml_path = cargo_spec.workspace_root.join("Cargo.toml");
1338 if !cargo_toml_path.exists() {
1339 return Ok(None);
1340 }
1341 let cargo_toml_url = to_proto::url_from_abs_path(&cargo_toml_path);
1342 let cargo_toml_location = Location::new(cargo_toml_url, Range::default());
1343 let res = lsp_types::GotoDefinitionResponse::from(cargo_toml_location);
1344 Ok(Some(res))
1345}
1346
1325fn implementation_title(count: usize) -> String { 1347fn implementation_title(count: usize) -> String {
1326 if count == 1 { 1348 if count == 1 {
1327 "1 implementation".into() 1349 "1 implementation".into()
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index a7c3028e4..a5c65fa3e 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -354,3 +354,17 @@ impl Request for ExternalDocs {
354 type Result = Option<lsp_types::Url>; 354 type Result = Option<lsp_types::Url>;
355 const METHOD: &'static str = "experimental/externalDocs"; 355 const METHOD: &'static str = "experimental/externalDocs";
356} 356}
357
358pub enum OpenCargoToml {}
359
360impl Request for OpenCargoToml {
361 type Params = OpenCargoTomlParams;
362 type Result = Option<lsp_types::GotoDefinitionResponse>;
363 const METHOD: &'static str = "experimental/openCargoToml";
364}
365
366#[derive(Serialize, Deserialize, Debug)]
367#[serde(rename_all = "camelCase")]
368pub struct OpenCargoTomlParams {
369 pub text_document: TextDocumentIdentifier,
370}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 6e6cac42e..68a53bbcb 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -438,6 +438,7 @@ impl GlobalState {
438 .on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve) 438 .on::<lsp_ext::CodeActionResolveRequest>(handlers::handle_code_action_resolve)
439 .on::<lsp_ext::HoverRequest>(handlers::handle_hover) 439 .on::<lsp_ext::HoverRequest>(handlers::handle_hover)
440 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs) 440 .on::<lsp_ext::ExternalDocs>(handlers::handle_open_docs)
441 .on::<lsp_ext::OpenCargoToml>(handlers::handle_open_cargo_toml)
441 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting) 442 .on::<lsp_types::request::OnTypeFormatting>(handlers::handle_on_type_formatting)
442 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol) 443 .on::<lsp_types::request::DocumentSymbolRequest>(handlers::handle_document_symbol)
443 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol) 444 .on::<lsp_types::request::WorkspaceSymbol>(handlers::handle_workspace_symbol)
diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md
index 77d4e0ec9..db9727bee 100644
--- a/docs/dev/lsp-extensions.md
+++ b/docs/dev/lsp-extensions.md
@@ -1,8 +1,8 @@
1<!--- 1<!---
2lsp_ext.rs hash: 4f86fb54e4b2870e 2lsp_ext.rs hash: 9d5daed5b25dc4f6
3 3
4If you need to change the above hash to make the test pass, please check if you 4If you need to change the above hash to make the test pass, please check if you
5need to adjust this doc as well and ping this issue: 5need to adjust this doc as well and ping this issue:
6 6
7 https://github.com/rust-analyzer/rust-analyzer/issues/4604 7 https://github.com/rust-analyzer/rust-analyzer/issues/4604
8 8
@@ -537,3 +537,28 @@ Such actions on the client side are appended to a hover bottom as command links:
537 +-----------------------------+ 537 +-----------------------------+
538 ... 538 ...
539``` 539```
540
541## Open Cargo.toml
542
543**Issue:** https://github.com/rust-analyzer/rust-analyzer/issues/6462
544
545This request is sent from client to server to open the current project's Cargo.toml
546
547**Method:** `experimental/openCargoToml`
548
549**Request:** `OpenCargoTomlParams`
550
551**Response:** `Location | null`
552
553
554### Example
555
556```rust
557// Cargo.toml
558[package]
559// src/main.rs
560
561/* cursor here*/
562```
563
564`experimental/openCargoToml` returns a single `Link` to the start of the `[package]` keyword.
diff --git a/editors/code/package.json b/editors/code/package.json
index 6db78a99a..3768679fe 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -187,6 +187,11 @@
187 "command": "rust-analyzer.openDocs", 187 "command": "rust-analyzer.openDocs",
188 "title": "Open docs under cursor", 188 "title": "Open docs under cursor",
189 "category": "Rust Analyzer" 189 "category": "Rust Analyzer"
190 },
191 {
192 "command": "rust-analyzer.openCargoToml",
193 "title": "Open Cargo.toml",
194 "category": "Rust Analyzer"
190 } 195 }
191 ], 196 ],
192 "keybindings": [ 197 "keybindings": [
@@ -1065,6 +1070,10 @@
1065 { 1070 {
1066 "command": "rust-analyzer.openDocs", 1071 "command": "rust-analyzer.openDocs",
1067 "when": "inRustProject" 1072 "when": "inRustProject"
1073 },
1074 {
1075 "command": "rust-analyzer.openCargoToml",
1076 "when": "inRustProject"
1068 } 1077 }
1069 ] 1078 ]
1070 } 1079 }
diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts
index cf34622c3..92bc4d7f7 100644
--- a/editors/code/src/commands.ts
+++ b/editors/code/src/commands.ts
@@ -188,6 +188,27 @@ export function parentModule(ctx: Ctx): Cmd {
188 }; 188 };
189} 189}
190 190
191export function openCargoToml(ctx: Ctx): Cmd {
192 return async () => {
193 const editor = ctx.activeRustEditor;
194 const client = ctx.client;
195 if (!editor || !client) return;
196
197 const response = await client.sendRequest(ra.openCargoToml, {
198 textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
199 });
200 if (!response) return;
201
202 const uri = client.protocol2CodeConverter.asUri(response.uri);
203 const range = client.protocol2CodeConverter.asRange(response.range);
204
205 const doc = await vscode.workspace.openTextDocument(uri);
206 const e = await vscode.window.showTextDocument(doc);
207 e.selection = new vscode.Selection(range.start, range.start);
208 e.revealRange(range, vscode.TextEditorRevealType.InCenter);
209 };
210}
211
191export function ssr(ctx: Ctx): Cmd { 212export function ssr(ctx: Ctx): Cmd {
192 return async () => { 213 return async () => {
193 const editor = vscode.window.activeTextEditor; 214 const editor = vscode.window.activeTextEditor;
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index d320c3cd7..5e877ce65 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -114,3 +114,9 @@ export interface CommandLinkGroup {
114} 114}
115 115
116export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>('experimental/externalDocs'); 116export const openDocs = new lc.RequestType<lc.TextDocumentPositionParams, string | void, void>('experimental/externalDocs');
117
118export const openCargoToml = new lc.RequestType<OpenCargoTomlParams, lc.Location, void>("experimental/openCargoToml");
119
120export interface OpenCargoTomlParams {
121 textDocument: lc.TextDocumentIdentifier;
122}
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 09543e348..2f3dde8ac 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -111,6 +111,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
111 ctx.registerCommand('debug', commands.debug); 111 ctx.registerCommand('debug', commands.debug);
112 ctx.registerCommand('newDebugConfig', commands.newDebugConfig); 112 ctx.registerCommand('newDebugConfig', commands.newDebugConfig);
113 ctx.registerCommand('openDocs', commands.openDocs); 113 ctx.registerCommand('openDocs', commands.openDocs);
114 ctx.registerCommand('openCargoToml', commands.openCargoToml);
114 115
115 defaultOnEnter.dispose(); 116 defaultOnEnter.dispose();
116 ctx.registerCommand('onEnter', commands.onEnter); 117 ctx.registerCommand('onEnter', commands.onEnter);