7

Ruby:

file = File.new("some.txt", "r")
lines = file.readlines

Omni-completion tests

file.readl
   ---------
   readline     <- PASSED
   readlines
   ---------

"hola".capital
   ---------
   capitalize   <- PASSED
   capitalize!
   ---------

lines.
                <-- FAILED (no suggestions)

lines[0].capital
                <-- FAILED (no suggestions)

I tried Python as well, and it worked in similar way. So it looks like omni-completion can't be used for real development, as it fails on pretty simple cases?

Am I missing some thing? May be the intellisense can be improved some how for Ruby/Python?

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • It all depends on that omni completion script that is not necessarily part of the vim setup. If one went to extreme, omni completion script *could* handle any situation Intellisense handles. – mike3996 Jan 30 '11 at 09:50

1 Answers1

10

The issue is that Vim does not know if line is a String, an Array or some other Class. There is no deep syntactical analysis in Vim. Vim has no idea of scope, if a variable or method has been defined, etc.

It is only suggesting similar words. So yes, Vim is more limited than an IDE in this aspect. This is also why Eclipse can suggest errors as you typed them, and Vim can't.

Vim is much more basic: in a way, everything is text, and not necessarily seen as "code".

So you are right this is one of Vim limitation.

There are some plugins to work around those limitations (omnicpp is using ctags to determine the scope of some methods) but they are often developed on a per-language basis and there is no silver bullet.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
  • +1 - Good response. I would also add that the problem is compounded when working with dynamic languages where the bindings of objects isn't known until runtime. Even IDE's have to work some magic to be helpful in these cases. – Jordan Parmer Jan 28 '11 at 14:27
  • 3
    You know, AFAIK every omni completion script is somehow language specific: there's no default one set. They are just scripts, third-party, as any other plugins. The script could as well determine the scopes and types well as IDE's do it. – mike3996 Jan 30 '11 at 09:52
  • @progo : You are right. My comment was trying to put Vim into perspective versus a langage-specific IDE for Java, C#... Vim is a general tool and can't really compete versus a specific tool in some cases. – Xavier T. Feb 15 '11 at 16:15