Skip to content

Commit aa9835c

Browse files
committed
Vary E996 message by type
1 parent 5004a01 commit aa9835c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/cmd_line/commands/let.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,21 @@ export class LetCommand extends ExCommand {
177177
if (this.args.lock) {
178178
if (this.args.operation !== '=') {
179179
throw VimError.CannotModifyExistingVariable();
180-
} else if (variable.type !== 'variable') {
181-
// TODO: this error message should vary by type
182-
throw VimError.CannotLockARegister();
180+
}
181+
if (variable.type !== 'variable') {
182+
if (variable.type === 'register') {
183+
throw VimError.CannotLock('a register');
184+
}
185+
if (variable.type === 'option') {
186+
throw VimError.CannotLock('an option');
187+
}
188+
if (variable.type === 'env_variable') {
189+
throw VimError.CannotLock('an environment variable');
190+
}
191+
if (variable.type === 'slice') {
192+
throw VimError.CannotLock('a range');
193+
}
194+
throw VimError.CannotLock('a list or dict');
183195
}
184196
}
185197

src/error.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export enum ErrorCode {
8989
CanOnlyCompareBlobWithBlob = 977,
9090
InvalidOperationForBlob = 978,
9191
CannotModifyExistingVariable = 995,
92-
CannotLockARegister = 996,
92+
CannotLock = 996,
9393
ListRequiredForArgument = 1211,
9494
}
9595

@@ -437,8 +437,10 @@ export class VimError extends Error {
437437
static CannotModifyExistingVariable(): VimError {
438438
return new VimError(ErrorCode.CannotModifyExistingVariable, 'Cannot modify existing variable');
439439
}
440-
static CannotLockARegister(): VimError {
441-
return new VimError(ErrorCode.CannotLockARegister, 'Cannot lock a register');
440+
static CannotLock(
441+
what: 'a range' | 'an option' | 'a list or dict' | 'an environment variable' | 'a register',
442+
): VimError {
443+
return new VimError(ErrorCode.CannotLock, `Cannot lock ${what}`);
442444
}
443445
static ListRequiredForArgument(idx: number): VimError {
444446
return new VimError(ErrorCode.ListRequiredForArgument, `List required for argument ${idx}`);

0 commit comments

Comments
 (0)