alienhard / SublimeAllAutocomplete

Extend Sublime autocompletion to find matches in all open files of the current window
917 stars 110 forks source link

Words without last letter #3

Closed igoralekseev closed 11 years ago

igoralekseev commented 11 years ago

I got strange issue -- some words in two variants in list like "is_owne" and "is_owner" and i am sure there is no "is_owne" in my project.)

Do you know what it could be?

alienhard commented 11 years ago

Strange, I've never seen this...

Is always just the last character missing? It is always a substring of another match in the list? I could filter out matches that are substrings of others, but it would be interesting to see the pattern first (and hopefully where it comes from).

Does anyone else have this problem?

igoralekseev commented 11 years ago

it's complicated to diagnose because not every word have a duplicate It seem like suggestion comes from list which hasnt been updated, seems like i typed and it catched incomplete word and then continue to show it as a suggestion

osuushi commented 11 years ago

EDIT: After some more research, this appears to be a well-known bug in the Sublime Text 2 API; view.extract_completions returns truncated results. It might be possible to work around this by manually searching for the completions in the view and repairing them, but I think the options are limited.

I have been having the same issue, but I only see it with CoffeeScript files. Specifically, it happens when the source of the completion is CoffeeScript

Let's say I have foo.py:

pythonName = "Pat"

and I have bar.coffee

coffeeName = "Carl"

and I have baz.js

jsName = "James";

All of these files are open in Sublime.

If I type pyth in any of the open files then pythonName immediately pops up in the completion list.

If I type jsn in any of the files, jsName pops up.

But if I type cof in any of the files, coffeeNam pops up instead of coffeeName.

I can narrow it down further within CoffeeScript. If I have a file with this line:

x = secondCoffeeName

then secondCoffeeName autocompletes correctly in all file types.

If I add another line like this:

secondCoffeeName = 1
x = secondCoffeeName

then both secondCoffeeNam and secondCoffeeName will show up in the completion list.

Here is a full list of cases I am aware of where someName will lose its last letter in the completion list:

Straight variable assignment

someName = 1

Multiple variable assignment

x = someName = 1

Object property assignment

obj.someName = 1

Object literal

obj = someName: 1

This holds regardless of the literal syntax; curly braces, multi-lines, whatever, it always happens. The one exception is if the name is quoted, as in

obj = "someName": 1

In that case, the name will not be truncated.

Class properties

class X
    someName: 1

Here are some situations where someName doesn't get clipped. If any of these appear in addition to any of the above, you'll see both someNam and someName in the list:

Class definitions

class someName

Assignment using @ sign

@someName = 1

Class properties using @ sign

class X
    @someName: 1

Compound assignment

someName ?= 1

or

someName += 1

etc.

Rvalues

x = someName

Function arguments

f = (someName) -> 1

Array/object index

arr[someName] = 1

Name with index

someName[0] = 1

Name with property assignment

someName.x = 1

Name as iteration variable

x = 0
for someName in arr
    x += 1

Finally, we can falsify @igoralekseev's hypothesis that the incomplete word is being cached as you type. If you paste abracadabra = 1 into a brand new CoffeeScript file, then you will still see abracadabr in the completion list, even though the word was pasted in whole.

Rather, the inconsistency seems to be purely from different contexts in which a name has been used.

I hope this helps.

alienhard commented 11 years ago

I merged @osuushi's workaround so this should be fixed now. Thanks guys!