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

Racket omni_start_map should be something like \k\+ #3870

Closed
benknoble opened this issue Aug 10, 2021 · 4 comments
Closed

Racket omni_start_map should be something like \k\+ #3870

benknoble opened this issue Aug 10, 2021 · 4 comments

Comments

@benknoble
Copy link
Contributor

Racket, being a lisp, has far more than just alpha-numeric identifiers, which is what the default pattern matches. This means when I type file-name, invoking completion won't give file-name-from-path but completions like namespace—it has used only the name part. Using \k\+ seemed to work in cases like this, but I don't have an exhaustive test.

More broadly, and the reason this is an issue and not a PR, is I think the default should be \k\+—then it should be effectively scoped to the languages iskeyword setting, no?

I also don't understand why $ is included in the omni_start_map pattern: does that only allow completions when there is nothing else on the line? Perhaps word boundaries \<\> would be more appropriate?

Looking for feedback here.


PS Why not use the lisp pattern? Well, I don't think even it covers all possible lisp or racket identifiers, and \k\+ is so much easier to read.

@w0rp
Copy link
Member

w0rp commented Nov 11, 2021

I don't know what any of this is, but if you can create a pull request that fixes this without breaking any current functionality in languages like TypeScript, go for it.

@benknoble
Copy link
Contributor Author

I am referring to s:omni_start_map in autoload/ale/completion.vim (apologies for not being clear). The declaration is around line 139, with sole use at line 311.

It seems like the intent was to allow filetypes to specify patterns to find the start of a word for completion, with a default of

\v[a-zA-Z$_][a-zA-Z$_0-9]*$

Unfortunately, this doesn't work for some languages. It explicitly disallows - in words that should start completion, for example; every lisp I've ever used has - in names commonly (some examples are in the original post). This means that trying to complete from a word that already has - in it breaks.

My suggestion is to use \k\+ (possibly with word boundaries)—then the default should work for all filetypes by leveraging their custom iskeyword settings (which define in vim what a word is for a filetype). If a filetype has this correctly set (and, e.g., racket, scheme, and common lisp should), then it should "just work."

If that's no good, then I'd like to at least add 'racket': '\k\+' or similar—the issue is that racket is actually a lot of languages, so there are lots of possible filetypes… and other lisps suffer, too, so it would be nice to add them… etc. So then you have this mechanism that controls completion (and breaks it, if not set right) but that is really hard to customize. (By really hard, I mean that the only way is to (a) edit your local copy of ALE and be careful not to lose that when updating or (b) submit a PR and wait for it to merge. That seems untenable in the long-term.)

benknoble added a commit to benknoble/ale that referenced this issue May 5, 2022
The default `omni_start_map` is to restrictive for Lisps and Schemes
like Racket, which permit hyphens (among other special characters).

As recorded in dense-analysis#3870, trying to complete `file-name-from-path` when
typing `file-name<C-x><C-o>` would give completions like `namespace`
because the hyphen is ignored to find the start of the word for
completion.

Now the racket filetype searches for the start using the keyword class
`\k`, which is more precise.
benknoble added a commit to benknoble/ale that referenced this issue May 5, 2022
The default `omni_start_map` is too restrictive for Lisps and Schemes
like Racket, which permit hyphens (among other special characters).

As recorded in dense-analysis#3870, trying to complete `file-name-from-path` when
typing `file-name<C-x><C-o>` would give completions like `namespace`
because the hyphen is ignored to find the start of the word for
completion.

Now the default searches for the start using the keyword class
`\k`, which is more precise and configurable for each filetype without
modifying the source.
benknoble added a commit to benknoble/ale that referenced this issue May 5, 2022
The default `omni_start_map` is too restrictive for Lisps and Schemes
like Racket, which permit hyphens (among other special characters).

As recorded in dense-analysis#3870, trying to complete `file-name-from-path` when
typing `file-name<C-x><C-o>` would give completions like `namespace`
because the hyphen is ignored to find the start of the word for
completion.

Now the racket filetype searches for the start using the keyword class
`\k`, which is more precise.
@benknoble
Copy link
Contributor Author

I've opened 2 different pull requests:

  1. One only fixes Racket, which I feel is unsustainable.
  2. The other modifies the default to be more precise per-filetype, but I don't know if this will break anything else.

@benknoble
Copy link
Contributor Author

Reviving this, both PR #4186 and #4187 pass tests. It's not clear to me that passing the tests means "without breaking any current functionality in languages like TypeScript," but I thought I would mention it.

hsanson pushed a commit that referenced this issue Jun 23, 2022
The default `omni_start_map` is too restrictive for Lisps and Schemes
like Racket, which permit hyphens (among other special characters).

As recorded in #3870, trying to complete `file-name-from-path` when
typing `file-name<C-x><C-o>` would give completions like `namespace`
because the hyphen is ignored to find the start of the word for
completion.

Now the racket filetype searches for the start using the keyword class
`\k`, which is more precise.
@hsanson hsanson closed this as completed Jun 23, 2022
cyyever pushed a commit to cyyever/ale that referenced this issue Jul 11, 2022
The default `omni_start_map` is too restrictive for Lisps and Schemes
like Racket, which permit hyphens (among other special characters).

