Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Cleanup #2138

Merged
merged 18 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install:

script:
- git ls-tree -r HEAD --name-only | grep ".*.[t|j]s$" | xargs ./node_modules/prettier/bin/prettier.js --write --print-width 100 --single-quote --trailing-comma es5
- if [[ $(git diff-index HEAD --) ]]; then { ./node_modules/prettier/bin/prettier.js -v; git diff; echo "Compile with gulp first (to format things properly with prettier) before pushing!"; sleep 1; exit 1; }; else echo "Prettier passed."; fi
- if [[ $(git diff-index HEAD --) ]]; then { ./node_modules/prettier/bin/prettier.js -v; git diff; echo "Prettier Failed. Run `gulp` or `gulp forceprettier`"; exit 1; }; else echo "Prettier passed."; fi
- gulp
- npm test --silent;

Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/{out, node_modules}/**/*.js" ],
"preLaunchTask": "build",
"preLaunchTask": "gulp: default",
"internalConsoleOptions": "openOnSessionStart"
}
]
Expand Down
161 changes: 72 additions & 89 deletions README.md

Large diffs are not rendered by default.

50 changes: 2 additions & 48 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import * as vscode from 'vscode';
import * as _ from 'lodash';
import { showCmdLine } from './src/cmd_line/main';
import { EditorIdentity } from './src/editorIdentity';
import { ModeHandler } from './src/mode/modeHandler';
import { taskQueue } from './src/taskQueue';
import { Position } from './src/common/motion/position';
Expand Down Expand Up @@ -36,36 +37,6 @@ const packagejson: {
};
} = require('../package.json'); // out/../package.json

export class EditorIdentity {
private _fileName: string;
private _viewColumn: vscode.ViewColumn;

constructor(textEditor?: vscode.TextEditor) {
this._fileName = (textEditor && textEditor.document.fileName) || '';
this._viewColumn = (textEditor && textEditor.viewColumn) || vscode.ViewColumn.One;
}

get fileName() {
return this._fileName;
}

get viewColumn() {
return this._viewColumn;
}

public hasSameBuffer(identity: EditorIdentity): boolean {
return this.fileName === identity.fileName;
}

public isEqual(identity: EditorIdentity): boolean {
return this.fileName === identity.fileName && this.viewColumn === identity.viewColumn;
}

public toString() {
return this.fileName + this.viewColumn;
}
}

let extensionContext: vscode.ExtensionContext;

