-
Notifications
You must be signed in to change notification settings - Fork 335
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
Autocomplete: add git metadata to autocomplete requests #5955
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import dedent from 'dedent' | ||
import { Observable } from 'observable-fns' | ||
import { vi } from 'vitest' | ||
import type { URI } from 'vscode-uri' | ||
import { URI } from 'vscode-uri' | ||
|
||
import { | ||
AUTH_STATUS_FIXTURE_AUTHED, | ||
|
@@ -28,7 +28,7 @@ import type { | |
CodeCompletionsParams, | ||
CompletionResponseWithMetaData, | ||
} from '@sourcegraph/cody-shared/src/inferenceClient/misc' | ||
|
||
import { repoNameResolver } from '../../repository/repo-name-resolver' | ||
import { DEFAULT_VSCODE_SETTINGS } from '../../testutils/mocks' | ||
import type { SupportedLanguage } from '../../tree-sitter/grammars' | ||
import { updateParseTreeCache } from '../../tree-sitter/parse-tree-cache' | ||
|
@@ -411,6 +411,14 @@ export function initCompletionProviderConfig({ | |
authStatus, | ||
}: Partial<Pick<ParamsResult, 'configuration' | 'authStatus'>>): void { | ||
setEditorWindowIsFocused(() => true) | ||
|
||
vi.spyOn(repoNameResolver, 'getRepoInfoContainingUri').mockReturnValue( | ||
Observable.of({ | ||
rootUri: URI.file('/repoName'), | ||
repoNames: ['sourcegraph/repoName'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing that these repo names will be using sourcegraph formatting like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we use Sourcegraph API to resolve repo names based on remote URLs. |
||
}) | ||
) | ||
|
||
vi.spyOn(featureFlagProvider, 'evaluateFeatureFlagEphemerally').mockResolvedValue(false) | ||
vi.spyOn(featureFlagProvider, 'evaluatedFeatureFlag').mockReturnValue(Observable.of(false)) | ||
vi.spyOn(ClientConfigSingleton.getInstance(), 'getConfig').mockResolvedValue({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,15 @@ import * as vscode from 'vscode' | |
import { URI } from 'vscode-uri' | ||
|
||
import { vscodeGitAPI } from './git-extension-api' | ||
import { gitRemoteUrlsForUri } from './remote-urls-from-parent-dirs' | ||
import { gitRemoteUrlsInfoForUri } from './remote-urls-from-parent-dirs' | ||
import { mockFsCalls } from './test-helpers' | ||
|
||
describe('gitRemoteUrlsForUri', () => { | ||
async function gitRemoteUrlsForUri(uri: vscode.Uri): Promise<string[] | undefined> { | ||
const repoInfo = await gitRemoteUrlsInfoForUri(uri) | ||
return repoInfo?.remoteUrls | ||
} | ||
|
||
describe('gitRemoteUrlsInfoForUri', () => { | ||
beforeAll(() => { | ||
// Ensure that the `vscodeGitAPI` is not somehow set, because these tests were written to | ||
// test the behavior that is the fallback for when it is not set. | ||
|
@@ -75,9 +80,9 @@ describe('gitRemoteUrlsForUri', () => { | |
|
||
const remoteUrls = await gitRemoteUrlsForUri(fileUri) | ||
expect(remoteUrls).toEqual([ | ||
'https://github.com/username/yourproject.git', | ||
'https://github.com/originalauthor/yourproject.git', | ||
'git@backupserver:repositories/yourproject.git', | ||
'https://github.com/originalauthor/yourproject.git', | ||
'https://github.com/username/yourproject.git', | ||
]) | ||
}) | ||
|
||
|
@@ -109,7 +114,7 @@ describe('gitRemoteUrlsForUri', () => { | |
.mockRejectedValue(new vscode.FileSystemError('file does not exist')) | ||
|
||
const uri = URI.file('repo/src/dir/foo.ts') | ||
const remoteUrls = await gitRemoteUrlsForUri(uri) | ||
const remoteUrls = await gitRemoteUrlsInfoForUri(uri) | ||
|
||
expect(statMock).toBeCalledTimes(5) | ||
expect(remoteUrls).toBe(undefined) | ||
|
@@ -209,10 +214,12 @@ describe('gitRemoteUrlsForUri', () => { | |
gitConfig: 'a', | ||
}) | ||
|
||
expect(await gitRemoteUrlsForUri(URI.parse('https://example.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://gitlab.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://github.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('ssh://[email protected]:foo/bar.git'))).toBe(undefined) | ||
expect(await gitRemoteUrlsInfoForUri(URI.parse('https://example.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsInfoForUri(URI.parse('https://gitlab.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsInfoForUri(URI.parse('https://github.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsInfoForUri(URI.parse('ssh://[email protected]:foo/bar.git'))).toBe( | ||
undefined | ||
) | ||
expect(statMock).toBeCalledTimes(0) | ||
expect(readFileMock).toBeCalledTimes(0) | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { | |
mockResolvedConfig, | ||
} from '@sourcegraph/cody-shared' | ||
|
||
import { URI } from 'vscode-uri' | ||
import * as remoteUrlsFromParentDirs from './remote-urls-from-parent-dirs' | ||
import { RepoNameResolver } from './repo-name-resolver' | ||
import { mockFsCalls } from './test-helpers' | ||
|
@@ -24,9 +25,10 @@ describe('getRepoNamesContainingUri', () => { | |
mockResolvedConfig({ auth: {} }) | ||
mockClientCapabilities(CLIENT_CAPABILITIES_FIXTURE) | ||
|
||
vi.spyOn(remoteUrlsFromParentDirs, 'gitRemoteUrlsForUri').mockResolvedValue([ | ||
'[email protected]:sourcegraph/cody.git', | ||
]) | ||
vi.spyOn(remoteUrlsFromParentDirs, 'gitRemoteUrlsInfoForUri').mockResolvedValue({ | ||
rootUri: URI.file('/repo'), | ||
remoteUrls: ['[email protected]:sourcegraph/cody.git'], | ||
}) | ||
|
||
const { fileUri } = mockFsCalls({ | ||
filePath: '/repo/submodule/foo.ts', | ||
|
@@ -55,9 +57,10 @@ describe('getRepoNamesContainingUri', () => { | |
const repoNameResolver = new RepoNameResolver() | ||
mockAuthStatus(AUTH_STATUS_FIXTURE_AUTHED_DOTCOM) | ||
|
||
vi.spyOn(remoteUrlsFromParentDirs, 'gitRemoteUrlsForUri').mockResolvedValue([ | ||
'[email protected]:sourcegraph/cody.git', | ||
]) | ||
vi.spyOn(remoteUrlsFromParentDirs, 'gitRemoteUrlsInfoForUri').mockResolvedValue({ | ||
rootUri: URI.file('/repo'), | ||
remoteUrls: ['[email protected]:sourcegraph/cody.git'], | ||
}) | ||
|
||
const { fileUri } = mockFsCalls({ | ||
filePath: '/repo/submodule/foo.ts', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this an array? I can imagine we'll support multi-file edits at one point, and the request will be associated to multiple files.