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 exported types conflicting with agent protocol #5794

Merged
merged 4 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

data class AuthStatus(
import com.google.gson.annotations.SerializedName;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import java.lang.reflect.Type;

sealed class AuthStatus {
dominiccooney marked this conversation as resolved.
Show resolved Hide resolved
companion object {
val deserializer: JsonDeserializer<AuthStatus> =
JsonDeserializer { element: JsonElement, _: Type, context: JsonDeserializationContext ->
if (element.getAsJsonObject().get("username") == null) {
context.deserialize<UnauthenticatedAuthStatus>(element, UnauthenticatedAuthStatus::class.java)
} else {
context.deserialize<AuthenticatedAuthStatus>(element, AuthenticatedAuthStatus::class.java)
}
}
}
}

data class UnauthenticatedAuthStatus(
val endpoint: String,
val authenticated: Boolean,
val showNetworkError: Boolean? = null,
val showInvalidAccessTokenError: Boolean? = null,
val pendingValidation: Boolean,
) : AuthStatus() {
}

data class AuthenticatedAuthStatus(
val endpoint: String,
val authenticated: Boolean,
val username: String,
val isFireworksTracingEnabled: Boolean? = null,
val hasVerifiedEmail: Boolean? = null,
Expand All @@ -17,5 +44,7 @@ data class AuthStatus(
val displayName: String? = null,
val avatarURL: String? = null,
val userCanUpgrade: Boolean? = null,
)
val pendingValidation: Boolean,
) : AuthStatus() {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.sourcegraph.cody.agent.protocol_generated;

data class Range(
val start: Location,
val end: Location,
val start: Position,
val end: Position,
)

8 changes: 4 additions & 4 deletions lib/shared/src/sourcegraph-api/graphql/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ interface ContextSearchResponse {
}[]
}

interface Location {
interface Position {
line: number
column: number
character: number
}

export interface Range {
start: Location
end: Location
start: Position
end: Position
}

export interface ChatIntentResult {
Expand Down
2 changes: 1 addition & 1 deletion vscode/webviews/components/FileSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const FileSnippet: FC<FileSnippetProps> = props => {
chunkMatches: [
{
content: item.content ?? '',
contentStart: { line: Math.max(startLine - 1, 0), column: 0 },
contentStart: { line: Math.max(startLine - 1, 0), character: 0 },
ranges: item.ranges ?? [],
},
],
Expand Down
56 changes: 28 additions & 28 deletions vscode/webviews/components/codeSnippet/CodeSnippet.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ const meta: Meta<typeof FileContentSearchResult> = {
content: '\nclass SnippetBodyInsights {\n\n',
contentStart: {
line: 19,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 20,
column: 17,
character: 17,
},
end: {
line: 20,
column: 24,
character: 24,
},
},
],
Expand All @@ -38,27 +38,27 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\n\tprivate readonly _bodyInsights: WindowIdleValue<SnippetBodyInsights>;\n\n',
contentStart: {
line: 101,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 102,
column: 23,
character: 23,
},
end: {
line: 102,
column: 30,
character: 30,
},
},
{
start: {
line: 102,
column: 60,
character: 60,
},
end: {
line: 102,
column: 67,
character: 67,
},
},
],
Expand All @@ -68,27 +68,27 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\t\tthis.prefixLow = prefix.toLowerCase();\n\t\tthis._bodyInsights = new WindowIdleValue(getActiveWindow(), () => new SnippetBodyInsights(this.body));\n\t}\n',
contentStart: {
line: 118,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 119,
column: 12,
character: 12,
},
end: {
line: 119,
column: 19,
character: 19,
},
},
{
start: {
line: 119,
column: 83,
character: 83,
},
end: {
line: 119,
column: 90,
character: 90,
},
},
],
Expand All @@ -98,17 +98,17 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\tget codeSnippet(): string {\n\t\treturn this._bodyInsights.value.codeSnippet;\n\t}\n',
contentStart: {
line: 122,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 123,
column: 19,
character: 19,
},
end: {
line: 123,
column: 26,
character: 26,
},
},
],
Expand All @@ -118,17 +118,17 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\tget isBogous(): boolean {\n\t\treturn this._bodyInsights.value.isBogous;\n\t}\n',
contentStart: {
line: 126,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 127,
column: 19,
character: 19,
},
end: {
line: 127,
column: 26,
character: 26,
},
},
],
Expand All @@ -138,17 +138,17 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\tget isTrivial(): boolean {\n\t\treturn this._bodyInsights.value.isTrivial;\n\t}\n',
contentStart: {
line: 130,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 131,
column: 19,
character: 19,
},
end: {
line: 131,
column: 26,
character: 26,
},
},
],
Expand All @@ -158,17 +158,17 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\tget needsClipboard(): boolean {\n\t\treturn this._bodyInsights.value.usesClipboardVariable;\n\t}\n',
contentStart: {
line: 134,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 135,
column: 19,
character: 19,
},
end: {
line: 135,
column: 26,
character: 26,
},
},
],
Expand All @@ -178,17 +178,17 @@ const meta: Meta<typeof FileContentSearchResult> = {
'\tget usesSelection(): boolean {\n\t\treturn this._bodyInsights.value.usesSelectionVariable;\n\t}\n',
contentStart: {
line: 138,
column: 0,
character: 0,
},
ranges: [
{
start: {
line: 139,
column: 19,
character: 19,
},
end: {
line: 139,
column: 26,
character: 26,
},
},
],
Expand Down
4 changes: 2 additions & 2 deletions vscode/webviews/components/codeSnippet/CodeSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ function matchesToMatchGroups(result: ContentMatch): MatchGroup[] {
function chunkToMatchGroup(chunk: ChunkMatch): MatchGroup {
const matches = chunk.ranges.map(range => ({
startLine: range.start.line,
startCharacter: range.start.column,
startCharacter: range.start.character,
endLine: range.end.line,
endCharacter: range.end.column,
endCharacter: range.end.character,
}))
const plaintextLines = chunk.content.replace(/\r?\n$/, '').split(/\r?\n/)
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const RepoFileLink: React.FunctionComponent<React.PropsWithChildren<Props
for (const range of pathMatchRanges) {
highlightNode(
containerElement.current as HTMLElement,
range.start.column,
range.end.column - range.start.column
range.start.character,
range.end.character - range.start.character
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions vscode/webviews/components/codeSnippet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface LineMatch {

export interface ChunkMatch {
content: string
contentStart: Location
contentStart: Position
ranges: Range[]

/**
Expand All @@ -34,14 +34,14 @@ export interface ChunkMatch {
contentTruncated?: boolean
}

interface Location {
interface Position {
line: number
column: number
character: number
}

export interface Range {
start: Location
end: Location
start: Position
end: Position
}

/**
Expand Down
Loading