mirror of
https://github.com/VSCodeVim/Vim.git
synced 2024-09-11 12:25:59 +03:00
Simplify Logger
by removing concept of scope
I may re-introduce this at some point, but for now, it's not worth the clutter.
This commit is contained in:
parent
2508ed8f11
commit
baa82a2d7b
@ -75,17 +75,16 @@ export async function getAndUpdateModeHandler(
|
||||
async function loadConfiguration() {
|
||||
const validatorResults = await configuration.load();
|
||||
|
||||
const logger = Logger.get('Configuration');
|
||||
logger.debug(`${validatorResults.numErrors} errors found with vim configuration`);
|
||||
Logger.debug(`${validatorResults.numErrors} errors found with vim configuration`);
|
||||
|
||||
if (validatorResults.numErrors > 0) {
|
||||
for (const validatorResult of validatorResults.get()) {
|
||||
switch (validatorResult.level) {
|
||||
case 'error':
|
||||
logger.error(validatorResult.message);
|
||||
Logger.error(validatorResult.message);
|
||||
break;
|
||||
case 'warning':
|
||||
logger.warn(validatorResult.message);
|
||||
Logger.warn(validatorResult.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -98,11 +97,12 @@ async function loadConfiguration() {
|
||||
export async function activate(context: vscode.ExtensionContext, handleLocal: boolean = true) {
|
||||
ExCommandLine.parser = exCommandParser;
|
||||
|
||||
Logger.init();
|
||||
|
||||
// before we do anything else, we need to load the configuration
|
||||
await loadConfiguration();
|
||||
|
||||
const logger = Logger.get('Extension Startup');
|
||||
logger.debug('Start');
|
||||
Logger.debug('Start');
|
||||
|
||||
extensionContext = context;
|
||||
extensionContext.subscriptions.push(StatusBar);
|
||||
@ -290,19 +290,19 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
|
||||
const idx = mh.selectionsChanged.ourSelections.indexOf(selectionsHash);
|
||||
if (idx > -1) {
|
||||
mh.selectionsChanged.ourSelections.splice(idx, 1);
|
||||
logger.debug(
|
||||
Logger.debug(
|
||||
`Selections: Ignoring selection: ${selectionsHash}, Count left: ${mh.selectionsChanged.ourSelections.length}`
|
||||
);
|
||||
return;
|
||||
} else if (mh.selectionsChanged.ignoreIntermediateSelections) {
|
||||
logger.debug(`Selections: ignoring intermediate selection change: ${selectionsHash}`);
|
||||
Logger.debug(`Selections: ignoring intermediate selection change: ${selectionsHash}`);
|
||||
return;
|
||||
} else if (mh.selectionsChanged.ourSelections.length > 0) {
|
||||
// Some intermediate selection must have slipped in after setting the
|
||||
// 'ignoreIntermediateSelections' to false. Which means we didn't count
|
||||
// for it yet, but since we have selections to be ignored then we probably
|
||||
// wanted this one to be ignored as well.
|
||||
logger.warn(`Selections: Ignoring slipped selection: ${selectionsHash}`);
|
||||
Logger.warn(`Selections: Ignoring slipped selection: ${selectionsHash}`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -529,7 +529,7 @@ export async function activate(context: vscode.ExtensionContext, handleLocal: bo
|
||||
|
||||
await toggleExtension(configuration.disableExtension, compositionState);
|
||||
|
||||
logger.debug('Finish.');
|
||||
Logger.debug('Finish.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,6 @@ function executeShell(cmd: string): Promise<string> {
|
||||
* InputMethodSwitcher changes input method when mode changed
|
||||
*/
|
||||
export class InputMethodSwitcher {
|
||||
private static readonly logger = Logger.get('IMSwitcher');
|
||||
private execute: (cmd: string) => Promise<string>;
|
||||
private savedIMKey = '';
|
||||
|
||||
@ -59,7 +58,7 @@ export class InputMethodSwitcher {
|
||||
this.savedIMKey = insertIMKey.trim();
|
||||
}
|
||||
} catch (e) {
|
||||
InputMethodSwitcher.logger.error(`Error switching to default IM. err=${e}`);
|
||||
Logger.error(`Error switching to default IM. err=${e}`);
|
||||
}
|
||||
|
||||
const defaultIMKey = configuration.autoSwitchInputMethod.defaultIM;
|
||||
@ -82,7 +81,7 @@ export class InputMethodSwitcher {
|
||||
try {
|
||||
await this.execute(switchIMCmd);
|
||||
} catch (e) {
|
||||
InputMethodSwitcher.logger.error(`Error switching to IM. err=${e}`);
|
||||
Logger.error(`Error switching to IM. err=${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ function LastNextObject<T extends MoveInsideCharacter>(type: new () => T, which:
|
||||
constructor() {
|
||||
super();
|
||||
this.actual = new type();
|
||||
const logger = Logger.get(`${this.secondKey} Handler for ${type.name}`);
|
||||
|
||||
const secondKey = this.secondKey;
|
||||
const withWhichKey = (keys: string[]): string[] | undefined => {
|
||||
@ -49,7 +48,7 @@ function LastNextObject<T extends MoveInsideCharacter>(type: new () => T, which:
|
||||
if (this.actual.keys.length < 1) {
|
||||
this.valid = false;
|
||||
this.keys = [];
|
||||
logger.error(errMsg);
|
||||
Logger.error(errMsg);
|
||||
return;
|
||||
}
|
||||
if (typeof this.actual.keys[0] === 'string') {
|
||||
@ -58,7 +57,7 @@ function LastNextObject<T extends MoveInsideCharacter>(type: new () => T, which:
|
||||
if (keys === undefined) {
|
||||
this.valid = false;
|
||||
this.keys = [];
|
||||
logger.error(errMsg);
|
||||
Logger.error(errMsg);
|
||||
return;
|
||||
} else {
|
||||
this.keys = keys;
|
||||
@ -69,7 +68,7 @@ function LastNextObject<T extends MoveInsideCharacter>(type: new () => T, which:
|
||||
if (!keys.every((p) => p !== undefined)) {
|
||||
this.valid = false;
|
||||
this.keys = [];
|
||||
logger.error(errMsg);
|
||||
Logger.error(errMsg);
|
||||
return;
|
||||
} else {
|
||||
this.keys = keys as string[][];
|
||||
|
@ -207,8 +207,6 @@ export class ExCommandLine extends CommandLine {
|
||||
private lineRange: LineRange | undefined;
|
||||
private command: ExCommand | undefined;
|
||||
|
||||
private static readonly logger = Logger.get('CommandLine');
|
||||
|
||||
constructor(commandText: string, previousMode: Mode) {
|
||||
super(commandText, previousMode);
|
||||
this.commandText = commandText;
|
||||
@ -299,7 +297,7 @@ export class ExCommandLine extends CommandLine {
|
||||
StatusBar.setText(vimState, e.toString(), true);
|
||||
}
|
||||
} else {
|
||||
ExCommandLine.logger.error(`Error executing cmd=${this.text}. err=${e}.`);
|
||||
Logger.error(`Error executing cmd=${this.text}. err=${e}.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,6 @@ export class FileCommand extends ExCommand {
|
||||
};
|
||||
|
||||
private readonly arguments: IFileCommandArguments;
|
||||
private readonly logger = Logger.get('File');
|
||||
|
||||
constructor(args: IFileCommandArguments) {
|
||||
super();
|
||||
@ -214,7 +213,7 @@ export class FileCommand extends ExCommand {
|
||||
// untitled tab
|
||||
fileUri = uriPath.with({ scheme: 'untitled' });
|
||||
} else {
|
||||
this.logger.error(`${args.file} does not exist.`);
|
||||
Logger.error(`${args.file} does not exist.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ export class WriteCommand extends ExCommand {
|
||||
public override isRepeatableWithDot = false;
|
||||
|
||||
public readonly arguments: IWriteCommandArguments;
|
||||
private readonly logger = Logger.get('Write');
|
||||
|
||||
constructor(args: IWriteCommandArguments) {
|
||||
super();
|
||||
@ -88,7 +87,7 @@ export class WriteCommand extends ExCommand {
|
||||
}C written`
|
||||
);
|
||||
} else {
|
||||
this.logger.warn(':w failed');
|
||||
Logger.warn(':w failed');
|
||||
// TODO: What's the right thing to do here?
|
||||
}
|
||||
})
|
||||
|
@ -47,7 +47,6 @@ export class Remappers implements IRemapper {
|
||||
export class Remapper implements IRemapper {
|
||||
private readonly configKey: string;
|
||||
private readonly remappedModes: Mode[];
|
||||
private readonly logger = Logger.get('Remapper');
|
||||
|
||||
/**
|
||||
* Checks if the current commandList is a potential remap.
|
||||
@ -122,7 +121,7 @@ export class Remapper implements IRemapper {
|
||||
return true;
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`trying to find matching remap. keys=${keys}. mode=${
|
||||
Mode[vimState.currentMode]
|
||||
}. keybindings=${this.configKey}.`
|
||||
@ -210,11 +209,11 @@ export class Remapper implements IRemapper {
|
||||
|
||||
keys.push(SpecialKeys.TimeoutFinished); // include the '<TimeoutFinished>' key
|
||||
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. timeout finished, handling timed out buffer keys without allowing a new timeout.`
|
||||
);
|
||||
}
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. potential remap broken. resending keys without allowing a potential remap on first key. keys=${keys}`
|
||||
);
|
||||
this.hasPotentialRemap = false;
|
||||
@ -233,7 +232,7 @@ export class Remapper implements IRemapper {
|
||||
await modeHandler.handleMultipleKeyEvents(keys);
|
||||
} catch (e) {
|
||||
if (e instanceof ForceStopRemappingError) {
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. Stopped the remapping in the middle, ignoring the rest. Reason: ${e.message}`
|
||||
);
|
||||
}
|
||||
@ -269,12 +268,12 @@ export class Remapper implements IRemapper {
|
||||
// it again.
|
||||
this.hasAmbiguousRemap = remapping;
|
||||
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. ambiguous match found. before=${remapping.before}. after=${remapping.after}. command=${remapping.commands}. waiting for other key or timeout to finish.`
|
||||
);
|
||||
} else {
|
||||
this.hasPotentialRemap = true;
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. potential remap found. waiting for other key or timeout to finish.`
|
||||
);
|
||||
}
|
||||
@ -336,7 +335,7 @@ export class Remapper implements IRemapper {
|
||||
// Increase mapDepth
|
||||
remapState.mapDepth++;
|
||||
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. match found. before=${remapping.before}. after=${remapping.after}. command=${remapping.commands}. remainingKeys=${remainingKeys}. mapDepth=${remapState.mapDepth}.`
|
||||
);
|
||||
|
||||
@ -380,12 +379,12 @@ export class Remapper implements IRemapper {
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. Stopped the remapping in the middle, ignoring the rest. Reason: ${e.message}`
|
||||
);
|
||||
} else {
|
||||
// If some other error happens during the remapping handling it should stop the remap and rethrow
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. error found in the middle of remapping, ignoring the rest of the remap. error: ${e}`
|
||||
);
|
||||
throw e;
|
||||
@ -443,7 +442,7 @@ export class Remapper implements IRemapper {
|
||||
remapState.isCurrentlyPerformingRecursiveRemapping = true;
|
||||
await modeHandler.handleMultipleKeyEvents(remainingKeys);
|
||||
} catch (e) {
|
||||
this.logger.debug(
|
||||
Logger.debug(
|
||||
`${this.configKey}. Stopped the remapping in the middle, ignoring the rest. Reason: ${e.message}`
|
||||
);
|
||||
} finally {
|
||||
@ -545,13 +544,11 @@ export class Remapper implements IRemapper {
|
||||
for (let sliceLength = startingSliceLength; sliceLength >= range[0]; sliceLength--) {
|
||||
const keySlice = inputtedKeys.slice(-sliceLength).join('');
|
||||
|
||||
this.logger.debug(`key=${inputtedKeys}. keySlice=${keySlice}.`);
|
||||
Logger.debug(`key=${inputtedKeys}. keySlice=${keySlice}.`);
|
||||
if (userDefinedRemappings.has(keySlice)) {
|
||||
const precedingKeys = inputtedString.slice(0, inputtedString.length - keySlice.length);
|
||||
if (precedingKeys.length > 0 && !/^[0-9]+$/.test(precedingKeys)) {
|
||||
this.logger.debug(
|
||||
`key sequences need to match precisely. precedingKeys=${precedingKeys}.`
|
||||
);
|
||||
Logger.debug(`key sequences need to match precisely. precedingKeys=${precedingKeys}.`);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,6 @@ import { Logger } from '../util/logger';
|
||||
|
||||
export class VimrcImpl {
|
||||
private _vimrcPath?: string;
|
||||
private static readonly logger = Logger.get('VimRC');
|
||||
|
||||
/**
|
||||
* Fully resolved path to the user's .vimrc
|
||||
@ -45,10 +44,10 @@ export class VimrcImpl {
|
||||
const source = this.buildSource(line);
|
||||
if (source) {
|
||||
if (!(await fs.existsAsync(source))) {
|
||||
VimrcImpl.logger.warn(`Unable to find "${source}" file for configuration.`);
|
||||
Logger.warn(`Unable to find "${source}" file for configuration.`);
|
||||
continue;
|
||||
}
|
||||
VimrcImpl.logger.debug(`Loading "${source}" file for configuration.`);
|
||||
Logger.debug(`Loading "${source}" file for configuration.`);
|
||||
await VimrcImpl.loadConfig(config, source);
|
||||
continue;
|
||||
}
|
||||
@ -228,9 +227,7 @@ export class VimrcImpl {
|
||||
config.commandLineModeKeyBindingsNonRecursive,
|
||||
];
|
||||
default:
|
||||
VimrcImpl.logger.warn(
|
||||
`Encountered an unrecognized mapping type: '${remap.keyRemappingType}'`
|
||||
);
|
||||
Logger.warn(`Encountered an unrecognized mapping type: '${remap.keyRemappingType}'`);
|
||||
return undefined;
|
||||
}
|
||||
})();
|
||||
@ -312,9 +309,7 @@ export class VimrcImpl {
|
||||
config.commandLineModeKeyBindingsNonRecursive,
|
||||
];
|
||||
default:
|
||||
VimrcImpl.logger.warn(
|
||||
`Encountered an unrecognized unmapping type: '${remap.keyRemappingType}'`
|
||||
);
|
||||
Logger.warn(`Encountered an unrecognized unmapping type: '${remap.keyRemappingType}'`);
|
||||
return undefined;
|
||||
}
|
||||
})();
|
||||
@ -406,9 +401,7 @@ export class VimrcImpl {
|
||||
config.commandLineModeKeyBindingsNonRecursive,
|
||||
];
|
||||
default:
|
||||
VimrcImpl.logger.warn(
|
||||
`Encountered an unrecognized clearMapping type: '${remap.keyRemappingType}'`
|
||||
);
|
||||
Logger.warn(`Encountered an unrecognized clearMapping type: '${remap.keyRemappingType}'`);
|
||||
return undefined;
|
||||
}
|
||||
})();
|
||||
|
@ -1,12 +1,10 @@
|
||||
import { ExtensionContext } from 'vscode';
|
||||
import { Logger } from '../util/logger';
|
||||
import { configuration } from '../configuration/configuration';
|
||||
import { Globals } from '../globals';
|
||||
import { HistoryBase } from 'platform/history';
|
||||
|
||||
// TODO(jfields): What's going on here? Just combine HistoryFile and HistoryBase...
|
||||
export class HistoryFile {
|
||||
private readonly logger = Logger.get('HistoryFile');
|
||||
private base: HistoryBase;
|
||||
|
||||
get historyFilePath(): string {
|
||||
@ -14,12 +12,7 @@ export class HistoryFile {
|
||||
}
|
||||
|
||||
constructor(context: ExtensionContext, historyFileName: string) {
|
||||
this.base = new HistoryBase(
|
||||
context,
|
||||
historyFileName,
|
||||
Globals.extensionStoragePath,
|
||||
this.logger
|
||||
);
|
||||
this.base = new HistoryBase(context, historyFileName, Globals.extensionStoragePath);
|
||||
}
|
||||
|
||||
public async add(value: string | undefined): Promise<void> {
|
||||
|
@ -26,8 +26,6 @@ import { earlierOf } from '../common/motion/position';
|
||||
const diffEngine = new DiffMatchPatch.diff_match_patch();
|
||||
diffEngine.Diff_Timeout = 1; // 1 second
|
||||
|
||||
const logger = Logger.get('HistoryTracker');
|
||||
|
||||
class DocumentChange {
|
||||
/**
|
||||
* The Position at which this change starts
|
||||
@ -652,7 +650,7 @@ export class HistoryTracker {
|
||||
if (this.nextStepStartPosition === undefined) {
|
||||
const cursor = this.vimState.cursorsInitialState[0];
|
||||
this.nextStepStartPosition = earlierOf(cursor.start, cursor.stop);
|
||||
logger.debug(`Set nextStepStartPosition to ${this.nextStepStartPosition}`);
|
||||
Logger.debug(`Set nextStepStartPosition to ${this.nextStepStartPosition}`);
|
||||
}
|
||||
|
||||
if (
|
||||
@ -743,7 +741,7 @@ export class HistoryTracker {
|
||||
this.changeList.addChangePosition(changePos);
|
||||
}
|
||||
|
||||
logger.debug(`Finished history step with ${changes.length} change(s)`);
|
||||
Logger.debug(`Finished history step with ${changes.length} change(s)`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,6 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
private readonly disposables: vscode.Disposable[] = [];
|
||||
private readonly handlerMap: IModeHandlerMap;
|
||||
private readonly remappers: Remappers;
|
||||
private static readonly logger = Logger.get('ModeHandler');
|
||||
|
||||
/**
|
||||
* Used internally to ignore selection changes that were performed by us.
|
||||
@ -184,7 +183,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
return;
|
||||
}
|
||||
const selection = e.selections[0];
|
||||
ModeHandler.logger.debug(
|
||||
Logger.debug(
|
||||
`Selections: Handling Selection Change! Selection: ${selection.anchor.toString()}, ${
|
||||
selection.active
|
||||
}, SelectionsLength: ${e.selections.length}`
|
||||
@ -247,13 +246,13 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
// a command, so we need to update our start and stop positions. This is where commands
|
||||
// like 'editor.action.smartSelect.grow' are handled.
|
||||
if (this.vimState.currentMode === Mode.Visual) {
|
||||
ModeHandler.logger.debug('Selections: Updating Visual Selection!');
|
||||
Logger.debug('Selections: Updating Visual Selection!');
|
||||
this.vimState.cursorStopPosition = selection.active;
|
||||
this.vimState.cursorStartPosition = selection.anchor;
|
||||
await this.updateView({ drawSelection: false, revealRange: false });
|
||||
return;
|
||||
} else if (!selection.active.isEqual(selection.anchor)) {
|
||||
ModeHandler.logger.debug('Selections: Creating Visual Selection from command!');
|
||||
Logger.debug('Selections: Creating Visual Selection from command!');
|
||||
this.vimState.cursorStopPosition = selection.active;
|
||||
this.vimState.cursorStartPosition = selection.anchor;
|
||||
await this.setCurrentMode(Mode.Visual);
|
||||
@ -306,7 +305,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
// We still need to be careful with this because this here might be changing our cursors
|
||||
// in ways we don't want to. So with future selection issues this is a good place to start
|
||||
// looking.
|
||||
ModeHandler.logger.debug(
|
||||
Logger.debug(
|
||||
`Selections: Changing Cursors from selection handler... ${selection.anchor.toString()}, ${
|
||||
selection.active
|
||||
}`
|
||||
@ -409,7 +408,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
ModeHandler.logger.debug(`handling key=${printableKey}.`);
|
||||
Logger.debug(`handling key=${printableKey}.`);
|
||||
|
||||
if (
|
||||
(key === SpecialKeys.TimeoutFinished ||
|
||||
@ -550,7 +549,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
// with the next remapper check.
|
||||
this.vimState.recordedState.resetCommandList();
|
||||
|
||||
ModeHandler.logger.debug(`handleKeyEvent('${printableKey}') took ${Date.now() - now}ms`);
|
||||
Logger.debug(`handleKeyEvent('${printableKey}') took ${Date.now() - now}ms`);
|
||||
|
||||
// If we are handling a remap and the last movement failed stop handling the remap
|
||||
// and discard the rest of the keys. We throw an Exception here to stop any other
|
||||
@ -590,7 +589,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
|
||||
private async handleKeyAsAnAction(key: string): Promise<boolean> {
|
||||
if (vscode.window.activeTextEditor !== this.vimState.editor) {
|
||||
ModeHandler.logger.warn('Current window is not active');
|
||||
Logger.warn('Current window is not active');
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1371,7 +1370,7 @@ export class ModeHandler implements vscode.Disposable, IModeHandler {
|
||||
''
|
||||
);
|
||||
this.selectionsChanged.ourSelections.push(selectionsHash);
|
||||
ModeHandler.logger.debug(
|
||||
Logger.debug(
|
||||
`Selections: Adding Selection Change to be Ignored! (total: ${
|
||||
this.selectionsChanged.ourSelections.length
|
||||
}) Hash: ${selectionsHash}, Selections: ${selections[0].anchor.toString()}, ${selections[0].active.toString()}`
|
||||
|
@ -17,7 +17,6 @@ import { TextDocument } from 'vscode';
|
||||
export class NeovimWrapper implements vscode.Disposable {
|
||||
private process?: ChildProcess;
|
||||
private nvim?: Neovim;
|
||||
private static readonly logger = Logger.get('Neovim');
|
||||
private readonly processTimeoutInSeconds = 3;
|
||||
|
||||
async run(
|
||||
@ -48,7 +47,7 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
|
||||
const apiInfo = await this.nvim.apiInfo;
|
||||
const version = apiInfo[1].version;
|
||||
NeovimWrapper.logger.debug(`version: ${version.major}.${version.minor}.${version.patch}`);
|
||||
Logger.debug(`version: ${version.major}.${version.minor}.${version.patch}`);
|
||||
}
|
||||
|
||||
await this.syncVSCodeToVim(vimState);
|
||||
@ -59,7 +58,7 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
await this.nvim.command('let v:errmsg="" | let v:statusmsg=""');
|
||||
|
||||
// Execute the command
|
||||
NeovimWrapper.logger.debug(`Running ${command}.`);
|
||||
Logger.debug(`Running ${command}.`);
|
||||
await this.nvim.input(command);
|
||||
const mode = await this.nvim.mode;
|
||||
if (mode.blocking) {
|
||||
@ -88,7 +87,7 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
}
|
||||
|
||||
private async startNeovim(document: TextDocument) {
|
||||
NeovimWrapper.logger.debug('Spawning Neovim process...');
|
||||
Logger.debug('Spawning Neovim process...');
|
||||
let dir = dirname(document.uri.fsPath);
|
||||
if (!(await util.promisify(exists)(dir))) {
|
||||
dir = __dirname;
|
||||
@ -111,7 +110,7 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
});
|
||||
|
||||
this.process.on('error', (err) => {
|
||||
NeovimWrapper.logger.error(`Error spawning neovim. ${err.message}.`);
|
||||
Logger.error(`Error spawning neovim. ${err.message}.`);
|
||||
configuration.enableNeovim = false;
|
||||
});
|
||||
|
||||
@ -193,7 +192,7 @@ export class NeovimWrapper implements vscode.Disposable {
|
||||
fixedLines.join('\n')
|
||||
);
|
||||
|
||||
NeovimWrapper.logger.debug(`${lines.length} lines in nvim. ${lineCount} in editor.`);
|
||||
Logger.debug(`${lines.length} lines in nvim. ${lineCount} in editor.`);
|
||||
|
||||
const [row, character] = ((await this.nvim.callFunction('getpos', ['.'])) as number[]).slice(
|
||||
1,
|
||||
|
@ -6,7 +6,6 @@ import { Logger } from '../../util/logger';
|
||||
|
||||
export class HistoryBase {
|
||||
private readonly extensionStoragePath: string;
|
||||
private readonly logger: Logger;
|
||||
private readonly historyFileName: string;
|
||||
private history: string[] = [];
|
||||
|
||||
@ -17,12 +16,10 @@ export class HistoryBase {
|
||||
constructor(
|
||||
context: vscode.ExtensionContext,
|
||||
historyFileName: string,
|
||||
extensionStoragePath: string,
|
||||
logger: Logger
|
||||
extensionStoragePath: string
|
||||
) {
|
||||
this.historyFileName = historyFileName;
|
||||
this.extensionStoragePath = extensionStoragePath;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public async add(value: string | undefined, history: number): Promise<void> {
|
||||
@ -61,7 +58,7 @@ export class HistoryBase {
|
||||
this.history = [];
|
||||
unlinkSync(this.historyKey);
|
||||
} catch (err) {
|
||||
this.logger.warn(`Unable to delete ${this.historyKey}. err=${err}.`);
|
||||
Logger.warn(`Unable to delete ${this.historyKey}. err=${err}.`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +70,9 @@ export class HistoryBase {
|
||||
data = await readFileAsync(this.historyKey, 'utf-8');
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
this.logger.debug(`History does not exist. path=${this.historyKey}`);
|
||||
Logger.debug(`History does not exist. path=${this.historyKey}`);
|
||||
} else {
|
||||
this.logger.warn(`Failed to load history. path=${this.historyKey} err=${err}.`);
|
||||
Logger.warn(`Failed to load history. path=${this.historyKey} err=${err}.`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -91,7 +88,7 @@ export class HistoryBase {
|
||||
}
|
||||
this.history = parsedData;
|
||||
} catch (e) {
|
||||
this.logger.warn(`Deleting corrupted history file. path=${this.historyKey} err=${e}.`);
|
||||
Logger.warn(`Deleting corrupted history file. path=${this.historyKey} err=${e}.`);
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
@ -110,7 +107,7 @@ export class HistoryBase {
|
||||
// create file
|
||||
await writeFileAsync(this.historyKey, JSON.stringify(this.history), 'utf-8');
|
||||
} catch (err) {
|
||||
this.logger.error(`Failed to save history. filepath=${this.historyKey}. err=${err}.`);
|
||||
Logger.error(`Failed to save history. filepath=${this.historyKey}. err=${err}.`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,6 @@ interface INVim {
|
||||
* Each ModeHandler holds a VimState, so there is one for each open editor.
|
||||
*/
|
||||
export class VimState implements vscode.Disposable {
|
||||
private static readonly logger = Logger.get('VimState');
|
||||
|
||||
/**
|
||||
* The column the cursor wants to be at, or Number.POSITIVE_INFINITY if it should always
|
||||
* be the rightmost column.
|
||||
@ -136,7 +134,7 @@ export class VimState implements vscode.Disposable {
|
||||
}
|
||||
public set cursorStartPosition(value: Position) {
|
||||
if (!value.isValid(this.editor)) {
|
||||
VimState.logger.warn(`invalid cursor start position. ${value.toString()}.`);
|
||||
Logger.warn(`invalid cursor start position. ${value.toString()}.`);
|
||||
}
|
||||
this.cursors[0] = this.cursors[0].withNewStart(value);
|
||||
}
|
||||
@ -146,7 +144,7 @@ export class VimState implements vscode.Disposable {
|
||||
}
|
||||
public set cursorStopPosition(value: Position) {
|
||||
if (!value.isValid(this.editor)) {
|
||||
VimState.logger.warn(`invalid cursor stop position. ${value.toString()}.`);
|
||||
Logger.warn(`invalid cursor stop position. ${value.toString()}.`);
|
||||
}
|
||||
this.cursors[0] = this.cursors[0].withNewStop(value);
|
||||
}
|
||||
@ -161,14 +159,14 @@ export class VimState implements vscode.Disposable {
|
||||
}
|
||||
public set cursors(value: Cursor[]) {
|
||||
if (value.length === 0) {
|
||||
VimState.logger.warn('Tried to set VimState.cursors to an empty array');
|
||||
Logger.warn('Tried to set VimState.cursors to an empty array');
|
||||
return;
|
||||
}
|
||||
|
||||
const map = new Map<string, Cursor>();
|
||||
for (const cursor of value) {
|
||||
if (!cursor.isValid(this.editor)) {
|
||||
VimState.logger.warn(`invalid cursor position. ${cursor.toString()}.`);
|
||||
Logger.warn(`invalid cursor position. ${cursor.toString()}.`);
|
||||
}
|
||||
|
||||
// use a map to ensure no two cursors are at the same location.
|
||||
|
@ -4,7 +4,6 @@ import { Logger } from './util/logger';
|
||||
import { extensionVersion } from './configuration/configuration';
|
||||
|
||||
class TaskQueue {
|
||||
private readonly logger = Logger.get('TaskQueue');
|
||||
private readonly taskQueue = new Queue({ autostart: true, concurrency: 1 });
|
||||
|
||||
constructor() {
|
||||
@ -43,7 +42,7 @@ class TaskQueue {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.logger.error(`Error running task due to an unknown error: ${err}.`);
|
||||
Logger.error(`Error running task due to an unknown error: ${err}.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import { clamp } from './util/util';
|
||||
*/
|
||||
export class TextEditor {
|
||||
private static readonly whitespaceRegExp = new RegExp('\\s+');
|
||||
private static readonly logger = Logger.get('TextEditor');
|
||||
|
||||
/**
|
||||
* @deprecated Use InsertTextTransformation (or InsertTextVSCodeTransformation) instead.
|
||||
@ -62,7 +61,7 @@ export class TextEditor {
|
||||
|
||||
public static getLineLength(line: number): number {
|
||||
if (line < 0 || line >= TextEditor.getLineCount()) {
|
||||
this.logger.warn(`getLineLength() called with out-of-bounds line ${line}`);
|
||||
Logger.warn(`getLineLength() called with out-of-bounds line ${line}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,6 @@ export interface IModeHandler {
|
||||
rerunRecordedState(recordedState: RecordedState): Promise<void>;
|
||||
}
|
||||
|
||||
const logger = Logger.get('Parser');
|
||||
|
||||
export async function executeTransformations(
|
||||
modeHandler: IModeHandler,
|
||||
transformations: Transformation[]
|
||||
@ -69,7 +67,7 @@ export async function executeTransformations(
|
||||
case 'moveCursor':
|
||||
break;
|
||||
default:
|
||||
logger.warn(`Unhandled text transformation type: ${command.type}.`);
|
||||
Logger.warn(`Unhandled text transformation type: ${command.type}.`);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -90,7 +88,7 @@ export async function executeTransformations(
|
||||
const overlapping = overlappingTransformations(textTransformations);
|
||||
if (overlapping !== undefined) {
|
||||
const msg = `Transformations overlapping: ${JSON.stringify(overlapping)}`;
|
||||
logger.warn(msg);
|
||||
Logger.warn(msg);
|
||||
if (Globals.isTesting) {
|
||||
throw new Error(msg);
|
||||
}
|
||||
@ -145,7 +143,7 @@ export async function executeTransformations(
|
||||
// await vscode.commands.executeCommand('default:type', { text });
|
||||
await TextEditor.insert(vimState.editor, text);
|
||||
} else {
|
||||
logger.warn(`Unhandled multicursor transformations. Not all transformations are the same!`);
|
||||
Logger.warn(`Unhandled multicursor transformations. Not all transformations are the same!`);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +242,7 @@ export async function executeTransformations(
|
||||
break;
|
||||
|
||||
default:
|
||||
logger.warn(`Unhandled text transformation type: ${transformation.type}.`);
|
||||
Logger.warn(`Unhandled text transformation type: ${transformation.type}.`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,8 @@ import { stringify, Transformation } from './transformations';
|
||||
export class Transformer {
|
||||
public readonly transformations: Transformation[] = [];
|
||||
|
||||
private logger = Logger.get('Transformer');
|
||||
|
||||
public addTransformation(transformation: Transformation): void {
|
||||
this.logger.debug(`Adding Transformation ${stringify(transformation)}`);
|
||||
Logger.debug(`Adding Transformation ${stringify(transformation)}`);
|
||||
this.transformations.push(transformation);
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,11 @@ import { Logger } from './logger';
|
||||
* A thin wrapper around `vscode.env.clipboard`
|
||||
*/
|
||||
export class Clipboard {
|
||||
private static readonly logger = Logger.get('Clipboard');
|
||||
|
||||
public static async Copy(text: string): Promise<void> {
|
||||
try {
|
||||
await vscode.env.clipboard.writeText(text);
|
||||
} catch (e) {
|
||||
this.logger.error(`Error copying to clipboard. err=${e}`);
|
||||
Logger.error(`Error copying to clipboard. err=${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,42 +1,25 @@
|
||||
import { LogOutputChannel, window } from 'vscode';
|
||||
|
||||
export class Logger {
|
||||
private static output: LogOutputChannel | undefined;
|
||||
private static readonly cache = new Map<string, Logger>();
|
||||
private static output: LogOutputChannel;
|
||||
|
||||
static get(prefix: string): Logger {
|
||||
if (!this.output) {
|
||||
this.output = window.createOutputChannel('Vim', { log: true });
|
||||
}
|
||||
|
||||
let logger = Logger.cache.get(prefix);
|
||||
if (logger === undefined) {
|
||||
logger = new Logger(prefix);
|
||||
Logger.cache.set(prefix, logger);
|
||||
}
|
||||
|
||||
return logger;
|
||||
public static init(): void {
|
||||
Logger.output = window.createOutputChannel('Vim', { log: true });
|
||||
}
|
||||
|
||||
private scope: string;
|
||||
|
||||
private constructor(scope: string) {
|
||||
this.scope = scope;
|
||||
public static error(msg: string): void {
|
||||
Logger.output.error(msg);
|
||||
}
|
||||
|
||||
error(msg: string): void {
|
||||
Logger.output?.error(`[${this.scope}] ${msg}`);
|
||||
public static warn(msg: string): void {
|
||||
Logger.output.warn(msg);
|
||||
}
|
||||
warn(msg: string): void {
|
||||
Logger.output?.warn(`[${this.scope}] ${msg}`);
|
||||
public static info(msg: string): void {
|
||||
Logger.output.info(msg);
|
||||
}
|
||||
info(msg: string): void {
|
||||
Logger.output?.info(`[${this.scope}] ${msg}`);
|
||||
public static debug(msg: string): void {
|
||||
Logger.output.debug(msg);
|
||||
}
|
||||
debug(msg: string): void {
|
||||
Logger.output?.debug(`[${this.scope}] ${msg}`);
|
||||
}
|
||||
trace(msg: string): void {
|
||||
Logger.output?.trace(`[${this.scope}] ${msg}`);
|
||||
public static trace(msg: string): void {
|
||||
Logger.output.trace(msg);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export abstract class VSCodeContext {
|
||||
public static async set(key: string, value: ContextValue): Promise<void> {
|
||||
const prev = this.get(key);
|
||||
if (prev !== value) {
|
||||
Logger.get('vscode-context').debug(`Setting key='${key}' to value='${value}'`);
|
||||
Logger.debug(`Setting key='${key}' to value='${value}'`);
|
||||
this.cache.set(key, value);
|
||||
await vscode.commands.executeCommand('setContext', key, value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user