mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 12:25:59 +03:00
refactor: move util.ts into util folder. separate clipboard/messages to own files. don't export default
This commit is contained in:
parent
3b2631ed46
commit
c4cd9a3f7f
@ -20,7 +20,7 @@ import { Notation } from './src/configuration/notation';
|
||||
import { StatusBar } from './src/statusBar';
|
||||
import { taskQueue } from './src/taskQueue';
|
||||
import { ModeHandlerMap } from './src/mode/modeHandlerMap';
|
||||
import logger from './src/util/logger';
|
||||
import { logger } from './src/util/logger';
|
||||
|
||||
let extensionContext: vscode.ExtensionContext;
|
||||
|
||||
|
@ -3,7 +3,8 @@ import * as vscode from 'vscode';
|
||||
import { RecordedState } from '../../state/recordedState';
|
||||
import { ReplaceState } from '../../state/replaceState';
|
||||
import { VimState } from '../../state/vimState';
|
||||
import { allowVSCodeToPropagateCursorUpdatesAndReturnThem, Clipboard } from '../../util';
|
||||
import { allowVSCodeToPropagateCursorUpdatesAndReturnThem } from '../../util/util';
|
||||
import { Clipboard } from '../../util/clipboard';
|
||||
import { FileCommand } from './../../cmd_line/commands/file';
|
||||
import { OnlyCommand } from './../../cmd_line/commands/only';
|
||||
import { QuitCommand } from './../../cmd_line/commands/quit';
|
||||
|
@ -1,11 +1,12 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { configuration } from '../configuration/configuration';
|
||||
import logger from '../util/logger';
|
||||
import { logger } from '../util/logger';
|
||||
import { Message } from '../util/message';
|
||||
import { getExternalExtensionDirPath } from '../util/util';
|
||||
import { VimState } from '../state/vimState';
|
||||
import { StatusBar } from '../statusBar';
|
||||
import * as parser from './parser';
|
||||
import * as util from '../util';
|
||||
import { VimError, ErrorCode } from '../error';
|
||||
import { CommandLineHistory } from './commandLineHistory';
|
||||
|
||||
@ -56,7 +57,7 @@ export class CommandLine {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
util.showError(e.toString());
|
||||
Message.ShowError(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -93,7 +94,7 @@ export class CommandLine {
|
||||
}
|
||||
|
||||
public static LoadHistory(): void {
|
||||
util.getExternalExtensionDirPath().then(externalExtensionDirPath => {
|
||||
getExternalExtensionDirPath().then(externalExtensionDirPath => {
|
||||
const path = require('path');
|
||||
const filePath: string = path.join(externalExtensionDirPath, '.cmdline_history');
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { configuration } from '../configuration/configuration';
|
||||
import logger from '../util/logger';
|
||||
import { logger } from '../util/logger';
|
||||
|
||||
export class CommandLineHistory {
|
||||
private _history: string[] = [];
|
||||
|
@ -3,7 +3,7 @@ import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import * as node from '../node';
|
||||
import { showError } from './../../util';
|
||||
import { Message } from './../../util/message';
|
||||
|
||||
const untildify = require('untildify');
|
||||
|
||||
@ -107,7 +107,7 @@ export class FileCommand extends node.CommandBase {
|
||||
if (this.arguments.createFileIfNotExists) {
|
||||
fs.closeSync(fs.openSync(filePath, 'w'));
|
||||
} else {
|
||||
showError('The file ' + filePath + ' does not exist.');
|
||||
Message.ShowError('The file ' + filePath + ' does not exist.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { configuration } from '../../configuration/configuration';
|
||||
import * as util from '../../util';
|
||||
import { Message } from '../../util/message';
|
||||
import * as node from '../node';
|
||||
|
||||
export enum SetOptionOperator {
|
||||
@ -98,9 +98,9 @@ export class SetOptionsCommand extends node.CommandBase {
|
||||
case SetOptionOperator.Info:
|
||||
let value = configuration[this._arguments.name];
|
||||
if (value === undefined) {
|
||||
await util.showError(`E518 Unknown option: ${this._arguments.name}`);
|
||||
await Message.ShowError(`E518 Unknown option: ${this._arguments.name}`);
|
||||
} else {
|
||||
await util.showInfo(`${this._arguments.name}=${value}`);
|
||||
await Message.ShowInfo(`${this._arguments.name}=${value}`);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -4,7 +4,7 @@ import * as vscode from 'vscode';
|
||||
|
||||
import { VimState } from '../../state/vimState';
|
||||
import { StatusBar } from '../../statusBar';
|
||||
import * as util from '../../util';
|
||||
import { Message } from '../../util/message';
|
||||
import * as node from '../node';
|
||||
|
||||
export interface IWriteCommandArguments extends node.ICommandArgs {
|
||||
@ -36,16 +36,16 @@ export class WriteCommand extends node.CommandBase {
|
||||
|
||||
async execute(vimState: VimState): Promise<void> {
|
||||
if (this.arguments.opt) {
|
||||
util.showError('Not implemented.');
|
||||
Message.ShowError('Not implemented.');
|
||||
return;
|
||||
} else if (this.arguments.file) {
|
||||
util.showError('Not implemented.');
|
||||
Message.ShowError('Not implemented.');
|
||||
return;
|
||||
} else if (this.arguments.append) {
|
||||
util.showError('Not implemented.');
|
||||
Message.ShowError('Not implemented.');
|
||||
return;
|
||||
} else if (this.arguments.cmd) {
|
||||
util.showError('Not implemented.');
|
||||
Message.ShowError('Not implemented.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ import { Position } from './../common/motion/position';
|
||||
import { RecordedState } from './../state/recordedState';
|
||||
import { VimState } from './../state/vimState';
|
||||
import { TextEditor } from './../textEditor';
|
||||
import logger from './../util/logger';
|
||||
import { logger } from './../util/logger';
|
||||
|
||||
const diffEngine = new DiffMatchPatch.diff_match_patch();
|
||||
diffEngine.Diff_Timeout = 1; // 1 second
|
||||
|
@ -7,7 +7,7 @@ import { Decoration } from '../configuration/decoration';
|
||||
import { Remappers } from '../configuration/remapper';
|
||||
import { Globals } from '../globals';
|
||||
import { StatusBar } from '../statusBar';
|
||||
import { allowVSCodeToPropagateCursorUpdatesAndReturnThem } from '../util';
|
||||
import { allowVSCodeToPropagateCursorUpdatesAndReturnThem } from '../util/util';
|
||||
import { Actions, BaseAction, KeypressState } from './../actions/base';
|
||||
import {
|
||||
BaseCommand,
|
||||
@ -30,7 +30,7 @@ import {
|
||||
TextTransformations,
|
||||
} from './../transformations/transformations';
|
||||
import { Mode, ModeName, VSCodeVimCursorType } from './mode';
|
||||
import logger from '../util/logger';
|
||||
import { logger } from '../util/logger';
|
||||
|
||||
export class ModeHandler implements vscode.Disposable {
|
||||
private _disposables: vscode.Disposable[] = [];
|
||||
|
@ -9,7 +9,7 @@ import { Register, RegisterMode } from '../register/register';
|
||||
import { TextEditor } from '../textEditor';
|
||||
import { Position } from './../common/motion/position';
|
||||
import { VimState } from './../state/vimState';
|
||||
import logger from '../util/logger';
|
||||
import { logger } from '../util/logger';
|
||||
|
||||
export class Neovim implements vscode.Disposable {
|
||||
private process: ChildProcess;
|
||||
|
@ -2,7 +2,7 @@ import { BaseCommand, CommandRegister, CommandYankFullLine } from './../actions/
|
||||
import { BaseOperator, DeleteOperator, YankOperator } from './../actions/operator';
|
||||
import { RecordedState } from './../state/recordedState';
|
||||
import { VimState } from './../state/vimState';
|
||||
import { Clipboard } from './../util';
|
||||
import { Clipboard } from './../util/clipboard';
|
||||
|
||||
/**
|
||||
* There are two different modes of copy/paste in Vim - copy by character
|
||||
|
@ -12,7 +12,7 @@ import { GlobalState } from './../state/globalState';
|
||||
import { ReplaceState } from './../state/replaceState';
|
||||
import { RecordedState } from './recordedState';
|
||||
import { Neovim } from '../neovim/neovim';
|
||||
import logger from '../util/logger';
|
||||
import { logger } from '../util/logger';
|
||||
|
||||
/**
|
||||
* The VimState class holds permanent state that carries over from action
|
||||
|
16
src/util/clipboard.ts
Normal file
16
src/util/clipboard.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { logger } from './logger';
|
||||
import * as clipboardy from 'clipboardy';
|
||||
|
||||
export class Clipboard {
|
||||
public static Copy(text: string) {
|
||||
try {
|
||||
clipboardy.writeSync(text);
|
||||
} catch (e) {
|
||||
logger.error(e, `Clipboard: Error copying to clipboard. Error=${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static Paste(): string {
|
||||
return clipboardy.readSync();
|
||||
}
|
||||
}
|
@ -2,10 +2,8 @@ import { configuration } from '../configuration/configuration';
|
||||
import * as winston from 'winston';
|
||||
import { ConsoleForElectron } from 'winston-console-for-electron';
|
||||
|
||||
const logger = winston.createLogger({
|
||||
export const logger = winston.createLogger({
|
||||
level: configuration.debug.loggingLevel,
|
||||
format: winston.format.simple(),
|
||||
transports: [new ConsoleForElectron()],
|
||||
});
|
||||
|
||||
export default logger;
|
||||
|
12
src/util/message.ts
Normal file
12
src/util/message.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { logger } from './logger';
|
||||
|
||||
export class Message {
|
||||
public static async ShowInfo(message: string): Promise<{}> {
|
||||
return vscode.window.showInformationMessage('Vim: ' + message) as {};
|
||||
}
|
||||
|
||||
public static async ShowError(message: string): Promise<{}> {
|
||||
return vscode.window.showErrorMessage('Vim: ' + message) as {};
|
||||
}
|
||||
}
|
@ -1,33 +1,8 @@
|
||||
import * as _ from 'lodash';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { Position } from './common/motion/position';
|
||||
import { Range } from './common/motion/range';
|
||||
import logger from './util/logger';
|
||||
|
||||
export async function showInfo(message: string): Promise<{}> {
|
||||
return vscode.window.showInformationMessage('Vim: ' + message) as {};
|
||||
}
|
||||
|
||||
export async function showError(message: string): Promise<{}> {
|
||||
return vscode.window.showErrorMessage('Vim: ' + message) as {};
|
||||
}
|
||||
|
||||
import * as clipboardy from 'clipboardy';
|
||||
|
||||
export class Clipboard {
|
||||
public static Copy(text: string) {
|
||||
try {
|
||||
clipboardy.writeSync(text);
|
||||
} catch (e) {
|
||||
logger.error(e, `Clipboard: Error copying to clipboard. Error=${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static Paste(): string {
|
||||
return clipboardy.readSync();
|
||||
}
|
||||
}
|
||||
import { Position } from '../common/motion/position';
|
||||
import { Range } from '../common/motion/range';
|
||||
import { logger } from './logger';
|
||||
|
||||
/**
|
||||
* This is certainly quite janky! The problem we're trying to solve
|
||||
@ -63,6 +38,7 @@ export async function waitForTabChange(): Promise<void> {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function allowVSCodeToPropagateCursorUpdatesAndReturnThem(
|
||||
timeout: number
|
||||
): Promise<Range[]> {
|
||||
@ -85,7 +61,7 @@ export async function getExternalExtensionDirPath(): Promise<string> {
|
||||
if (!err || err.code === 'EEXIST') {
|
||||
resolve(extensionFolder);
|
||||
} else {
|
||||
logger.error(err.message);
|
||||
logger.debug(err.message);
|
||||
reject(err);
|
||||
}
|
||||
});
|
@ -3,8 +3,6 @@ import * as assert from 'assert';
|
||||
import * as vscode from 'vscode';
|
||||
import { getAndUpdateModeHandler } from '../extension';
|
||||
import { ModeHandler } from '../src/mode/modeHandler';
|
||||
import { TextEditor } from '../src/textEditor';
|
||||
import * as util from '../src/util';
|
||||
import { getTestingFunctions } from './testSimplifier';
|
||||
import {
|
||||
assertEqual,
|
||||
|
@ -5,7 +5,7 @@ import { getAndUpdateModeHandler } from '../../extension';
|
||||
import { ModeHandler } from '../../src/mode/modeHandler';
|
||||
import { IRegisterContent, Register } from '../../src/register/register';
|
||||
import { VimState } from '../../src/state/vimState';
|
||||
import { Clipboard } from '../../src/util';
|
||||
import { Clipboard } from '../../src/util/clipboard';
|
||||
import { getTestingFunctions } from '../testSimplifier';
|
||||
import { assertEqual, assertEqualLines, cleanUpWorkspace, setupWorkspace } from '../testUtils';
|
||||
|
||||
|
@ -7,7 +7,7 @@ import { Globals } from '../src/globals';
|
||||
import { ModeName } from '../src/mode/mode';
|
||||
import { ModeHandler } from '../src/mode/modeHandler';
|
||||
import { TextEditor } from '../src/textEditor';
|
||||
import { waitForCursorUpdatesToHappen } from '../src/util';
|
||||
import { waitForCursorUpdatesToHappen } from '../src/util/util';
|
||||
import { assertEqualLines } from './testUtils';
|
||||
|
||||
export function getTestingFunctions() {
|
||||
|
Loading…
Reference in New Issue
Block a user