/**
Expand All @@ -81,22 +52,6 @@ export async function getAndUpdateModeHandler(): Promise<ModeHandler> {

let curHandler = modeHandlerToEditorIdentity[activeEditorId.toString()];
if (!curHandler) {
if (!Configuration.disableAnnoyingNeovimMessage) {
vscode.window
.showInformationMessage(
'We have now added neovim integration for Ex-commands.\
Enable it with vim.enableNeovim in settings',
'Never show again'
)
.then(result => {
if (result !== 'Close') {
vscode.workspace
.getConfiguration('vim')
.update('disableAnnoyingNeovimMessage', true, true);
Configuration.disableAnnoyingNeovimMessage = true;
}
});
}
const newModeHandler = await new ModeHandler();
if (Configuration.enableNeovim) {
await Neovim.initNvim(newModeHandler.vimState);
Expand Down Expand Up @@ -319,10 +274,9 @@ export async function activate(context: vscode.ExtensionContext) {
async function toggleExtension(isDisabled: boolean) {
await vscode.commands.executeCommand('setContext', 'vim.active', !isDisabled);
if (isDisabled) {
let cursorStyle = await vscode.workspace.getConfiguration().get('editor.cursorStyle', 'line');
vscode.window.visibleTextEditors.forEach(editor => {
let options = editor.options;
switch (cursorStyle) {
switch (Configuration.userCursorString) {
case 'line':
options.cursorStyle = vscode.TextEditorCursorStyle.Line;
break;
Expand Down
8 changes: 5 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ gulp.task('prettier', function() {
});

gulp.task('forceprettier', function() {
// Enumerate files managed by git
// files managed by git
runPrettier('git ls-files');
// Enumerate untracked files
// untracked files
runPrettier('git ls-files --others --exclude-standard');
});

Expand All @@ -65,7 +65,9 @@ function runPrettier(command) {
for (const file of files) {
if (file.endsWith('.ts') || file.endsWith('.js')) {
exec(
`node ./node_modules/prettier/bin/prettier.js --write --print-width 100 --single-quote --trailing-comma es5 ${file}`
`node ./node_modules/prettier/bin/prettier.js --write --print-width 100 --single-quote --trailing-comma es5 ${
file
}`
);
}
}
Expand Down
27 changes: 14 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"activationEvents": [
"*"
],
"qna": "https://vscodevim-slackin.azurewebsites.net/",
"main": "./out/extension",
"contributes": {
"commands": [
Expand Down Expand Up @@ -543,11 +544,6 @@
"description": "Path to run neovim executable. For example, /usr/bin/nvim, or C:\\Program Files\\Neovim\\bin\\nvim.exe",
"default": "nvim"
},
"vim.disableAnnoyingNeovimMessage": {
"type": "boolean",
"description": "Get rid of that annoying message that shows up everytime you make a new file",
"default": false
},
"vim.substituteGlobalFlag": {
"type": "boolean",
"description": "Automatically apply the global flag, /g, to substitute commands. When set to true, use /g to mean only first match should be replaced.",
Expand All @@ -572,16 +568,15 @@
"postinstall": "node ./node_modules/vscode/bin/install && gulp init"
},
"dependencies": {
"clipboardy": "^1.1.4",
"clipboardy": "^1.2.1",
"diff-match-patch": "^1.0.0",
"lodash": "^4.17.4",
"neovim-client": "^2.1.0",
"prettier": "^1.7.4",
"promised-neovim-client": "^2.0.2",
"untildify": "^3.0.2"
},
"devDependencies": {
"@types/mocha": "^2.2.43",
"@types/mocha": "^2.2.44",
"@types/node": "^6.0.89",
"gulp": "^3.9.1",
"gulp-bump": "^2.8.0",
Expand All @@ -593,6 +588,7 @@
"gulp-typings": "^2.0.4",
"merge-stream": "^1.0.1",
"mocha": "^4.0.1",
"prettier": "^1.8.2",
"tslint": "^5.7.0",
"typescript": "^2.5.3",
"vscode": "^1.1.6"
Expand Down
51 changes: 26 additions & 25 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3481,32 +3481,33 @@ class ActionOverrideCmdDInsert extends BaseCommand {
// Since editor.action.addSelectionToNextFindMatch uses the selection to
// determine where to add a word, we need to do a hack and manually set the
// selections to the word boundaries before we make the api call.
vscode.window.activeTextEditor!.selections = vscode.window
.activeTextEditor!.selections.map((x, idx) => {
const curPos = Position.FromVSCodePosition(x.active);
if (idx === 0) {
return new vscode.Selection(
curPos.getWordLeft(false),
curPos
.getLeft()
.getCurrentWordEnd(true)
.getRight()
);
} else {
// Since we're adding the selections ourselves, we need to make sure
// that our selection is actually over what our original word is
const matchWordPos = Position.FromVSCodePosition(
vscode.window.activeTextEditor!.selections[0].active
);
const matchWordLength =
matchWordPos
.getLeft()
.getCurrentWordEnd(true)
.getRight().character - matchWordPos.getWordLeft(false).character;
const wordBegin = curPos.getLeftByCount(matchWordLength);
return new vscode.Selection(wordBegin, curPos);
vscode.window.activeTextEditor!.selections = vscode.window.activeTextEditor!.selections.map(
(x, idx) => {
const curPos = Position.FromVSCodePosition(x.active);
if (idx === 0) {
return new vscode.Selection(
curPos.getWordLeft(false),
curPos
.getLeft()
.getCurrentWordEnd(true)
.getRight()
);
} else {
// Since we're adding the selections ourselves, we need to make sure
// that our selection is actually over what our original word is
const matchWordPos = Position.FromVSCodePosition(
vscode.window.activeTextEditor!.selections[0].active
);
const matchWordLength =
matchWordPos
.getLeft()
.getCurrentWordEnd(true)
.getRight().character - matchWordPos.getWordLeft(false).character;
const wordBegin = curPos.getLeftByCount(matchWordLength);
return new vscode.Selection(wordBegin, curPos);
}
}
});
);
await vscode.commands.executeCommand('editor.action.addSelectionToNextFindMatch');
vimState.allCursors = await allowVSCodeToPropagateCursorUpdatesAndReturnThem();
return vimState;
Expand Down
Loading