Skip to content

Commit

Permalink
Add commands shortcuts (#497)
Browse files Browse the repository at this point in the history
Docs updated. 
Subscription renamed to My Account.
Shortcuts added.
Mnemonics for commands added.

Fixes #408,
#412,
#415.


## Test plan

| Command | Windows / Linux | MacOs |

|---------------|------------------------------------------------------|------------------------------------------------------|
| Explain Code | <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>1</kbd> |
<kbd>control</kbd> + <kbd>Shift</kbd> + <kbd>E</kbd> |
| Smell Code | <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>2</kbd> |
<kbd>control</kbd> + <kbd>Shift</kbd> + <kbd>S</kbd> |
| Generate Test | <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>3</kbd> |
<kbd>control</kbd> + <kbd>Shift</kbd> + <kbd>T</kbd> |
  • Loading branch information
mkondratek authored Feb 6, 2024
1 parent 0ca9dbf commit 6679cd8
Show file tree
Hide file tree
Showing 23 changed files with 191 additions and 214 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Choose Edit Configurations and `+` to add a new one:

### Agent Run Config

Create this configuration in the `sourcegraph/cod`y project window.
Create this configuration in the `sourcegraph/cody` project window.
Choose Edit Configurations and `+` to add a new one:

- Type: Attach to Node.js/Chrome
Expand All @@ -239,7 +239,7 @@ Choose Edit Configurations and `+` to add a new one:
- Attach to: `Chrome or Node.js > 6.3 started with --inspect`
- Reconnect automatically: yes

## Cody connects to remote Agent
## Option 2: Cody connects to remote Agent

This option has two run configurations, different from two above. Note that
if you want both debugging options available, you can set up all four run
Expand Down Expand Up @@ -286,7 +286,7 @@ iteration. You can make code changes to the TypeScript and just hit
Debug or Run, and it will `pnpm build` your repo before spawning the agent.

Note that for Option 1 (Cody spawns Agent), the Before Task is added to the run
configuration on the java side. For IntelliJ spawning the AGent, the Before Task is
configuration on the java side. For IntelliJ spawning the Agent, the Before Task is
added to the run configuration on the TypeScript side.

### Setup
Expand Down
48 changes: 30 additions & 18 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
- [ ] [Infilling autocomplete](#infilling-autocomplete)
- [ ] [Cycle through autocomplete](#cycle-through-autocomplete)
- Commands
- [ ] [General commands availability in toolbar](#general-commands-availability-in-cody-toolbar)
- [ ] [General commands availability in Cody tool window](#general-commands-availability-in-cody-tool-window)
- [ ] [General commands availability in context menu](#general-commands-availability-in-context-menu)
- [ ] [Explain Selected Code](#explain-selected-code)
- [ ] [Generate Test](#generate-unit-test)
- [ ] [Explain Selected Code](#explain-code)
- [ ] [Generate Test](#generate-test)
- [ ] [Smell Code](#smell-code)
- Chat
- [ ] [Autoscroll to latest message](#autoscroll-to-latest-message)
Expand All @@ -25,7 +25,7 @@
- [ ] [Open Selection on Sourcegraph Web](#open-selection-on-sourcegraph-web)
- [ ] [Copy Sourcegraph File Link](#copy-sourcegraph-file-link)
- Product-led growth
- [ ] [Cody Free/Pro subscription tab](#cody-freepro-subscription-tab)
- [ ] [My Account Tab](#my-account-tab)
- [ ] [Cody Free/Pro rate limit errors](#cody-freepro-rate-limit-errors)
- Other
- [ ] [Automatic repository recognition](#automatic-repository-recognition)
Expand All @@ -38,7 +38,7 @@

Prerequisite: You have to **sign out** from all existing accounts.

1. Navigate to `Cody` toolbar and use `Sign in with GitHub`.
1. Navigate to `Cody` tool window and use `Sign in with GitHub`.
2. Browser is launched automatically and IDE freezes with spinning `Login to Sourcegraph` dialog.
3. Authorize with a valid account.

Expand All @@ -58,7 +58,7 @@ Prerequisite: You have to be **signed in**. This is important because we expect

#### Expected behaviour

* Cody toolbar is automatically refreshed and the user is greeted with the `Welcome to Cody` panel.
* `Cody` tool window is automatically refreshed and the user is greeted with the `Welcome to Cody` panel.
* Status bar widget has a `No account signed-in` status. Status bar is located in the bottom right corner of the IDE.

## Autocomplete
Expand Down Expand Up @@ -119,13 +119,25 @@ Prerequisite: You have to be **signed in**. This is important because we expect

## Commands

### General commands availability in Cody toolbar
### General commands availability in Cody tool window

1. Navigate to `Cody` toolbar and open `Commands`.
1. Navigate to `Cody` tool window and open `Commands`.

#### Expected behaviour

* List of commands is immediately available after the toolbar is displayed. **No refresh is required.**
* List of commands is immediately available after the tool window is displayed. **No refresh is required.**

### General commands availability from keyboard shortcuts

| Command | Windows / Linux | MacOs |
|---------------|------------------------------------------------------|------------------------------------------------------|
| Explain Code | <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>1</kbd> | <kbd>control</kbd> + <kbd>Shift</kbd> + <kbd>E</kbd> |
| Smell Code | <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>2</kbd> | <kbd>control</kbd> + <kbd>Shift</kbd> + <kbd>S</kbd> |
| Generate Test | <kbd>Alt</kbd> + <kbd>Shift</kbd> + <kbd>3</kbd> | <kbd>control</kbd> + <kbd>Shift</kbd> + <kbd>T</kbd> |

#### Expected behaviour

* Commands work as executed from any other place (the tool window opens if needed).

### General commands availability in context menu

Expand Down Expand Up @@ -239,7 +251,7 @@ Test ideas:
2. Restore historical chat, focus on chat input field and use UP/DOWN keys to cycle between previous questions.
3. Press "new chat" as fast as you can. Especially during the IDE startup.
4. Switch between chats as fast as you can.
5. Press "new chat" while being inside Subscription panel or something other than Chat tab. Tabs should switch automatically.
5. Press "new chat" while being inside `My Account` tab or something other than Chat tab. Tabs should switch automatically.
6. Use commands/recipes inside empty, new chat. Verify serialization/deserialization.
7. Ask about codebase to force response with listed context files and verify if everything is correctly serialized/deserialized. Links to context files should be clickable.
8. Remove all chats using history UI. Tree presentation is empty and branches like "Today" are removed from panel. File with transcripts should also disappear.
Expand Down Expand Up @@ -294,23 +306,23 @@ To open the context menu:

## [Product-led growth](https://handbook.sourcegraph.com/departments/data-analytics/product-led-growth/)

### Cody Free/Pro subscription tab
### My Account Tab

1. Log in to Sourcegraph.com with a **Free** account and `cody-pro-jetbrains` feature flag enabled.
2. Go to the `Cody` toolbar and open `Subscription` tab.
2. Go to `Cody` tool window and open `My Account` tab.
3. Verify:
* The current tier should be `Cody Free`.
* The `Upgrade` button is visible and it points to `https://sourcegraph.com/cody/subscription`.
* The `Check Usage` button is visible and it points to `https://sourcegraph.com/cody/manage`.
4. Go to accounts settings and switch to **Pro** account.
5. Go to `Subscription` tab.
5. Go to `My Account` tab.
6. Verify:
* The current tier should be `Cody Pro`.
* The `Upgrade` is **not visible**.
7. Go to account settings and switch to an Enterprise account (AKA *non-dotcom*).
8. Verify: `Subscription` panel is not visible in `Cody` toolbar.
8. Verify: `My Account` tab is not visible in `Cody` tool window.
9. Go to accounts settings and switch back to the **Free** account.
10. Verify: `Subscription` panel is visible.
10. Verify: `My Account` tab is visible.

### Cody Free/Pro rate limit errors

Expand All @@ -325,8 +337,8 @@ To open the context menu:
### Automatic repository recognition

1. Open project with enabled Git VCS. This repository must be publicly available on GitHub.
2. Open to `Cody` toolbar.
3. Click on repository button to open `Context Selection` dialog. Button is placed inside `Cody` toolbar on left, bottom
2. Open to `Cody` tool window.
3. Click on repository button to open `Context Selection` dialog. Button is placed inside `Cody` tool window on left, bottom
corner.

#### Expected behaviour
Expand All @@ -337,7 +349,7 @@ To open the context menu:
### Persistent custom repository

1. Open project with enabled Git VCS. This repository must be publicly available on GitHub.
2. Open to `Cody` toolbar.
2. Open to `Cody` tool window.
3. Click on repository button to open `Context Selection` dialog.
4. Change `Git URL` to a different, valid Git URL repository.
5. Click `OK` button and restart IDE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.awt.BorderLayout
import javax.swing.JPanel
import javax.swing.border.EmptyBorder

class SubscriptionTabPanel : JPanel() {
class MyAccountTabPanel : JPanel() {

private var isCurrentUserPro: Boolean? = null
private var chatLimitError = UpgradeToCodyProNotification.chatRateLimitError.get()
Expand All @@ -41,12 +41,12 @@ class SubscriptionTabPanel : JPanel() {
"<td width=\"10%\"><span style=\"font-size:20px;\">⚡</span></td>" +
"<td width=\"90%\"><p>${
if (autocompleteLimitError != null && chatLimitError != null) {
CodyBundle.getString("subscription-tab.chat-and-autocomplete-rate-limit-error")
CodyBundle.getString("my-account-tab.chat-and-autocomplete-rate-limit-error")
} else {
if (chatLimitError != null) {
CodyBundle.getString("subscription-tab.chat-rate-limit-error")
CodyBundle.getString("my-account-tab.chat-rate-limit-error")
} else {
CodyBundle.getString("subscription-tab.autocomplete-rate-limit-error")
CodyBundle.getString("my-account-tab.autocomplete-rate-limit-error")
}
}
}</p></td>" +
Expand All @@ -66,9 +66,9 @@ class SubscriptionTabPanel : JPanel() {
private fun createCenterPanel() = panel {
val getIsCurrentUserPro = isCurrentUserPro
val tier =
if (getIsCurrentUserPro == null) CodyBundle.getString("subscription-tab.loading-label")
else if (getIsCurrentUserPro) CodyBundle.getString("subscription-tab.cody-pro-label")
else CodyBundle.getString("subscription-tab.cody-free-label")
if (getIsCurrentUserPro == null) CodyBundle.getString("my-account-tab.loading-label")
else if (getIsCurrentUserPro) CodyBundle.getString("my-account-tab.cody-pro-label")
else CodyBundle.getString("my-account-tab.cody-free-label")
row { label("<html>Current tier: <b>$tier</b><html/>") }
row {
if (getIsCurrentUserPro != null && !getIsCurrentUserPro) {
Expand All @@ -79,7 +79,7 @@ class SubscriptionTabPanel : JPanel() {
button("Check Usage") { BrowserUtil.browse(ConfigUtil.DOTCOM_URL + "cody/manage") }
}
if (getIsCurrentUserPro != null && !getIsCurrentUserPro) {
row { text(CodyBundle.getString("tab.subscription.already-pro")) }
row { text(CodyBundle.getString("my-account-tab.already-pro")) }
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/sourcegraph/cody/SubscriptionTabUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import com.sourcegraph.cody.config.CodyAuthenticationManager
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit

data class SubscriptionTabPanelData(
data class MyAccountTabPanelData(
val isDotcomAccount: Boolean,
val codyProFeatureFlag: Boolean,
val isCurrentUserPro: Boolean?
)

@RequiresBackgroundThread
fun fetchSubscriptionPanelData(
fun fetchMyAccountPanelData(
project: Project,
server: CodyAgentServer
): CompletableFuture<SubscriptionTabPanelData?> {
): CompletableFuture<MyAccountTabPanelData?> {
val activeAccountType = CodyAuthenticationManager.instance.getActiveAccount(project)
val result = CompletableFuture<SubscriptionTabPanelData?>()
val result = CompletableFuture<MyAccountTabPanelData?>()

if (activeAccountType != null) {
ensureUserIdMatchInAgent(activeAccountType.id, server)
Expand All @@ -36,21 +36,21 @@ fun fetchSubscriptionPanelData(
if (codyProFeatureFlag) {
val isCurrentUserPro = getIsCurrentUserPro(server) ?: false
result.complete(
SubscriptionTabPanelData(
MyAccountTabPanelData(
activeAccountType.isDotcomAccount(),
codyProFeatureFlag = true,
isCurrentUserPro = isCurrentUserPro))
} else {
result.complete(
SubscriptionTabPanelData(
MyAccountTabPanelData(
activeAccountType.isDotcomAccount(),
codyProFeatureFlag = false,
isCurrentUserPro = null))
}
}
} else {
result.complete(
SubscriptionTabPanelData(
MyAccountTabPanelData(
activeAccountType.isDotcomAccount(),
codyProFeatureFlag = false,
isCurrentUserPro = false))
Expand Down
66 changes: 0 additions & 66 deletions src/main/java/com/sourcegraph/cody/prompts/Preamble.java

This file was deleted.

27 changes: 12 additions & 15 deletions src/main/kotlin/com/sourcegraph/cody/CodyToolWindowContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import com.intellij.openapi.project.Project
import com.intellij.ui.components.JBTabbedPane
import com.intellij.util.concurrency.annotations.RequiresEdt
import com.jetbrains.rd.util.AtomicReference
import com.sourcegraph.cody.agent.*
import com.sourcegraph.cody.agent.CodyAgentService
import com.sourcegraph.cody.chat.*
import com.sourcegraph.cody.chat.AgentChatSession
import com.sourcegraph.cody.chat.AgentChatSessionService
import com.sourcegraph.cody.chat.SignInWithSourcegraphPanel
Expand Down Expand Up @@ -50,20 +48,20 @@ class CodyToolWindowContent(private val project: Project) {
switchToChatSession(AgentChatSession.createFromCommand(project, commandId))
}

private val subscriptionPanel = SubscriptionTabPanel()
private val myAccountPanel = MyAccountTabPanel()

init {
tabbedPane.insertSimpleTab("Chat", chatContainerPanel, CHAT_TAB_INDEX)
tabbedPane.insertSimpleTab("Chat History", historyTree, HISTORY_TAB_INDEX)
tabbedPane.insertSimpleTab("Commands", commandsPanel, COMMANDS_TAB_INDEX)
tabbedPane.insertSimpleTab("Subscription", subscriptionPanel, SUBSCRIPTION_TAB_INDEX)
tabbedPane.insertSimpleTab("My Account", myAccountPanel, MY_ACCOUNT_TAB_INDEX)

allContentPanel.add(tabbedPane, MAIN_PANEL, CHAT_PANEL_INDEX)
allContentPanel.add(signInWithSourcegraphPanel, SIGN_IN_PANEL, SIGN_IN_PANEL_INDEX)
allContentLayout.show(allContentPanel, SIGN_IN_PANEL)

refreshPanelsVisibility()
refreshSubscriptionTab()
refreshMyAccountTab()
switchToChatSession(AgentChatSession.createNew(project))
}

Expand All @@ -81,20 +79,19 @@ class CodyToolWindowContent(private val project: Project) {
}
}

fun refreshSubscriptionTab() {
fun refreshMyAccountTab() {
CodyAgentService.applyAgentOnBackgroundThread(project) { agent ->
fetchSubscriptionPanelData(project, agent.server).thenApply { data ->
fetchMyAccountPanelData(project, agent.server).thenApply { data ->
if (data != null) {
ApplicationManager.getApplication().invokeLater {
val isSubscriptionTabPresent = tabbedPane.tabCount > SUBSCRIPTION_TAB_INDEX
val isMyAccountTabVisible = tabbedPane.tabCount > MY_ACCOUNT_TAB_INDEX
if (data.isDotcomAccount && data.codyProFeatureFlag) {
if (!isSubscriptionTabPresent) {
tabbedPane.insertSimpleTab(
"Subscription", subscriptionPanel, SUBSCRIPTION_TAB_INDEX)
if (!isMyAccountTabVisible) {
tabbedPane.insertSimpleTab("My Account", myAccountPanel, MY_ACCOUNT_TAB_INDEX)
}
subscriptionPanel.update(data.isCurrentUserPro)
} else if (isSubscriptionTabPresent) {
tabbedPane.remove(SUBSCRIPTION_TAB_INDEX)
myAccountPanel.update(data.isCurrentUserPro)
} else if (isMyAccountTabVisible) {
tabbedPane.remove(MY_ACCOUNT_TAB_INDEX)
}
}
}
Expand Down Expand Up @@ -167,7 +164,7 @@ class CodyToolWindowContent(private val project: Project) {
private const val CHAT_TAB_INDEX = 0
private const val HISTORY_TAB_INDEX = 1
private const val COMMANDS_TAB_INDEX = 2
private const val SUBSCRIPTION_TAB_INDEX = 3
private const val MY_ACCOUNT_TAB_INDEX = 3

var logger = Logger.getInstance(CodyToolWindowContent::class.java)

Expand Down
Loading

0 comments on commit 6679cd8

Please sign in to comment.