From 37feb18ca138a229e8e9e95141fd09c97654f55d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 2 Nov 2022 01:09:42 -0400 Subject: [PATCH] Fixes #1488 issue with translated error messages --- CHANGELOG.md | 1 + src/trackers/documentTracker.ts | 35 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7597b..90e9db9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed +- Fixes [#1488](https://github.com/gitkraken/vscode-gitlens/issues/1488) - Open Folder History not working with non-English language pack - Fixes [#2303](https://github.com/gitkraken/vscode-gitlens/issues/2303) - "Googlesource" gerrit only supports two levels of domain — thanks to [PR #2304](https://github.com/gitkraken/vscode-gitlens/pull/2304) by Matt Buckley ([@Mattadore](https://github.com/Mattadore)) - Fixes [#2300](https://github.com/gitkraken/vscode-gitlens/issues/2300) - extra non-functional toolbar buttons when viewing PR diffs in VSCode web - Fixes [#2281](https://github.com/gitkraken/vscode-gitlens/issues/2281) - Push and Pull buttons missing from the commits view w/ integrations disabled diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index 4722148..f17e431 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -9,7 +9,7 @@ import type { TextEditor, TextLine, } from 'vscode'; -import { Disposable, EndOfLine, EventEmitter, Uri, window, workspace } from 'vscode'; +import { Disposable, EndOfLine, env, EventEmitter, Uri, window, workspace } from 'vscode'; import { configuration } from '../configuration'; import { ContextKeys } from '../constants'; import type { Container } from '../container'; @@ -241,20 +241,27 @@ export class DocumentTracker implements Disposable { document = await workspace.openTextDocument(documentOrUri.documentUri()); } catch (ex) { const msg: string = ex?.toString() ?? ''; - if (msg.includes('File seems to be binary and cannot be opened as text')) { - document = new BinaryTextDocument(documentOrUri); - } else if ( - msg.includes('File not found') || - msg.includes('Unable to read file') || - msg.includes('Unable to resolve non-existing file') - ) { - // If we can't find the file, assume it is because the file has been renamed or deleted at some point + if (env.language.startsWith('en')) { + if (msg.includes('File seems to be binary and cannot be opened as text')) { + document = new BinaryTextDocument(documentOrUri); + } else if ( + msg.includes('File not found') || + msg.includes('Unable to read file') || + msg.includes('Unable to resolve non-existing file') + ) { + // If we can't find the file, assume it is because the file has been renamed or deleted at some point + document = new MissingRevisionTextDocument(documentOrUri); + + // const [fileName, repoPath] = await this.container.git.findWorkingFileName(documentOrUri, undefined, ref); + // if (fileName == null) throw new Error(`Failed to add tracking for document: ${documentOrUri}`); + + // documentOrUri = await workspace.openTextDocument(path.resolve(repoPath!, fileName)); + } else { + throw ex; + } + } else if (msg.includes('cannot open')) { + // If we aren't in english, we can't figure out what the error might be (since the messages are translated), so just assume its missing document = new MissingRevisionTextDocument(documentOrUri); - - // const [fileName, repoPath] = await this.container.git.findWorkingFileName(documentOrUri, undefined, ref); - // if (fileName == null) throw new Error(`Failed to add tracking for document: ${documentOrUri}`); - - // documentOrUri = await workspace.openTextDocument(path.resolve(repoPath!, fileName)); } else { throw ex; }