Skip to content

Commit

Permalink
Use FileSystemProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
thenamankumar committed Jan 8, 2025
1 parent d3517b4 commit 04541ae
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
4 changes: 2 additions & 2 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,11 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
private async openRemoteFile(uri: vscode.Uri) {
const json = uri.toJSON()
json.scheme = 'codysourcegraph'
const sourcegraphSchemaURI = vscode.Uri.from(json)
const sourcegraphSchemaURI = vscode.Uri.from(json).with({ query: 'readonly' })

vscode.workspace
.openTextDocument(sourcegraphSchemaURI)
.then(doc => vscode.window.showTextDocument(doc))
.then(async doc => vscode.window.showTextDocument(doc))
}

private submitOrEditOperation: AbortController | undefined
Expand Down
49 changes: 43 additions & 6 deletions vscode/src/chat/chat-view/sourcegraphRemoteFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ import { graphqlClient, isError } from '@sourcegraph/cody-shared'
import { LRUCache } from 'lru-cache'
import * as vscode from 'vscode'

export class SourcegraphRemoteFileProvider
implements vscode.TextDocumentContentProvider, vscode.Disposable
{
export class SourcegraphRemoteFileProvider implements vscode.FileSystemProvider, vscode.Disposable {
private cache = new LRUCache<string, string>({ max: 128 })
private disposables: vscode.Disposable[] = []

constructor() {
this.disposables.push(
vscode.workspace.registerTextDocumentContentProvider('codysourcegraph', this)
vscode.workspace.registerFileSystemProvider('codysourcegraph', this, { isReadonly: true })
)
}

async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
async readFile(uri: vscode.Uri): Promise<Uint8Array<ArrayBufferLike>> {
const content =
this.cache.get(uri.toString()) ||
(await SourcegraphRemoteFileProvider.getFileContentsFromURL(uri))

this.cache.set(uri.toString(), content)

return content
return new TextEncoder().encode(content)
}

public dispose(): void {
Expand Down Expand Up @@ -56,4 +54,43 @@ export class SourcegraphRemoteFileProvider

return content
}

// Below methods are unused

onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = new vscode.EventEmitter<
vscode.FileChangeEvent[]
>().event

watch(): vscode.Disposable {
return new vscode.Disposable(() => {})
}

stat(uri: vscode.Uri): vscode.FileStat {
return {
type: vscode.FileType.File,
ctime: 0,
mtime: 0,
size: 0,
}
}

readDirectory() {
return []
}

createDirectory() {
throw new Error('Method not implemented.')
}

writeFile() {
throw new Error('Method not implemented.')
}

rename() {
throw new Error('Method not implemented.')
}

delete() {
throw new Error('Method not implemented.')
}
}
1 change: 1 addition & 0 deletions vscode/webviews/utils/useFeatureFlags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useExtensionAPI, useObservable } from '@sourcegraph/prompt-editor'
import { useMemo } from 'react'

/**
*
* React hook for getting a feature flag's value.
*
* @returns `true` or `false` if the flag is exposed by the server endpoint, has been fetched, and
Expand Down

0 comments on commit 04541ae

Please sign in to comment.