Giter Club home page Giter Club logo

Comments (13)

powerman avatar powerman commented on July 16, 2024

Comment #1 originally posted by powerman on 2012-05-20T15:49:42.000Z:

Actually I didn't know/use python, and implemented python support for viewdoc in very basic way. I expect someone with better python knowledge will provide real python plugin for viewdoc. Anyway, I've fixed this (update from repository).

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #2 originally posted by powerman on 2012-05-31T05:22:32.000Z:

improve viewdoc:

give out a python code example:
s = "HI"
s.lower()
str.lower()

s is an instance of object str.
when I press "K" on str.lo|wer(), viewdoc can work fine.
but viewdoc can not work on instance like s.lo|wer()
Python has a built-in function type() to detect.
so viewdoc script can use a command like bellowing to work correctly.
python -c "s = 'hi' ; print(type(s))

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #3 originally posted by powerman on 2012-05-31T06:46:37.000Z:

Actually I don't think it's possible to do this.

In large python script, somewhere in the middle of code you'll see "var.method()", but "var" may be defined far away from this place. So only way to find "type(var)" is execute full script, not just line which define this variable like "s='hi'" because in general case it's impossible to find and extract just this line from overall script. But executing full script also impossible - first because it's probably bad idea to run unknown script in current directory, second because script code most likely isn't complete yet and may contain syntax errors etc and it won't run in any case.

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #4 originally posted by powerman on 2012-05-31T08:00:44.000Z:

=> On [2012-05-31 06:46:52 +0000]:
[email protected] Said:

You are right, I have not consider it too much.
I come up with a new idea. Vim has a function, press "gd" or "gD" to go to
variable or function's define place. so viewdoc can use this approach too.
viewdoc only search through define place, (maybe need do a simple syntax check,
you can pass this task to other script like syntastic etc). This will be more
safer and effective.

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #5 originally posted by powerman on 2012-05-31T08:16:18.000Z:

And what if variable defined not like "s='hi'" but like "s=func()" or "s=othervar"?

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #6 originally posted by powerman on 2012-05-31T08:50:28.000Z:

=> On [2012-05-31 08:16:36 +0000]:
[email protected] Said:

Yes, this is difficult.

Maybe viewdoc can judge depend on the return and the output.
For example:
a = c
print(a)
error is c is not defined.
Then let viewdoc crawl for variable c again.

What about let viewdoc return error for those situation, but still implement
ahead what I said ? Of course if it is not a good idea to implement this complex
things.

This feels like a complex steps, at least it is for me. I do not know much on
programming. :)

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #7 originally posted by powerman on 2012-05-31T09:10:54.000Z:

That's not 'difficult'. That's impossible in general case; for some corner cases when it may work it's unsafe (require executing unknown code), slow and overcomplicated - i.e. there is no real sense in trying to implement such a thing.

This feature usually available only in 'real' IDE. I don't think Vim will be ever capable to understand meaning of code it editing as good as real IDE does. And without such deep code understanding it's impossible to get variable type from it name. Actually, all what Vim is able to do - use regular expressions/etc. to handle programming language syntax. Probably in some strict typing languages it's possible to find variable definition line and type using this way. But I don't think it's possible for flexible script languages like Python or Perl.

Actually, usually best thing we can do to detect which type of documentation should be used depending on current context - use Vim's syntax detection rules (which is also based in regular expressions) to find current syntax element name in cursor position. This is already done in viewdoc's Perl support - you can compare it with much more trivial Python support to see the difference.

So, if you manage to write regular expression which will detect Python variable type - I can use it in viewdoc. And by 'regular expression' I didn't mean limitation in just single regex, any non-overcomplicated algorithm which use any string processing functions is acceptable. Text should be statically analyzed, without executing (part of) editing file. But I don't really believe that's possible. What may be possible is improve Python support in way similar to used for Perl - using Vim syntax detection. This won't help in detecting variable types, but may help with other things like operators, modules, etc.

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #8 originally posted by powerman on 2012-05-31T09:33:01.000Z:

=> On [2012-05-31 09:11:00 +0000]:
[email protected] Said:

Awesome, I agree. ok, this feature closed. And say Thanks.

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #9 originally posted by powerman on 2012-06-01T08:59:21.000Z:

=> On [2012-05-31 09:11:00 +0000]:
[email protected] Said:

I found some vim syntax checker like syntastic.vim can do something similar.
For example:
python b = 1 a = b + c
Then syntastic.vim will notice you that variable c is not defined.
syntastic.vim use external program like pylint etc. so viewdoc can invoke some
thing from external program like pylint etc too.

What about this ?

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #10 originally posted by powerman on 2012-06-01T09:09:48.000Z:

I use syntastic too. But 'check syntax' and 'show documentation' is very different operations.

  1. When you do 'check syntax', your code is most likely have no obvious syntax errors. But when you do 'show documentation' your code is most likely have syntax errors (you type part of next command, and press F1 to see info about it to find what to type next). What this mean for us - in most cases when F1 pressed viewdoc will have syntactically incorrect code in current buffer, and such code usually can't be processed by tools which analyze it and show things like variable types.

  2. Ok, we can check syntax. This is safe, because it doesn't really execute this code. And so what? How this helps us to find variable type?

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #11 originally posted by powerman on 2012-06-01T09:19:23.000Z:

=> On [2012-06-01 09:09:57 +0000]:
[email protected] Said:

Because you asked what if a = func() this situation.
The syntax checker must follow some rules to check, it it does not really run
code. Then it maybe check rules with strings, regex, patterns etc, right ?
So viewdoc can imitate those method. This is what I think.

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #12 originally posted by powerman on 2012-06-01T09:29:33.000Z:

Thing is, syntax checkers check syntax - it doesn't mean they able and will check variable types. Moreover, in scripting/dynamically typed languages that's often not possible at all because same variable may contain values of different types at runtime, like (in Perl):

$a = 123;
$sum = add($a, ...);
$a = 'string';
$text = sprintf("text is %s", $a);
$a = Class->new();
$a->method();

And while there is no problem in checking syntax of that code, it's impossible to find out 'current' type of variable $a without actually running this code.

So. If you find a tool which can somehow detect variable type inside incomplete Python code snippet with syntax errors without executing that code - I'll be happy to use that tool in viewdoc. But I don't really believe such a tool may exists.

from vim-plugin-viewdoc.

powerman avatar powerman commented on July 16, 2024

Comment #13 originally posted by powerman on 2012-06-01T09:47:25.000Z:

=> On [2012-06-01 09:29:42 +0000]:
[email protected] Said:

I know it is impossible.

But at least viewdoc can check out help at more wide scope.
Just like what I said ahead. A simple situation.
s = 'hi'
s.islo|wer()
This simple situation can be checked out help document.
I do not hope viewdoc can be very awesome.
In upper code example:
- viewdoc can support an option to whether enable this.
- viewdoc maybe find a wrong help document, because python those dynamic
language. viewdoc can not know exactly.
Anyway, I know this is not the correct way, but at least it can do a part of
things.

Hmm, this sounds like somebody use a wrong way to get a correct result.
(even this result is half correct)

Of course, I'm not force you to implement this half wrong thing. I just think
this "fake" half correct way can improve viewdoc.

from vim-plugin-viewdoc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.