mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-14 10:03:15 -05:00
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
'use strict';
|
|
import { CancellationToken, ExtensionContext, TextDocumentContentProvider, Uri, window } from 'vscode';
|
|
import { DocumentSchemes } from './constants';
|
|
import { GitService } from './gitService';
|
|
import { Logger } from './logger';
|
|
import * as path from 'path';
|
|
|
|
export class GitContentProvider implements TextDocumentContentProvider {
|
|
|
|
static scheme = DocumentSchemes.GitLensGit;
|
|
|
|
constructor(context: ExtensionContext, private git: GitService) { }
|
|
|
|
async provideTextDocumentContent(uri: Uri, token: CancellationToken): Promise<string | undefined> {
|
|
const data = GitService.fromGitContentUri(uri);
|
|
const fileName = data.originalFileName || data.fileName;
|
|
try {
|
|
let text = await this.git.getVersionedFileText(data.repoPath, fileName, data.sha);
|
|
if (data.decoration) {
|
|
text = `${data.decoration}\n${text}`;
|
|
}
|
|
return text;
|
|
}
|
|
catch (ex) {
|
|
Logger.error(ex, 'GitContentProvider', 'getVersionedFileText');
|
|
window.showErrorMessage(`Unable to show Git revision ${data.sha.substring(0, 8)} of '${path.relative(data.repoPath, fileName)}'`);
|
|
return undefined;
|
|
}
|
|
}
|
|
} |