Non-word-characters and `additionalWordCharacters`: inserting words bug
ashthespy opened this issue · 11 comments
Edit by @rsese - reproduced with the repro steps in autocomplete-python/autocomplete-python#369 (comment). See the copied repro steps and repeated "foo" in the GIF from that issue below
- Autocomplete-python is enabled
- Underscore set as a non-word character in Editor setting
- Type any word with underscore. If the current typing position is after an underscore, the autocompleted word insert will be the whole phrase again instead of only the remaining part.
And from @ashthespy #1020 (comment):
I'd reckon it's autocomplete-plus bug as it is doing the replacing of the suggestion and replacement prefix from the external providers.
Description
When the prefix contains a nonWordCharacter
, the suggestion jumps after the last character, instead of consuming the prefix.
Cross posting from issue: ashthespy/Atom-LaTeX#186
Similar issue also seen over at autocomplete-python/autocomplete-python#369
Expected behavior:
Suggestion snippet replaces entire prefix.
Actual behavior:
Suggestion snipped replaces the last word boundary
Versions
Currently atom-latex runs v2.0.0
of the provider API. I was able to overcome this issue by adding :
to the additionalWordCharacters
UI setting, and bumping up the provider API version to v4.0.0
. however, is there a way to set additionalWordCharacters
at the provider/grammar level instead??
Maybe pertinent info from DamnedScholar:
I think what’s happening is that the colon is a non-word character. You type eq:, and autocomplete-plus is given the text just before the cursor, which doesn’t seem to care about the colon for some reason. When the package tries to insert the completion, I would expect it to run editor.selectToBeginningOfWord(), which is of course a zero-length string if the colon is a non-word character.
After checking the code: the above is a pretty theory, but I can’t support it with an actual reading of the source code 2. It’s still worth fiddling that setting to see if there’s an easy out. Based on that function, maybe autocomplete-plus does something erroneous like passing on a zero-length prefix when the final character isn’t a word character (you should be able to test this with any of the others on the list).
@ashthespy What is the value of the prefix being passed to getSuggestions
(it should be empty when :
is typed and not registered as a word character)? I think I had similar trouble, so I grab the prefix manually.
@Aerijo The prefix to getSuggestions
hands out :
when sec:
is typed. So we grab the prefix manually as well. This manually grabbed prefix is returned via replacementPrefix
but it doesn't seem to be used?
Thanks for the report @ashthespy - reproduced with the steps in autocomplete-python/autocomplete-python#369. @ashthespy do you happen to have a repro case that involves just core Atom (so not using a community package)?
Not that I know of - haven't explored all the default grammars. However, doesn't this look more to be an issue with the custom providers/implementation of the providers?
Sorry yes that's the question I'm moving towards - do folks think this is an issue with particular autocomplete providers or is this a bug report for autocomplete-plus?
I'd reckon it's autocomplete-plus
bug as it is doing the replacing of the suggestion and replacement prefix from the external providers.
Ok thanks @ashthespy - if you have any more specific details to share feel free to edit the issue body and we'll go ahead and mention this one to the team.
Sorry no updates @ashthespy, our engineers can prioritize only so many things unfortunately. If someone were to open a well-written pull request however, we could add that to the team's list of things to review.
Managed to fix this from my package's side with
diff --git a/package.json b/package.json
index 7f0fbec..fe7b306 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"providedServices": {
"autocomplete.provider": {
"versions": {
- "2.0.0": "provide"
+ "4.0.0": "provide"
}
}
},
diff --git a/settings/language-latex.cson b/settings/language-latex.cson
index 9645e98..3c4ebf2 100644
--- a/settings/language-latex.cson
+++ b/settings/language-latex.cson
@@ -4,6 +4,8 @@
'tabLength': 2
'softWrap': true
'commentStart': '% '
+ 'autocomplete-plus':
+ 'extraWordCharacters': ':_/'
'bracket-matcher':
'autocompleteCharacters': [
'$$',
My issue was that I was earlier using autocomplete
instead of autocomplete-plus
in my language.cson.