Skip to content

Commit f5401f6

Browse files
committed
Auto merge of rust-lang#14175 - jmviz:openDocs-context-menu, r=lnicola
add openDocs command to context menu in VS Code extension This adds the `openDocs` command to the VS Code context menu. I believe there are probably many user who are unaware of this command existing in the rust analyzer extension, and that this should enhance the discoverability of the command. Additionally, even if people are aware of this capability, it's helpful to have this in the context menu anyway; for example, one might forget the name of the command, or the keybinding they have assigned to it. I think that opening docs is a common enough action to warrant the extra line added to the context menu. This makes a few other small changes as well. There are two minor style changes to increase style consistency. First, it changes the titles of the two commands that the rust analyzer extension will contribute to the context menu to title case. All standard VS Code commands that appear in the context menu are in title case. Second, it shortens the title of the `openDocs` command from `Open docs under cursor` to `Open Docs`. The implicit assumption in the standard VS Code context menu command titles is that the action applies to the symbol under the cursor: `Go to Definition`, `Find All References`, etc. Note that since these are changes to the command titles, rather than the command names themselves, these changes will not break any users' existing keybindings for these commands. Second, this adds further restrictions to the `where` clauses of the two commands that the rust analyzer extension will contribute to the context menu, so that the two commands will appear in the context menu only when in a Rust project **and** within a Rust file. Say you have a Python or bash script inside your Rust project. Having these commands appear in the context menu when you right click a symbol in such a non-Rust file is extraneous and potentially confusing. ![demonstration](https://user-images.githubusercontent.com/6609145/219976062-b46ab21b-5753-48f5-a1da-562566cae71c.gif)
2 parents 27239fb + dd92e4a commit f5401f6

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

crates/ide/src/doc_links.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,18 @@ pub(crate) fn remove_links(markdown: &str) -> String {
107107
out
108108
}
109109

110-
/// Retrieve a link to documentation for the given symbol.
110+
// Feature: Open Docs
111+
//
112+
// Retrieve a link to documentation for the given symbol.
113+
//
114+
// The simplest way to use this feature is via the context menu. Right-click on
115+
// the selected item. The context menu opens. Select **Open Docs**.
116+
//
117+
// |===
118+
// | Editor | Action Name
119+
//
120+
// | VS Code | **rust-analyzer: Open Docs**
121+
// |===
111122
pub(crate) fn external_docs(
112123
db: &RootDatabase,
113124
position: &FilePosition,

crates/ide/src/runnables.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,13 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
195195
//
196196
// Provides a sneak peek of all tests where the current item is used.
197197
//
198-
// The simplest way to use this feature is via the context menu:
199-
// - Right-click on the selected item. The context menu opens.
200-
// - Select **Peek related tests**
198+
// The simplest way to use this feature is via the context menu. Right-click on
199+
// the selected item. The context menu opens. Select **Peek Related Tests**.
201200
//
202201
// |===
203202
// | Editor | Action Name
204203
//
205-
// | VS Code | **rust-analyzer: Peek related tests**
204+
// | VS Code | **rust-analyzer: Peek Related Tests**
206205
// |===
207206
pub(crate) fn related_tests(
208207
db: &RootDatabase,

editors/code/package.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
},
227227
{
228228
"command": "rust-analyzer.openDocs",
229-
"title": "Open docs under cursor",
229+
"title": "Open Docs",
230230
"category": "rust-analyzer"
231231
},
232232
{
@@ -236,7 +236,7 @@
236236
},
237237
{
238238
"command": "rust-analyzer.peekTests",
239-
"title": "Peek related tests",
239+
"title": "Peek Related Tests",
240240
"category": "rust-analyzer"
241241
},
242242
{
@@ -1869,8 +1869,13 @@
18691869
"editor/context": [
18701870
{
18711871
"command": "rust-analyzer.peekTests",
1872-
"when": "inRustProject",
1872+
"when": "inRustProject && editorTextFocus && editorLangId == rust",
18731873
"group": "navigation@1000"
1874+
},
1875+
{
1876+
"command": "rust-analyzer.openDocs",
1877+
"when": "inRustProject && editorTextFocus && editorLangId == rust",
1878+
"group": "navigation@1001"
18741879
}
18751880
]
18761881
},

0 commit comments

Comments
 (0)