From 2ffbb788335e7006294ed9de4f8753ce915afbd5 Mon Sep 17 00:00:00 2001 From: Jason Fields Date: Thu, 28 Nov 2019 23:15:15 -0500 Subject: [PATCH] Just some trivial clean-up --- extension.ts | 5 ++--- src/actions/motion.ts | 1 + src/actions/textobject.ts | 2 ++ src/cmd_line/lexer.ts | 26 ++++++-------------------- src/common/matching/matcher.ts | 4 ++-- src/common/motion/position.ts | 25 +++++++++++++++---------- src/register/register.ts | 2 +- src/statusBar.ts | 2 +- src/util/clipboard.ts | 3 +++ src/util/logger.ts | 2 +- 10 files changed, 34 insertions(+), 38 deletions(-) diff --git a/extension.ts b/extension.ts index fe1619b60..1cc903eb0 100644 --- a/extension.ts +++ b/extension.ts @@ -25,7 +25,6 @@ import { configuration } from './src/configuration/configuration'; import { globalState } from './src/state/globalState'; import { taskQueue } from './src/taskQueue'; import { Register } from './src/register/register'; -import { vimrc } from './src/configuration/vimrc'; let extensionContext: vscode.ExtensionContext; let previousActiveEditorId: EditorIdentity | null = null; @@ -123,13 +122,13 @@ export async function activate(context: vscode.ExtensionContext) { ); registerEventListener(context, vscode.workspace.onDidChangeTextDocument, async event => { - const textWasDeleted = changeEvent => + const textWasDeleted = (changeEvent: vscode.TextDocumentChangeEvent) => changeEvent.contentChanges.length === 1 && changeEvent.contentChanges[0].text === '' && changeEvent.contentChanges[0].range.start.line !== changeEvent.contentChanges[0].range.end.line; - const textWasAdded = changeEvent => + const textWasAdded = (changeEvent: vscode.TextDocumentChangeEvent) => changeEvent.contentChanges.length === 1 && (changeEvent.contentChanges[0].text === '\n' || changeEvent.contentChanges[0].text === '\r\n') && diff --git a/src/actions/motion.ts b/src/actions/motion.ts index ca96602ce..0687dbb46 100644 --- a/src/actions/motion.ts +++ b/src/actions/motion.ts @@ -1583,6 +1583,7 @@ export abstract class MoveQuoteMatch extends BaseMovement { isJump = true; public async execAction(position: Position, vimState: VimState): Promise { + // TODO: Don't limit quote matching to the same line const text = TextEditor.getLineAt(position).text; const quoteMatcher = new QuoteMatcher(this.charToMatch, text); let start = quoteMatcher.findOpening(position.character); diff --git a/src/actions/textobject.ts b/src/actions/textobject.ts index b4b00956a..9e6a5df8d 100644 --- a/src/actions/textobject.ts +++ b/src/actions/textobject.ts @@ -156,6 +156,8 @@ export class SelectABigWord extends TextObjectMovement { * larger blocks. e.g. if you had "blah (foo [bar 'ba|z'])" then it would * select 'baz' first. If you pressed af again, it'd then select [bar 'baz'], * and if you did it a third time it would select "(foo [bar 'baz'])". + * + * Very similar is the now built-in `editor.action.smartSelect.expand` */ @RegisterAction export class SelectAnExpandingBlock extends ExpandingSelection { diff --git a/src/cmd_line/lexer.ts b/src/cmd_line/lexer.ts index f9361f033..3f2f79615 100644 --- a/src/cmd_line/lexer.ts +++ b/src/cmd_line/lexer.ts @@ -136,23 +136,10 @@ namespace LexerFunctions { return null; } - const c = state.next(); - switch (c) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - continue; - default: - state.backup(); - tokens.push(emitToken(tokenType, state)!); - return lexRange; + if (!/[0-9]/.test(state.next())) { + state.backup(); + tokens.push(emitToken(tokenType, state)!); + return lexRange; } } }; @@ -165,9 +152,8 @@ namespace LexerFunctions { tokens.push(emitToken(TokenType.CommandName, state)!); break; } - const c = state.next(); - const lc = c.toLowerCase(); - if (lc >= 'a' && lc <= 'z') { + const c = state.next().toLowerCase(); + if (c >= 'a' && c <= 'z') { continue; } else { state.backup(); diff --git a/src/common/matching/matcher.ts b/src/common/matching/matcher.ts index c5d5ce6ae..e427f30e5 100644 --- a/src/common/matching/matcher.ts +++ b/src/common/matching/matcher.ts @@ -40,7 +40,7 @@ export class PairMatcher { position: Position, charToFind: string, charToStack: string, - stackHeight, + stackHeight: number, isNextMatchForward: boolean, vimState?: VimState ): Position | undefined { @@ -107,7 +107,7 @@ export class PairMatcher { return undefined; } - private static keepSearching(lineNumber, lineCount, isNextMatchForward) { + private static keepSearching(lineNumber: number, lineCount: number, isNextMatchForward: boolean) { if (isNextMatchForward) { return lineNumber <= lineCount - 1; } else { diff --git a/src/common/motion/position.ts b/src/common/motion/position.ts index ed5fc92e6..ed5db6275 100644 --- a/src/common/motion/position.ts +++ b/src/common/motion/position.ts @@ -288,7 +288,9 @@ export class Position extends vscode.Position { } } - // Iterates through words on the same line, starting from the current position. + /** + * Iterates through words on the same line, starting from the current position. + */ public static *IterateWords( start: Position ): Iterable<{ start: Position; end: Position; word: string }> { @@ -1297,16 +1299,19 @@ export class Position extends vscode.Position { throw new Error('This should never happen...'); } - private findHelper(char: string, count: number, direction: number): Position | undefined { - // -1 = backwards, +1 = forwards + private findHelper( + char: string, + count: number, + direction: 'forward' | 'backward' + ): Position | undefined { const line = TextEditor.getLineAt(this); let index = this.character; while (count && index !== -1) { - if (direction > 0) { - index = line.text.indexOf(char, index + direction); + if (direction === 'forward') { + index = line.text.indexOf(char, index + 1); } else { - index = line.text.lastIndexOf(char, index + direction); + index = line.text.lastIndexOf(char, index - 1); } count--; } @@ -1319,7 +1324,7 @@ export class Position extends vscode.Position { } public tilForwards(char: string, count: number = 1): Position | null { - const position = this.findHelper(char, count, +1); + const position = this.findHelper(char, count, 'forward'); if (!position) { return null; } @@ -1328,7 +1333,7 @@ export class Position extends vscode.Position { } public tilBackwards(char: string, count: number = 1): Position | null { - const position = this.findHelper(char, count, -1); + const position = this.findHelper(char, count, 'backward'); if (!position) { return null; } @@ -1337,7 +1342,7 @@ export class Position extends vscode.Position { } public findForwards(char: string, count: number = 1): Position | null { - const position = this.findHelper(char, count, +1); + const position = this.findHelper(char, count, 'forward'); if (!position) { return null; } @@ -1346,7 +1351,7 @@ export class Position extends vscode.Position { } public findBackwards(char: string, count: number = 1): Position | null { - const position = this.findHelper(char, count, -1); + const position = this.findHelper(char, count, 'backward'); if (!position) { return null; } diff --git a/src/register/register.ts b/src/register/register.ts index 400fabb64..2a5dab6bd 100644 --- a/src/register/register.ts +++ b/src/register/register.ts @@ -13,7 +13,7 @@ import { VimState } from './../state/vimState'; /** * There are two different modes of copy/paste in Vim - copy by character * and copy by line. Copy by line typically happens in Visual Line mode, but - * also shows up in some other actions that work over lines (most noteably dd, + * also shows up in some other actions that work over lines (most notably dd, * yy). */ export enum RegisterMode { diff --git a/src/statusBar.ts b/src/statusBar.ts index 40498b733..e37efcbe1 100644 --- a/src/statusBar.ts +++ b/src/statusBar.ts @@ -87,7 +87,7 @@ class StatusBarImpl implements vscode.Disposable { 'statusBar.foreground': `${foreground}`, }); - // if colors are undefined, return to vscode defaults + // If colors are undefined, return to VSCode defaults if (background === undefined) { delete colorCustomizations['statusBar.background']; delete colorCustomizations['statusBar.noFolderBackground']; diff --git a/src/util/clipboard.ts b/src/util/clipboard.ts index cdff7a161..ab311b5ec 100644 --- a/src/util/clipboard.ts +++ b/src/util/clipboard.ts @@ -1,6 +1,9 @@ import * as vscode from 'vscode'; import { Logger } from './logger'; +/** + * A thin wrapper around `vscode.env.clipboard` + */ export class Clipboard { private static readonly logger = Logger.get('Clipboard'); diff --git a/src/util/logger.ts b/src/util/logger.ts index 49e041913..33e9a4eb2 100644 --- a/src/util/logger.ts +++ b/src/util/logger.ts @@ -10,7 +10,7 @@ interface VsCodeMessageOptions extends TransportStream.TransportStreamOptions { /** * Implementation of Winston transport - * Displays VS Code message to user + * Displays VSCode message to user */ class VsCodeMessage extends TransportStream { prefix?: string;