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

Recent Ruby changes add more keystrokes for me: class names and symbols #9069

Closed
1 task done
kaspth opened this issue Mar 8, 2024 · 6 comments · Fixed by #9170
Closed
1 task done

Recent Ruby changes add more keystrokes for me: class names and symbols #9069

kaspth opened this issue Mar 8, 2024 · 6 comments · Fixed by #9170
Assignees
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc language An umbrella label for all programming languages syntax behaviors ruby Ruby programming language support

Comments

@kaspth
Copy link

kaspth commented Mar 8, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

After some recent Zed updates, I'm getting different behavior when I try to edit class names and symbols.

Today I was trying to type out ActiveModel::Model, but had a misspelling like ActiveModel::Kod and as I went to hit to opt+delete to correct, Zed deleted the whole thing instead of just Kod. I've been used to :: being considered a word boundary previously.

Double-clicking on ActiveModel::Model or ActiveModel::Kod also selects the whole namespace as opposed to just a piece.

The same thing happens for symbols, so double-clicking on :some_symbol or some_symbol_keyword: in def some_method(some_symbol_keyword:) now includes : in the select.

I find both these changes quite frustrating as a user because it reduces my ability to navigate around Zed with a keyboard.

As a bit tough to recall when these things changed, but I'm guessing they're related to the recent highlights.scm changes.

cc @mrnugget

Environment

Zed: v0.125.3 (Zed)
OS: macOS 14.3.1
Memory: 16 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

@kaspth kaspth added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels Mar 8, 2024
@JosephTLyons JosephTLyons added ruby Ruby programming language support language An umbrella label for all programming languages syntax behaviors editor Feedback for code editing, formatting, editor iterations, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Mar 8, 2024
@mrnugget
Copy link
Member

mrnugget commented Mar 8, 2024

Hey @kaspth! Very interesting. I guess the only relevant change in recent weeks was this one: 3921259. That was to fix #7819 but maybe I overdid it and we shouldn't include : here.

If you want to run Zed from source and give it a short: simply remove : from here

word_characters = ["_", "$", "=", "@", "!", ":", "?"]
and cargo run.

If not, I'll give it a shot next week.

Thanks for reporting!

@mrnugget mrnugget self-assigned this Mar 8, 2024
@kaspth
Copy link
Author

kaspth commented Mar 8, 2024

@mrnugget ah thank you! I'll try to run it from source, but that commit does look like it could be it.

From an editing standout, I have liked that those characters weren't part of the word. But yeah, if autocomplete doesn't work without them, then…

Well, I'll try to play around with this first!

@davekaro
Copy link

davekaro commented Mar 8, 2024

Thank you for this issue, I also noticed in a recent Zed update that in vim mode, pressing w to navigate to the next word was skipping right past my namespaced classes. In your example, I'm used to having the cursor at the start of ActiveModel::Model and pressing w to advance to ::Model but now it's just going straight to the end. I thought it was a vim issue, but after seeing the issue, I verified in a non-Ruby file that word boundaries work as I expect.

All that to say, I'm in favor of removing the : from word_characters

@mrnugget
Copy link
Member

I have a branch in which I remove the : and after playing around with it, here's what I think:

It restores some of the old behavior: w in Vim mode will jump to ::Model (like you wanted @davekaro), double-clicking on ActiveRecord in ActiveRecord::Base will only select ActiveRecord, ...

The problem is that it breaks auto-complete for symbols, because now : isn't considered part of the word anymore. Investigating.

@mrnugget
Copy link
Member

Fix is here: #9170

Short version: restores old word boundaries, fixes completion to work with those word boundaries.

mrnugget added a commit that referenced this issue Mar 11, 2024
…Ruby word chars (#9170)

This fixes #9069 by

1. reverting #7819 
2. fixing completion filtering with regards to word boudaries

For (2) see explanation in commit message:

> Previously, this would only split words on upper-lower boundaries or
> on `_`/`-`.
> 
> The result was that we would filter out completions too aggressively.
> The filter works by taking a suggested completion, say `foo_bar_lol`,
split
> it up into words - `foo`, `bar, `lol` - and check whether any of the
words
> start with the same characters as what the user already typed: `fo`,
or `bar`,
> ...
> 
> In the case of Ruby, though, `:` wasn't considered a word boundary. If
the
> LSP would return `:foobar` when the user typed `:foo`, we'd check if
there are
> any completions that match `foo` (because that's the current word) but
> we'd compare against `foobar`, not `:` or `:foobar`.
> 
> With this change, we get more match candidates and thus more
completions in Ruby.

With that we can do (1) because we don't need these characters as word
characters anymore to trigger completions.

Release Notes:

- Fixed word boundaries in Ruby by restoring old behavior (`@`, `:`, ...
are no longer considered word characters)
([#9069](#9069))
- Fixed completions being filtered out when they happened at word
boundaries on special characters (e.g. `:`)

---------

Co-authored-by: Max <max@zed.dev>
@kaspth
Copy link
Author

kaspth commented Mar 11, 2024

@mrnugget woot, that's so cool! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc language An umbrella label for all programming languages syntax behaviors ruby Ruby programming language support
Projects
None yet
4 participants