Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing current repo context in jetbrains #6649

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

pkukielka
Copy link
Contributor

Fixes https://linear.app/sourcegraph/issue/CODY-3906/agent-allow-use-of-existing-fallback-that-looks-at-gitconfig-to-get
Fixes https://linear.app/sourcegraph/issue/CODY-4140/jetbrains-cody-current-repo-no-longer-available-as-context

I think that was a simple mistake introduced by https://linear.app/sourcegraph/issue/CODY-3906/agent-allow-use-of-existing-fallback-that-looks-at-gitconfig-to-get

If I remove code you can see in the diff it simply works.
All git based methods themselves check if they can be executed so this safeguard was not adding any value there from what I can see.

Test plan

  1. Open jetbrains with cody repo and login to sg02
  2. Current Repository should be visible in the chat context by default
  3. Remove Current Repository
  4. Type @ and then Start typing Current Repository - suggestion to add should appear and you should be able to accept it

Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be useful to know exactly why this works now, I'm assuming it didn't work at the time, unless this was just a mistake we missed.

Have we verified that the context is correctly included in the chat message too?

@pkukielka
Copy link
Contributor Author

It'd be useful to know exactly why this works now, I'm assuming it didn't work at the time, unless this was just a mistake we missed.

Have we verified that the context is correctly included in the chat message too?

I verified it works now.

I took some time to read sqs PR so I can tell you exactly what happened:

Look at vscode/src/chat/initialContext.ts:201
Previously if workspaceReposMonitor was not defined we were falling into else branch.
In the new code version remoteReposForAllWorkspaceFolders returns empty list, but we are still entering first if branch, and thus we have no chance to recover.

That said I think entering that first branch is right, we have remote repos.
We just should not return early in remoteReposForAllWorkspaceFolders. We obtain git repo name/url not obly using VSC git extension, we also use methods like this:

/**
 * Walks the tree from the current directory to find the `.git` folder and
 * extracts remote URLs.
 */
async function gitRemoteUrlsFromParentDirs

So giving up just because VSC git extension is not initialised is in fact incorrect.

Copy link
Contributor

@umpox umpox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into it! Makes sense from my perspective 👍

@pkukielka pkukielka force-pushed the pkukielka/fix-missing-context-repo branch from 5bdaa0d to 3a4f2a3 Compare January 15, 2025 15:12
@pkukielka
Copy link
Contributor Author

I added one small improvement:
3a4f2a3
This way if we will fail to find remote repo, we will at least add local one (which was previously always happening in JetBrains because we were, incorrectly, skipping looking for the remote)

@umpox
Copy link
Contributor

umpox commented Jan 15, 2025

@pkukielka LGTM!

@pkukielka pkukielka enabled auto-merge (squash) January 15, 2025 15:29
@pkukielka pkukielka force-pushed the pkukielka/fix-missing-context-repo branch from a55c6ec to e2114b7 Compare January 16, 2025 14:16
@pkukielka pkukielka merged commit 959f67b into main Jan 16, 2025
21 checks passed
@pkukielka pkukielka deleted the pkukielka/fix-missing-context-repo branch January 16, 2025 14:22
@dominiccooney
Copy link
Contributor

I added one small improvement:
3a4f2a3
This way if we will fail to find remote repo, we will at least add local one (which was previously always happening in JetBrains because we were, incorrectly, skipping looking for the remote)

@pkukielka , @umpox I don't think this is right.

For enterprise with remote search, my understanding is that there is no local tree context. Let's use this Slack thread to clarify: https://sourcegraph.slack.com/archives/C05AGQYD528/p1736959465468939?thread_ts=1736948828.528379&cid=C05AGQYD528

dominiccooney added a commit that referenced this pull request Jan 22, 2025
…n non-dotcom (#6695)

When remote search is enabled (that is, Enterprise, etc.) and the
current repo is not indexed remotely:

- Do *not* add a phony "current repo" context item to default context.
- *Do* show an indication that the current repo is not available as
context, and link to a helpful resource. (Part of CODY-4676.)

#6649 make a change to show a "current repo" context item when remote
search is available, but the current repo is not indexed remotely. That
is not right. We want current repo context to be backed by remote search
(although even with remote search there is a local layer on top with
`git status`, we do not support 100% local context ala symf when remote
search is enabled.)

## Test plan

1. Sign in to a dotcom account. Verify that default context, @-mentions
show "Current Repository" and fetch context from it, etc. This behavior
has not changed in this PR and must still work.
2. Sign in to an Enterprise account and open a workspace that *is*
indexed remotely. There should be a "Current Repository" context item by
default; the @-mentions menu should contain "Current Context
github.com/foo", etc. This behavior also has not changed in this PR and
must still work.
3. While still signed in to Enterprise, open a workspace that is *not*
indexed remotely. There should not be a "Current Repository" context
item by default. There should be a new "Current Repository/Not yet
available" menu item, and activating that menu item should open a
browser.
4. Run `pnpm -C web dev` and verify that Cody Web still works as in step
2 above.

![Screenshot 2025-01-20 at 13 17
22](https://github.com/user-attachments/assets/aed6d36b-3fc5-4584-bbc6-373db146af36)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants