Fail gracefully when trying to jump to a weird document (like a search editor)

Fixes #6445
This commit is contained in:
Jason Fields 2021-11-05 14:12:15 -04:00
parent 8fb76a106b
commit 35faa9209b
2 changed files with 10 additions and 2 deletions

View File

@ -14,6 +14,7 @@ export enum ErrorCode {
NoPreviousRegularExpression = 35,
NoWriteSinceLastChange = 37,
ErrorWritingToFile = 208,
FileNoLongerAvailable = 211,
RecursiveMapping = 223,
NoStringUnderCursor = 348,
NothingInRegister = 353,
@ -48,6 +49,7 @@ export const ErrorMessage: IErrorMessage = {
35: 'No previous regular expression',
37: 'No write since last change (add ! to override)',
208: 'Error writing to file',
211: 'File no longer available', // TODO: Should be `File "[file_name]" no longer available`
223: 'Recursive mapping',
348: 'No string under cursor',
353: 'Nothing in register',

View File

@ -6,6 +6,7 @@ import { VimState } from '../state/vimState';
import { Jump } from './jump';
import { existsAsync } from 'platform/fs';
import { Position } from 'vscode';
import { ErrorCode, VimError } from '../error';
const MAX_JUMPS = 100;
@ -111,8 +112,13 @@ export class JumpTracker {
this.isJumpingThroughHistory = true;
if (jump.document) {
// Open jump file from stored editor
await vscode.window.showTextDocument(jump.document);
try {
// Open jump file from stored editor
await vscode.window.showTextDocument(jump.document);
} catch (e: unknown) {
// This can happen when the document we'd like to jump to is weird (like a search editor) or has been deleted
throw VimError.fromCode(ErrorCode.FileNoLongerAvailable);
}
} else if (await existsAsync(jump.fileName)) {
// Open jump file from disk
await new FileCommand({