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

Fix # and * Behaviour #702

Merged
merged 1 commit into from
Sep 2, 2016
Merged

Fix # and * Behaviour #702

merged 1 commit into from
Sep 2, 2016

Conversation

jpoon
Copy link
Member

@jpoon jpoon commented Sep 2, 2016

Properly fixes #569.

Behaviour of # and * is expected to be:

  1. If cursor selects whitespace, the word closest to right is chosen
  2. If there is no word to the right of the cursor, a VIM error is thrown
  3. Otherwise, searches for currently selected word.

@jpoon jpoon force-pushed the fix_hash_asterix_command branch 2 times, most recently from 5ab128a to f576c25 Compare September 2, 2016 20:47
const word = TextEditor.getText(new vscode.Range(start, end));

if (whitespaceRegex.test(word)) {
throw VimError.fromCode(ErrorCode.E348);
Copy link
Member

@johnfn johnfn Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm beginning to think we should move away from throw and try/catch. The more I use them the more I feel like they're just a goto statement to some arbitrary point in the codebase.

I'd much rather prefer making the return type something like string | undefined to indicate failure and then handling that at the call site. Fortunately this change is pretty easy here.

Copy link
Member Author

@jpoon jpoon Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer throw as it's a bit more declarative of what's going on; undefined is well, undefined and can be overloaded on what the caller should do with it. It doesn't matter in this case as the caller ignores the error, but eventually it would be nice to show this error on the status bar like how vim does it.

Did I sway you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you're saying, but hailing from other languages with optionals, IMO returning an empty optional is as declarative as throwing an error. I like it because now the return value indicates "this function can fail" and the caller is forced to deal with it, or else get type errors.

As it is, anyone else who calls this function will have to remember that it throws or else they'll get into trouble.

I could see putting the status message on VimState actually. This seems nice to me because then we'd retain the behavior of updateView taking a VimState and rendering it to screen.

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is, anyone else who calls this function will have to remember that it throws or else they'll get into trouble.

Fair point. Coming from c#, the compiler would complain if you didn't properly catch an exception.

@jpoon jpoon merged commit 259ce18 into master Sep 2, 2016
@jpoon jpoon deleted the fix_hash_asterix_command branch September 2, 2016 23:12
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

# in Normal mode causes Vim to lock up
2 participants