As recorded in dense-analysis#3870, trying to complete `file-name-from-path` when
typing `file-name<C-x><C-o>` would give completions like `namespace`
because the hyphen is ignored to find the start of the word for
completion.

Now the racket filetype searches for the start using the keyword class
`\k`, which is more precise.
cyyever pushed a commit to cyyever/ale that referenced this issue Jul 11, 2022
The default `omni_start_map` is too restrictive for Lisps and Schemes
like Racket, which permit hyphens (among other special characters).

As recorded in dense-analysis#3870, trying to complete `file-name-from-path` when
typing `file-name<C-x><C-o>` would give completions like `namespace`
because the hyphen is ignored to find the start of the word for
completion.

Now the racket filetype searches for the start using the keyword class
`\k`, which is more precise.
benknoble added a commit to benknoble/ale that referenced this issue Nov 3, 2022
Consider a file like
```
 #lang racket
(require racket/gui)
```
Type `Go(eventspace-`.

Pressing <C-x><C-o> to trigger omnicomplete should suggest
```
eventspace-handler-thread
eventspace-shutdown?
eventspace-event-evt
```

It does not (instead producing "top-level" completions, as if
`(eventspace-` wasn't even there).

Debugging, `ale#completion#OmniFunc(1, '')` correctly returns `1`, but
when given `(0, 'eventspace-')` it returns either the empty list or
generic completion results as described above. I'm not entirely sure of
the mechanism, but it seems that b:ale_completion_info.prefix is the
key, and that this is set by `ale#completion#GetPrefix`.

Calling `ale#completion#GetPrefix('racket', line('.'), col('.'))` with
the cursor on a space _after_ `eventspace-` returned `''`!

Now, it returns `eventspace-` and the completions work correctly again.

Ref dense-analysis#4293, dense-analysis#4186, dense-analysis#3870
benknoble added a commit to benknoble/ale that referenced this issue Nov 3, 2022
Consider a file like
```
 #lang racket
(require racket/gui)
```
Type `Go(eventspace-`.

Pressing <C-x><C-o> to trigger omnicomplete should suggest
```
eventspace-handler-thread
eventspace-shutdown?
eventspace-event-evt
```

It does not (instead producing "top-level" completions, as if
`(eventspace-` wasn't even there).

Debugging, place the cursor on a space _after_. Now
`ale#completion#OmniFunc(1, '')` correctly returns `1`, but when given
`(0, 'eventspace-')` it returns either the empty list or generic
completion results as described above. I'm not entirely sure of the
mechanism, but it seems that `b:ale_completion_info.prefix` is the key,
and that this is set by `ale#completion#GetPrefix`. Calling
`ale#completion#GetPrefix('racket', line('.'), col('.'))` returned `''`!

Now, it returns `eventspace-` and the completions work correctly again.

Ref dense-analysis#4293, dense-analysis#4186, dense-analysis#3870
hsanson pushed a commit that referenced this issue Nov 5, 2022
Consider a file like
```
 #lang racket
(require racket/gui)
```
Type `Go(eventspace-`.

Pressing <C-x><C-o> to trigger omnicomplete should suggest
```
eventspace-handler-thread
eventspace-shutdown?
eventspace-event-evt
```

It does not (instead producing "top-level" completions, as if
`(eventspace-` wasn't even there).

Debugging, place the cursor on a space _after_. Now
`ale#completion#OmniFunc(1, '')` correctly returns `1`, but when given
`(0, 'eventspace-')` it returns either the empty list or generic
completion results as described above. I'm not entirely sure of the
mechanism, but it seems that `b:ale_completion_info.prefix` is the key,
and that this is set by `ale#completion#GetPrefix`. Calling
`ale#completion#GetPrefix('racket', line('.'), col('.'))` returned `''`!

Now, it returns `eventspace-` and the completions work correctly again.

Ref #4293, #4186, #3870
mnikulin pushed a commit to mnikulin/ale that referenced this issue Nov 12, 2023
Consider a file like
```
 #lang racket
(require racket/gui)
```
Type `Go(eventspace-`.

Pressing <C-x><C-o> to trigger omnicomplete should suggest
```
eventspace-handler-thread
eventspace-shutdown?
eventspace-event-evt
```

It does not (instead producing "top-level" completions, as if
`(eventspace-` wasn't even there).

Debugging, place the cursor on a space _after_. Now
`ale#completion#OmniFunc(1, '')` correctly returns `1`, but when given
`(0, 'eventspace-')` it returns either the empty list or generic
completion results as described above. I'm not entirely sure of the
mechanism, but it seems that `b:ale_completion_info.prefix` is the key,
and that this is set by `ale#completion#GetPrefix`. Calling
`ale#completion#GetPrefix('racket', line('.'), col('.'))` returned `''`!

Now, it returns `eventspace-` and the completions work correctly again.

Ref dense-analysis#4293, dense-analysis#4186, dense-analysis#3870
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants