Fix :p[ut] command neovim capability and subparser (#5063)

Enables neovim capability and fixes arg parsing for the `:p[ut]` command. Apparently the put command allows no whitespace between the command name and the register name, so commands like `:put"` are perfectly valid. I've added some subparser tests to document this.

Fixes #5052
Fixes #5090
This commit is contained in:
J.R. Maingat 2020-08-14 23:36:48 -04:00 committed by GitHub
parent b74ccf6244
commit e0da682ac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 3 deletions

View File

@ -27,6 +27,10 @@ export class PutExCommand extends node.CommandBase {
return this._arguments;
}
public neovimCapable(): boolean {
return true;
}
async doPut(vimState: VimState, position: Position) {
const registerName = this.arguments.register || (configuration.useSystemClipboard ? '*' : '"');
vimState.recordedState.registerName = registerName;

View File

@ -1,5 +1,4 @@
import { PutExCommand, IPutCommandArguments } from '../commands/put';
import { ErrorCode, VimError } from '../../error';
import { Scanner } from '../scanner';
export function parsePutExCommandArgs(args: string): PutExCommand {
@ -14,8 +13,8 @@ export function parsePutExCommandArgs(args: string): PutExCommand {
if (c === '!') {
scannedArgs.bang = true;
scanner.ignore();
} else if (c !== ' ') {
throw VimError.fromCode(ErrorCode.TrailingCharacters);
} else {
scanner.backup();
}
scanner.skipWhiteSpace();

View File

@ -0,0 +1,34 @@
import * as assert from 'assert';
import { commandParsers } from '../../src/cmd_line/subparser';
suite(':put args parser', () => {
test('can parse empty args', () => {
const args = commandParsers.put.parser('');
assert.strictEqual(args.arguments.bang, undefined);
assert.strictEqual(args.arguments.register, undefined);
});
test('can parse !', () => {
const args = commandParsers.put.parser('!');
assert.strictEqual(args.arguments.bang, true);
assert.strictEqual(args.arguments.range, undefined);
});
test('can parse register', () => {
const args = commandParsers.put.parser(' *');
assert.strictEqual(args.arguments.bang, undefined);
assert.strictEqual(args.arguments.register, '*');
});
test('can parse register with no whitespace', () => {
const args = commandParsers.put.parser('*');
assert.strictEqual(args.arguments.bang, undefined);
assert.strictEqual(args.arguments.register, '*');
});
test('can parse register with no whitespace and !', () => {
const args = commandParsers.put.parser('!*');
assert.strictEqual(args.arguments.bang, true);
assert.strictEqual(args.arguments.register, '*');
});
});