Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit a741da2

Browse files
committed
fix: render diffs for created files
1 parent b15f9a5 commit a741da2

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/extension.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ export function activate(context: vscode.ExtensionContext): void {
9696
}
9797

9898
const semanticTokens = new SourcegraphSemanticTokenProvider()
99-
for (const color of ['green', 'orange', 'red']) {
100-
for (const index of [1, 2, 3]) {
101-
const name = `extension.${color}${index}`
102-
context.subscriptions.push(vscode.commands.registerCommand(name, () => {}))
103-
}
104-
}
10599
context.subscriptions.push(
106100
vscode.commands.registerCommand('extension.goToFileInFolder', async (uri: string | undefined) => {
107101
if (typeof uri === 'string') {

src/file-system/DiffsTreeDataProvider.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class DiffsTreeDataProvider implements vscode.TreeDataProvider<string> {
179179

180180
private oldPath(newPath: string, nodes: FileDiffNode[]): FileDiffNode | undefined {
181181
for (const node of nodes) {
182-
if (newPath === node.newPath && node.oldPath) {
182+
if (newPath === node.newPath) {
183183
return node
184184
}
185185
}
@@ -261,18 +261,21 @@ export class DiffsTreeDataProvider implements vscode.TreeDataProvider<string> {
261261
fileDiff: FileDiffNode | undefined,
262262
comparison: RepositoryComparison
263263
): vscode.TreeItem {
264-
const command =
265-
uri.isFile() && fileDiff?.oldPath
266-
? {
267-
command: 'vscode.diff',
268-
title: 'Compare files',
269-
arguments: [
270-
vscode.Uri.parse(uri.withRevision(range.base).withPath(fileDiff.oldPath).uri),
271-
vscode.Uri.parse(uri.withRevision(range.head).uri),
272-
`${uri.basename()} (${range.base}...${range.head})`,
273-
],
274-
}
275-
: undefined
264+
const command = uri.isFile()
265+
? {
266+
command: 'vscode.diff',
267+
title: 'Compare files',
268+
arguments: [
269+
vscode.Uri.parse(
270+
fileDiff?.oldPath
271+
? uri.withRevision(range.base).withPath(fileDiff.oldPath).uri
272+
: this.fs.emptyFileUri()
273+
),
274+
vscode.Uri.parse(uri.withRevision(range.head).uri),
275+
`${uri.basename()} (${range.base}...${range.head})`,
276+
],
277+
}
278+
: undefined
276279

277280
const fileStats = fileDiffStats(uri, fileDiff, comparison)
278281
const label = uri.treeItemLabel(parent)

src/file-system/SourcegraphFileSystemProvider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ export class SourcegraphFileSystemProvider implements vscode.FileSystemProvider
4040
public readonly onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = this.didChangeFile.event
4141
public async stat(vscodeUri: vscode.Uri): Promise<vscode.FileStat> {
4242
const uri = this.sourcegraphUri(vscodeUri)
43+
const now = Date.now()
44+
if (uri.uri === this.emptyFileUri()) {
45+
return { mtime: now, ctime: now, size: 0, type: vscode.FileType.File }
46+
}
4347
const files = await this.downloadFiles(uri)
4448
const isFile = uri.path && files.includes(uri.path)
4549
const type = isFile ? vscode.FileType.File : vscode.FileType.Directory
4650
// log.appendLine(
4751
// `stat(${uri.uri}) path=${uri.path || '""'} files.length=${files.length} type=${vscode.FileType[type]}`
4852
// )
49-
const now = Date.now()
5053
return {
5154
// It seems to be OK to return hardcoded values for the timestamps
5255
// and the byte size. If it turns out the byte size needs to be
@@ -59,8 +62,15 @@ export class SourcegraphFileSystemProvider implements vscode.FileSystemProvider
5962
}
6063
}
6164

65+
public emptyFileUri(): string {
66+
return 'sourcegraph://sourcegraph.com/empty-file.txt'
67+
}
68+
6269
public async readFile(vscodeUri: vscode.Uri): Promise<Uint8Array> {
6370
const uri = this.sourcegraphUri(vscodeUri)
71+
if (uri.uri === this.emptyFileUri()) {
72+
return new Uint8Array()
73+
}
6474
const blob = await this.fetchBlob(uri)
6575
return blob.content
6676
}

0 commit comments

Comments
 (0)