Skip to content

Commit

Permalink
Auto merge of rust-lang#14175 - jmviz:openDocs-context-menu, r=lnicola
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bors committed Feb 24, 2023
2 parents 27239fb + dd92e4a commit f5401f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 12 additions & 1 deletion crates/ide/src/doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,18 @@ pub(crate) fn remove_links(markdown: &str) -> String {
out
}

/// Retrieve a link to documentation for the given symbol.
// Feature: Open Docs
//
// Retrieve a link to documentation for the given symbol.
//
// The simplest way to use this feature is via the context menu. Right-click on
// the selected item. The context menu opens. Select **Open Docs**.
//
// |===
// | Editor | Action Name
//
// | VS Code | **rust-analyzer: Open Docs**
// |===
pub(crate) fn external_docs(
db: &RootDatabase,
position: &FilePosition,
Expand Down
7 changes: 3 additions & 4 deletions crates/ide/src/runnables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,13 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
//
// Provides a sneak peek of all tests where the current item is used.
//
// The simplest way to use this feature is via the context menu:
// - Right-click on the selected item. The context menu opens.
// - Select **Peek related tests**
// The simplest way to use this feature is via the context menu. Right-click on
// the selected item. The context menu opens. Select **Peek Related Tests**.
//
// |===
// | Editor | Action Name
//
// | VS Code | **rust-analyzer: Peek related tests**
// | VS Code | **rust-analyzer: Peek Related Tests**
// |===
pub(crate) fn related_tests(
db: &RootDatabase,
Expand Down
11 changes: 8 additions & 3 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
},
{
"command": "rust-analyzer.openDocs",
"title": "Open docs under cursor",
"title": "Open Docs",
"category": "rust-analyzer"
},
{
Expand All @@ -236,7 +236,7 @@
},
{
"command": "rust-analyzer.peekTests",
"title": "Peek related tests",
"title": "Peek Related Tests",
"category": "rust-analyzer"
},
{
Expand Down Expand Up @@ -1869,8 +1869,13 @@
"editor/context": [
{
"command": "rust-analyzer.peekTests",
"when": "inRustProject",
"when": "inRustProject && editorTextFocus && editorLangId == rust",
"group": "navigation@1000"
},
{
"command": "rust-analyzer.openDocs",
"when": "inRustProject && editorTextFocus && editorLangId == rust",
"group": "navigation@1001"
}
]
},
Expand Down

0 comments on commit f5401f6

Please sign in to comment.