Skip to content

Hierarchical symbols#176

Merged
gatesn merged 8 commits into
developfrom
ngates/hierarchical-symbols
Oct 28, 2017
Merged

Hierarchical symbols#176
gatesn merged 8 commits into
developfrom
ngates/hierarchical-symbols

Conversation

@gatesn

@gatesn gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

@lgeiger want to decide on what the symbols look like:

import sys

a = 'hello'

class B:
    def __init__(self):
        x = 2
        self.y = x

def main(x):
    y = 2 * x
    return y

IMO:

  • sys
  • a
  • B
  • B.__init__
  • B.__init__.x
  • main
  • main.y

@lgeiger

lgeiger commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

Thanks for continuing the efforts!

This is how it looks in Atom:
bildschirmfoto 2017-10-28 um 20 53 35

The filename is jedie.py. This line used to prevent it from always showing.

Personally I'd prefer to not show x any y per default because things may become pretty cluttered on large files, but I'm happy to go with this and let more people chime in on the discussion.
I think it's OK to go with this for now and see if people complain about pyls showing too many symbols. Since pyls is pre 1.0 we can always iterate later.

pyls/plugins/symbols.py looks like this:
bildschirmfoto 2017-10-28 um 21 02 45

Comment thread pyls/plugins/symbols.py Outdated
result['kind'] = _kind(name)

# All assignments have the filename as a there toplevel parent.
if parent and parent.parent():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need this check, otherwise the filename is always the top most symbol.

@gatesn

gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

I added the check to remove the top-level module name. But there's not sensible way to get rid of x and y without excluding things like a. So I'm going to leave it in for now.

@gatesn

gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

@lgeiger I just had a thought... the names should be fully qualified. Otherwise a variable defined in constructors of two classes (init method) can't be disambiguated.

@lgeiger

lgeiger commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

I added the check to remove the top-level module name.

👍

But there's not sensible way to get rid of x and y without excluding things like a. So I'm going to leave it in for now.

That's totally possible. That's what this check did.

@lgeiger I just had a thought... the names should be fully qualified. Otherwise a variable defined in constructors of two classes (init method) can't be disambiguated.

I don't know if I fully understand you, but I think they can be distinguished easily by the indentation in the UI since the __init__ methods hase different parents.

@gatesn

gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

What I mean is that a will have containerName __init__, as will b.

@gatesn

gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

I think we already make that check right? https://github.com/palantir/python-language-server/pull/176/files#diff-cee448b8821a222944d7e6f2ca332ddaR28

[edit] I see what's missing. Let me fix.

@lgeiger

lgeiger commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

What I mean is that a will have containerName init, as will b.

Yes, that's why the correct start and end positions are important for the UI to figure out where they belong.

@gatesn

gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

Got it, the positions are used in addition to containerName.

Also, on second thoughts, a variable local to a function is still a symbol. So going to leave them.

@lgeiger

lgeiger commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

I think we already make that check right?

No, the check here also tests if the statement is defined inside a function and omits it. If parent.parent() isn't defined it's in the global scope, otherwise it was defined inside a function.

Got it, the positions are used in addition to containerName.

Yeah, it's not exactly the most elegant way to infer hierarchy 😄

Also, on second thoughts, a variable local to a function is still a symbol. So going to leave them.

I'm OK with this. I don't know what the canonical way would be.

@gatesn

gatesn commented Oct 28, 2017

Copy link
Copy Markdown
Contributor Author

Ok, sounds sounds like we're in agreement. I also don't mind if the client excludes variables whose container symbol is a function. Most outline views tend to be expandable trees though, so I wonder if it can just be solved with default level of expanded subtrees.

Anyway, going to merge to get this out the door. Thanks for all your help / opinions!

@gatesn gatesn merged commit 9a3545d into develop Oct 28, 2017
@gatesn gatesn deleted the ngates/hierarchical-symbols branch October 28, 2017 20:38
@lgeiger

lgeiger commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

so I wonder if it can just be solved with default level of expanded subtrees.

It's not so easy to solve this with default levels since one would also exclude class methods then.

Anyway, going to merge to get this out the door. Thanks for all your help / opinions!

Cool looking forward to the next release.

@bhack

bhack commented Dec 14, 2017

Copy link
Copy Markdown

Do you think that we will have a new tagged release for this soon?

@bhack

bhack commented Dec 19, 2017

Copy link
Copy Markdown

@lgeiger The is a new release now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants