mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 20:27:17 +03:00
A bit more general clean-up
This commit is contained in:
parent
fec96c4695
commit
b9353ae810
10
extension.ts
10
extension.ts
@ -90,8 +90,7 @@ async function loadConfiguration() {
|
||||
}
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
// before we do anything else,
|
||||
// we need to load the configuration first
|
||||
// before we do anything else, we need to load the configuration
|
||||
await loadConfiguration();
|
||||
|
||||
const logger = Logger.get('Extension Startup');
|
||||
@ -145,8 +144,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
);
|
||||
}
|
||||
|
||||
// Change from vscode editor should set document.isDirty to true but they initially don't!
|
||||
// There is a timing issue in vscode codebase between when the isDirty flag is set and
|
||||
// Change from VSCode editor should set document.isDirty to true but they initially don't!
|
||||
// There is a timing issue in VSCode codebase between when the isDirty flag is set and
|
||||
// when registered callbacks are fired. https://github.com/Microsoft/vscode/issues/11339
|
||||
const contentChangeHandler = (modeHandler: ModeHandler) => {
|
||||
if (modeHandler.vimState.currentMode === ModeName.Insert) {
|
||||
@ -188,7 +187,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
const modeHandler = ModeHandlerMap.get(editorIdentity);
|
||||
|
||||
let shouldDelete = false;
|
||||
|
||||
if (modeHandler == null || modeHandler.vimState.editor === undefined) {
|
||||
shouldDelete = true;
|
||||
} else {
|
||||
@ -387,7 +385,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
if (args.commands) {
|
||||
for (const command of args.commands) {
|
||||
// Check if this is a vim command by looking for :
|
||||
if (command.command.slice(0, 1) === ':') {
|
||||
if (command.command.startsWith(':')) {
|
||||
await commandLine.Run(command.command.slice(1, command.command.length), mh.vimState);
|
||||
mh.updateView(mh.vimState);
|
||||
} else {
|
||||
|
@ -4,6 +4,7 @@ import { BaseAction } from './base';
|
||||
import { ModeName } from '../mode/mode';
|
||||
import { VimState } from '../state/vimState';
|
||||
import { RecordedState } from '../state/recordedState';
|
||||
import { clamp } from '../util/util';
|
||||
|
||||
export function isIMovement(o: IMovement | Position): o is IMovement {
|
||||
return (o as IMovement).start !== undefined && (o as IMovement).stop !== undefined;
|
||||
@ -117,7 +118,7 @@ export abstract class BaseMovement extends BaseAction {
|
||||
let prevResult: IMovement | undefined = undefined;
|
||||
let firstMovementStart: Position = new Position(position.line, position.character);
|
||||
|
||||
count = this.clampCount(count);
|
||||
count = clamp(count, this.minCount, this.maxCount);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const firstIteration = i === 0;
|
||||
@ -147,12 +148,6 @@ export abstract class BaseMovement extends BaseAction {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected clampCount(count: number) {
|
||||
count = Math.max(count, this.minCount);
|
||||
count = Math.min(count, this.maxCount);
|
||||
return count;
|
||||
}
|
||||
|
||||
protected async createMovementResult(
|
||||
position: Position,
|
||||
vimState: VimState,
|
||||
@ -165,6 +160,7 @@ export abstract class BaseMovement extends BaseAction {
|
||||
: await this.execAction(position, vimState);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected adjustPosition(position: Position, result: IMovement, lastIteration: boolean) {
|
||||
if (!lastIteration) {
|
||||
position = result.stop.getRightThroughLineBreaks();
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { VimState } from '../../state/vimState';
|
||||
import * as node from '../node';
|
||||
import { StatusBar } from '../../statusBar';
|
||||
import { globalState } from '../../state/globalState';
|
||||
import { ReportClear } from '../../util/statusBarTextUtils';
|
||||
|
||||
export class NohlCommand extends node.CommandBase {
|
||||
protected _arguments: {};
|
||||
@ -19,6 +19,6 @@ export class NohlCommand extends node.CommandBase {
|
||||
globalState.hl = false;
|
||||
|
||||
// Clear the `match x of y` message from status bar
|
||||
StatusBar.Set('', vimState, true);
|
||||
ReportClear(vimState);
|
||||
}
|
||||
}
|
||||
|
@ -67,12 +67,7 @@ export class SetOptionsCommand extends node.CommandBase {
|
||||
}
|
||||
|
||||
if (configuration[this._arguments.name] == null) {
|
||||
StatusBar.Set(
|
||||
`${VimError.fromCode(ErrorCode.E518).toString()}. ${this._arguments.name}`,
|
||||
vimState,
|
||||
true
|
||||
);
|
||||
return;
|
||||
throw VimError.fromCode(ErrorCode.E518);
|
||||
}
|
||||
|
||||
switch (this._arguments.operator) {
|
||||
@ -104,11 +99,7 @@ export class SetOptionsCommand extends node.CommandBase {
|
||||
case SetOptionOperator.Info:
|
||||
let value = configuration[this._arguments.name];
|
||||
if (value === undefined) {
|
||||
StatusBar.Set(
|
||||
`${VimError.fromCode(ErrorCode.E518).toString()}. ${value}`,
|
||||
vimState,
|
||||
true
|
||||
);
|
||||
throw VimError.fromCode(ErrorCode.E518);
|
||||
} else {
|
||||
StatusBar.Set(`${this._arguments.name}=${value}`, vimState, true);
|
||||
}
|
||||
|
@ -5,11 +5,15 @@ import { ModeHandler } from './mode/modeHandler';
|
||||
* Global variables shared throughout extension
|
||||
*/
|
||||
export class Globals {
|
||||
static isTesting = false;
|
||||
|
||||
static mockModeHandler: ModeHandler;
|
||||
|
||||
static mockConfiguration: IConfiguration;
|
||||
|
||||
/**
|
||||
* This is where we put files like HistoryFile. The path is given to us by VSCode.
|
||||
*/
|
||||
static extensionStoragePath: string;
|
||||
|
||||
/**
|
||||
* Used for testing.
|
||||
*/
|
||||
static isTesting = false;
|
||||
static mockModeHandler: ModeHandler;
|
||||
static mockConfiguration: IConfiguration;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import { Jump } from './jump';
|
||||
import { getCursorsAfterSync } from '../util/util';
|
||||
|
||||
/**
|
||||
* JumpTracker is a handrolled version of vscode's TextEditorState
|
||||
* JumpTracker is a handrolled version of VSCode's TextEditorState
|
||||
* in relation to the 'workbench.action.navigateBack' command.
|
||||
*/
|
||||
export class JumpTracker {
|
||||
|
@ -45,7 +45,7 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
this.logger.debug(`version: ${version.major}.${version.minor}.${version.patch}`);
|
||||
}
|
||||
|
||||
await this.syncVSToVim(vimState);
|
||||
await this.syncVSCodeToVim(vimState);
|
||||
command = (':' + command + '\n').replace('<', '<lt>');
|
||||
|
||||
// Clear the previous error and status messages.
|
||||
@ -73,8 +73,8 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync buffer back to vscode
|
||||
await this.syncVimToVs(vimState);
|
||||
// Sync buffer back to VSCode
|
||||
await this.syncVimToVSCode(vimState);
|
||||
|
||||
return statusBarText;
|
||||
}
|
||||
@ -97,8 +97,8 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
return attach({ proc: this.process });
|
||||
}
|
||||
|
||||
// Data flows from VS to Vim
|
||||
private async syncVSToVim(vimState: VimState) {
|
||||
// Data flows from VSCode to Vim
|
||||
private async syncVSCodeToVim(vimState: VimState) {
|
||||
const buf = await this.nvim.buffer;
|
||||
if (configuration.expandtab) {
|
||||
await vscode.commands.executeCommand('editor.action.indentationToTabs');
|
||||
@ -144,8 +144,8 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
]);
|
||||
}
|
||||
|
||||
// Data flows from Vim to VS
|
||||
private async syncVimToVs(vimState: VimState) {
|
||||
// Data flows from Vim to VSCode
|
||||
private async syncVimToVSCode(vimState: VimState) {
|
||||
const buf = await this.nvim.buffer;
|
||||
const lines = await buf.getLines({ start: 0, end: -1, strictIndexing: false });
|
||||
|
||||
|
@ -20,7 +20,7 @@ class GlobalState {
|
||||
/**
|
||||
* Track jumps, and traverse jump history
|
||||
*/
|
||||
private _jumpTracker: JumpTracker = new JumpTracker();
|
||||
public readonly jumpTracker: JumpTracker = new JumpTracker();
|
||||
|
||||
/**
|
||||
* Tracks search history
|
||||
@ -125,10 +125,6 @@ class GlobalState {
|
||||
|
||||
return item ? item.searchState : undefined;
|
||||
}
|
||||
|
||||
public get jumpTracker(): JumpTracker {
|
||||
return this._jumpTracker;
|
||||
}
|
||||
}
|
||||
|
||||
export const globalState = new GlobalState();
|
||||
|
@ -102,9 +102,9 @@ export class VimState implements vscode.Disposable {
|
||||
public actionCount = 0;
|
||||
|
||||
/**
|
||||
* Every time we invoke a VS Code command which might trigger Code's view update,
|
||||
* we should postpone its view updating phase to avoid conflicting with our internal view updating mechanism.
|
||||
* This array is used to cache every VS Code view updating event and they will be triggered once we run the inhouse `viewUpdate`.
|
||||
* Every time we invoke a VSCode command which might trigger a view update.
|
||||
* We should postpone its view updating phase to avoid conflicting with our internal view updating mechanism.
|
||||
* This array is used to cache every VSCode view updating event and they will be triggered once we run the inhouse `viewUpdate`.
|
||||
*/
|
||||
public postponedCodeViewChanges: ViewChange[] = [];
|
||||
|
||||
|
@ -6,7 +6,7 @@ import { exec } from 'child_process';
|
||||
|
||||
/**
|
||||
* This is certainly quite janky! The problem we're trying to solve
|
||||
* is that writing editor.selection = new Position() won't immediately
|
||||
* is that writing `editor.selection = new Position()` won't immediately
|
||||
* update the position of the cursor. So we have to wait!
|
||||
*/
|
||||
export async function waitForCursorSync(
|
||||
@ -38,7 +38,7 @@ export async function getCursorsAfterSync(timeoutInMilliseconds: number = 0): Pr
|
||||
}
|
||||
|
||||
/**
|
||||
* This function execute a shell command and return the standard output as string.
|
||||
* This function executes a shell command and returns the standard output as a string.
|
||||
*/
|
||||
export function executeShell(cmd: string): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
|
Loading…
Reference in New Issue
Block a user