instruction
stringclasses
1 value
input
stringlengths
67
168
output
stringlengths
46
67k
You are a code assistant
Definition of 'updateFile' in file src/common/advanced_context/lru_cache.ts in project gitlab-lsp
Definition: updateFile(context: IDocContext) { return this.#cache.set(context.uri, context); } /** * @returns `true` if the file was deleted, `false` if the file was not found */ deleteFile(uri: DocumentUri): boolean { return this.#cache.delete(uri); } /** * Get the most recently accessed files in the workspace * @param context - The current document context `IDocContext` * @param includeCurrentFile - Include the current file in the list of most recent files, default is `true` */ mostRecentFiles({ context, includeCurrentFile = true, }: { context?: IDocContext; includeCurrentFile?: boolean; }): IDocContext[] { const files = Array.from(this.#cache.values()); if (includeCurrentFile) { return files; } return files.filter( (file) => context?.workspaceFolder?.uri === file.workspaceFolder?.uri && file.uri !== context?.uri, ); } } References:
You are a code assistant
Definition of 'RepositoryTrie' in file src/common/git/repository_trie.ts in project gitlab-lsp
Definition: export class RepositoryTrie { children: Map<string, RepositoryTrie>; repository: URI | null; constructor() { this.children = new Map(); this.repository = null; } dispose(): void { this.children.forEach((child) => child.dispose()); this.children.clear(); this.repository = null; } } References: - src/common/git/repository_service.ts:124 - src/common/git/repository_service.ts:123 - src/common/git/repository_service.ts:176 - src/common/git/repository_service.ts:130
You are a code assistant
Definition of 'greet2' in file src/tests/fixtures/intent/empty_function/python.py in project gitlab-lsp
Definition: def greet2(name): print(name) class Greet: def __init__(self, name): pass def greet(self): pass class Greet2: def __init__(self, name): self.name = name def greet(self): print(f"Hello {self.name}") class Greet3: pass def greet3(name): ... class Greet4: def __init__(self, name): ... def greet(self): ... class Greet3: ... def greet3(name): class Greet4: def __init__(self, name): def greet(self): class Greet3: References: - src/tests/fixtures/intent/empty_function/ruby.rb:4
You are a code assistant
Definition of 'DuoProject' in file src/common/services/duo_access/project_access_cache.ts in project gitlab-lsp
Definition: export type DuoProject = GitLabRemote & { /** * This is the pointer on the file system to the project. * eg. file:///User/username/gitlab-development-kit/gitlab/.git/config * This should match the `DocumentUri` of the document to check. * * @reference `DocumentUri` is the URI of the document to check. Comes from * the `TextDocument` object. */ uri: string; /** * enabled: true if the project has Duo features enabled */ enabled: boolean; }; type WorkspaceFolderUri = string; const duoFeaturesEnabledQuery = gql` query GetProject($projectPath: ID!) { project(fullPath: $projectPath) { duoFeaturesEnabled } } `; interface GitConfig { [section: string]: { [key: string]: string }; } type GitlabRemoteAndFileUri = GitLabRemote & { fileUri: string }; export interface GqlProjectWithDuoEnabledInfo { duoFeaturesEnabled: boolean; } export interface DuoProjectAccessCache { getProjectsForWorkspaceFolder(workspaceFolder: WorkspaceFolder): DuoProject[]; updateCache({ baseUrl, workspaceFolders, }: { baseUrl: string; workspaceFolders: WorkspaceFolder[]; }): Promise<void>; onDuoProjectCacheUpdate(listener: () => void): Disposable; } export const DuoProjectAccessCache = createInterfaceId<DuoProjectAccessCache>('DuoProjectAccessCache'); @Injectable(DuoProjectAccessCache, [DirectoryWalker, FileResolver, GitLabApiClient]) export class DefaultDuoProjectAccessCache { #duoProjects: Map<WorkspaceFolderUri, DuoProject[]>; #eventEmitter = new EventEmitter(); constructor( private readonly directoryWalker: DirectoryWalker, private readonly fileResolver: FileResolver, private readonly api: GitLabApiClient, ) { this.#duoProjects = new Map<WorkspaceFolderUri, DuoProject[]>(); } getProjectsForWorkspaceFolder(workspaceFolder: WorkspaceFolder): DuoProject[] { return this.#duoProjects.get(workspaceFolder.uri) ?? []; } async updateCache({ baseUrl, workspaceFolders, }: { baseUrl: string; workspaceFolders: WorkspaceFolder[]; }) { try { this.#duoProjects.clear(); const duoProjects = await Promise.all( workspaceFolders.map(async (workspaceFolder) => { return { workspaceFolder, projects: await this.#duoProjectsForWorkspaceFolder({ workspaceFolder, baseUrl, }), }; }), ); for (const { workspaceFolder, projects } of duoProjects) { this.#logProjectsInfo(projects, workspaceFolder); this.#duoProjects.set(workspaceFolder.uri, projects); } this.#triggerChange(); } catch (err) { log.error('DuoProjectAccessCache: failed to update project access cache', err); } } #logProjectsInfo(projects: DuoProject[], workspaceFolder: WorkspaceFolder) { if (!projects.length) { log.warn( `DuoProjectAccessCache: no projects found for workspace folder ${workspaceFolder.uri}`, ); return; } log.debug( `DuoProjectAccessCache: found ${projects.length} projects for workspace folder ${workspaceFolder.uri}: ${JSON.stringify(projects, null, 2)}`, ); } async #duoProjectsForWorkspaceFolder({ workspaceFolder, baseUrl, }: { workspaceFolder: WorkspaceFolder; baseUrl: string; }): Promise<DuoProject[]> { const remotes = await this.#gitlabRemotesForWorkspaceFolder(workspaceFolder, baseUrl); const projects = await Promise.all( remotes.map(async (remote) => { const enabled = await this.#checkDuoFeaturesEnabled(remote.namespaceWithPath); return { projectPath: remote.projectPath, uri: remote.fileUri, enabled, host: remote.host, namespace: remote.namespace, namespaceWithPath: remote.namespaceWithPath, } satisfies DuoProject; }), ); return projects; } async #gitlabRemotesForWorkspaceFolder( workspaceFolder: WorkspaceFolder, baseUrl: string, ): Promise<GitlabRemoteAndFileUri[]> { const paths = await this.directoryWalker.findFilesForDirectory({ directoryUri: workspaceFolder.uri, filters: { fileEndsWith: ['/.git/config'], }, }); const remotes = await Promise.all( paths.map(async (fileUri) => this.#gitlabRemotesForFileUri(fileUri.toString(), baseUrl)), ); return remotes.flat(); } async #gitlabRemotesForFileUri( fileUri: string, baseUrl: string, ): Promise<GitlabRemoteAndFileUri[]> { const remoteUrls = await this.#remoteUrlsFromGitConfig(fileUri); return remoteUrls.reduce<GitlabRemoteAndFileUri[]>((acc, remoteUrl) => { const remote = parseGitLabRemote(remoteUrl, baseUrl); if (remote) { acc.push({ ...remote, fileUri }); } return acc; }, []); } async #remoteUrlsFromGitConfig(fileUri: string): Promise<string[]> { try { const fileString = await this.fileResolver.readFile({ fileUri }); const config = ini.parse(fileString); return this.#getRemoteUrls(config); } catch (error) { log.error(`DuoProjectAccessCache: Failed to read git config file: ${fileUri}`, error); return []; } } #getRemoteUrls(config: GitConfig): string[] { return Object.keys(config).reduce<string[]>((acc, section) => { if (section.startsWith('remote ')) { acc.push(config[section].url); } return acc; }, []); } async #checkDuoFeaturesEnabled(projectPath: string): Promise<boolean> { try { const response = await this.api.fetchFromApi<{ project: GqlProjectWithDuoEnabledInfo }>({ type: 'graphql', query: duoFeaturesEnabledQuery, variables: { projectPath, }, } satisfies ApiRequest<{ project: GqlProjectWithDuoEnabledInfo }>); return Boolean(response?.project?.duoFeaturesEnabled); } catch (error) { log.error( `DuoProjectAccessCache: Failed to check if Duo features are enabled for project: ${projectPath}`, error, ); return true; } } onDuoProjectCacheUpdate( listener: (duoProjectsCache: Map<WorkspaceFolderUri, DuoProject[]>) => void, ): Disposable { this.#eventEmitter.on(DUO_PROJECT_CACHE_UPDATE_EVENT, listener); return { dispose: () => this.#eventEmitter.removeListener(DUO_PROJECT_CACHE_UPDATE_EVENT, listener), }; } #triggerChange() { this.#eventEmitter.emit(DUO_PROJECT_CACHE_UPDATE_EVENT, this.#duoProjects); } } References:
You are a code assistant
Definition of 'subscribe' in file packages/lib_webview/src/events/utils/subscribe.ts in project gitlab-lsp
Definition: export function subscribe<TEvents extends EventMap, TEventName extends keyof TEvents>( eventEmitter: TypedEventEmitter<TEvents>, eventName: TEventName, handler: TEvents[TEventName], ): Disposable { eventEmitter.on(eventName, handler); return { dispose: () => { eventEmitter.off(eventName, handler); }, }; } References:
You are a code assistant
Definition of 'AiCompletionResponseChannel' in file packages/webview_duo_chat/src/plugin/port/api/graphql/ai_completion_response_channel.ts in project gitlab-lsp
Definition: export class AiCompletionResponseChannel extends Channel< AiCompletionResponseParams, AiCompletionResponseResponseType, AiCompletionResponseChannelEvents > { static identifier = 'GraphqlChannel'; constructor(params: AiCompletionResponseInput) { super({ channel: 'GraphqlChannel', operationName: 'aiCompletionResponse', query: AI_MESSAGE_SUBSCRIPTION_QUERY, variables: JSON.stringify(params), }); } receive(message: AiCompletionResponseResponseType) { if (!message.result.data.aiCompletionResponse) return; const data = message.result.data.aiCompletionResponse; if (data.role.toLowerCase() === 'system') { this.emit('systemMessage', data); } else if (data.chunkId) { this.emit('newChunk', data); } else { this.emit('fullMessage', data); } } } References: - packages/webview_duo_chat/src/plugin/port/api/graphql/ai_completion_response_channel.test.ts:4 - packages/webview_duo_chat/src/plugin/port/api/graphql/ai_completion_response_channel.test.ts:16 - packages/webview_duo_chat/src/plugin/port/chat/gitlab_chat_api.ts:205
You are a code assistant
Definition of '__init__' in file src/tests/fixtures/intent/empty_function/python.py in project gitlab-lsp
Definition: def __init__(self, name): self.name = name def greet(self): print(f"Hello {self.name}") class Greet3: pass def greet3(name): ... class Greet4: def __init__(self, name): ... def greet(self): ... class Greet3: ... def greet3(name): class Greet4: def __init__(self, name): def greet(self): class Greet3: References: