Skip to content

Commit 9f18329

Browse files
authored
ensure workspace index is disabled for no auth, disable semantic search provider (#1155)
1 parent 3c09fa5 commit 9f18329

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

src/extension/conversation/vscode-node/conversationFeature.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ export class ConversationFeature implements IExtensionContribution {
162162
return;
163163
} else {
164164
this._searchProviderRegistered = true;
165+
166+
// Don't register for no auth user
167+
if (this.authenticationService.copilotToken?.isNoAuthUser) {
168+
this.logService.debug('ConversationFeature: Skipping search provider registration - no GitHub session available');
169+
return;
170+
}
171+
165172
return vscode.workspace.registerAITextSearchProvider('file', this.instantiationService.createInstance(SemanticSearchTextSearchProvider));
166173
}
167174
}

src/extension/prompts/node/panel/workspace/workspaceContext.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { IPromptPathRepresentationService } from '../../../../../platform/prompt
1313
import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry';
1414
import { getWorkspaceFileDisplayPath, IWorkspaceService } from '../../../../../platform/workspace/common/workspaceService';
1515
import { KeywordItem, ResolvedWorkspaceChunkQuery, WorkspaceChunkQuery } from '../../../../../platform/workspaceChunkSearch/common/workspaceChunkSearch';
16+
import { LocalEmbeddingsIndexStatus } from '../../../../../platform/workspaceChunkSearch/node/embeddingsChunkSearch';
1617
import { IWorkspaceChunkSearchService, WorkspaceChunkSearchResult } from '../../../../../platform/workspaceChunkSearch/node/workspaceChunkSearchService';
1718
import { GlobIncludeOptions } from '../../../../../util/common/glob';
1819
import { createFencedCodeBlock, getLanguageId } from '../../../../../util/common/markdown';
@@ -45,7 +46,7 @@ export const MAX_CHUNK_TOKEN_COUNT = 32_000;
4546
export const MAX_TOOL_CHUNK_TOKEN_COUNT = 20_000;
4647

4748
type WorkspaceChunksState = {
48-
readonly result: WorkspaceChunkSearchResult;
49+
readonly result?: WorkspaceChunkSearchResult;
4950
};
5051

5152
export interface ChunksToolProps extends BasePromptElementProps {
@@ -73,6 +74,11 @@ export class WorkspaceChunks extends PromptElement<ChunksToolProps, WorkspaceChu
7374
}
7475

7576
override async prepare(sizing: PromptSizing, progress: vscode.Progress<vscode.ChatResponsePart> | undefined, token = CancellationToken.None): Promise<WorkspaceChunksState> {
77+
const indexState = await this.workspaceChunkSearch.getIndexState();
78+
if (indexState.localIndexState.status === LocalEmbeddingsIndexStatus.Disabled && indexState.remoteIndexState.status === 'disabled') {
79+
return {};
80+
}
81+
7682
const searchResult = await logExecTime(this.logService, 'workspaceContext.perf.prepareWorkspaceChunks', () => {
7783
return raceCancellationError(
7884
this.workspaceChunkSearch.searchFileChunks({
@@ -115,6 +121,10 @@ export class WorkspaceChunks extends PromptElement<ChunksToolProps, WorkspaceChu
115121
}
116122

117123
override render(state: WorkspaceChunksState, sizing: PromptSizing): PromptPiece<any, any> | undefined {
124+
if (state.result === undefined) {
125+
return <TextChunk>The workspace index is not available at this time.</TextChunk>;
126+
}
127+
118128
return <WorkspaceChunkList
119129
result={state.result}
120130
referencesOut={this.props.referencesOut}

src/extension/workspaceChunkSearch/vscode-node/workspaceIndexingStatus.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ export class ChatStatusWorkspaceIndexingStatus extends Disposable {
272272
},
273273
};
274274

275+
case LocalEmbeddingsIndexStatus.Disabled:
276+
return undefined;
277+
275278
case LocalEmbeddingsIndexStatus.TooManyFilesForAnyIndexing:
276279
default:
277280
return {

src/platform/workspaceChunkSearch/node/embeddingsChunkSearch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { WorkspaceChunkEmbeddingsIndex, WorkspaceChunkEmbeddingsIndexState } fro
2828
import { IWorkspaceFileIndex } from './workspaceFileIndex';
2929

3030
export enum LocalEmbeddingsIndexStatus {
31+
Disabled = 'disabled',
3132
Unknown = 'unknown',
3233

3334
UpdatingIndex = 'updatingIndex',

src/platform/workspaceChunkSearch/node/workspaceChunkSearchService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { Disposable, IDisposable } from '../../../util/vs/base/common/lifecycle'
1919
import { StopWatch } from '../../../util/vs/base/common/stopwatch';
2020
import { IInstantiationService } from '../../../util/vs/platform/instantiation/common/instantiation';
2121
import { ChatResponseProgressPart2 } from '../../../vscodeTypes';
22+
import { IAuthenticationService } from '../../authentication/common/authentication';
2223
import { IAuthenticationChatUpgradeService } from '../../authentication/common/authenticationUpgrade';
2324
import { FileChunk, FileChunkAndScore } from '../../chunking/common/chunk';
2425
import { MAX_CHUNK_SIZE_TOKENS } from '../../chunking/node/naiveChunker';
@@ -118,6 +119,7 @@ export class WorkspaceChunkSearchService extends Disposable implements IWorkspac
118119

119120
constructor(
120121
@IInstantiationService private readonly _instantiationService: IInstantiationService,
122+
@IAuthenticationService private readonly _authenticationService: IAuthenticationService,
121123
@ILogService private readonly _logService: ILogService,
122124
) {
123125
super();
@@ -128,6 +130,10 @@ export class WorkspaceChunkSearchService extends Disposable implements IWorkspac
128130
}
129131

130132
private async tryInit(silent: boolean): Promise<WorkspaceChunkSearchServiceImpl | undefined> {
133+
if (!this._authenticationService.copilotToken || this._authenticationService.copilotToken.isNoAuthUser) {
134+
return undefined;
135+
}
136+
131137
if (this._impl) {
132138
return this._impl;
133139
}
@@ -161,7 +167,7 @@ export class WorkspaceChunkSearchService extends Disposable implements IWorkspac
161167
repos: [],
162168
},
163169
localIndexState: {
164-
status: LocalEmbeddingsIndexStatus.Unknown,
170+
status: !this._authenticationService.copilotToken || this._authenticationService.copilotToken.isNoAuthUser ? LocalEmbeddingsIndexStatus.Disabled : LocalEmbeddingsIndexStatus.Unknown,
165171
getState: async () => undefined,
166172
}
167173
};

0 commit comments

Comments
 (0)