FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Introduce hierarchical documentSymbol support by CXuesong · Pull Request #537 · palantir/python-language-server · GitHub

Introduce hierarchical documentSymbol support - #537

Open
CXuesong wants to merge 8 commits into
palantir:developfrom
CXuesong:develop
Open

Introduce hierarchical documentSymbol support#537
CXuesong wants to merge 8 commits into
palantir:developfrom
CXuesong:develop

Conversation

CXuesong commented Apr 7, 2019

Copy link
Copy Markdown

c.f. #407

This PR should make textDocument/documentSymbol reponse use the new DocumentSymbol contract. This means you can have a list of children for each parent symbols. Now the documentSymbol is something like this

{
    "jsonrpc": "2.0",
    "id": "2",
    "result": [
        {
            "name": "ReadFields",
            "detail": "ReadFields",
            "range": {
                "start": {
                    "line": 3,
                    "character": 0
                },
                "end": {
                    "line": 19,
                    "character": 0
                }
            },
            "selectionRange": {
                "start": {
                    "line": 3,
                    "character": 4
                },
                "end": {
                    "line": 3,
                    "character": 14
                }
            },
            "kind": 12,
            "children": [
                {
                    "name": "closeFile",
                    "detail": "ReadFields.closeFile",
                    "range": {
                        "start": {
                            "line": 7,
                            "character": 4
                        },
                        "end": {
                            "line": 7,
                            "character": 21
                        }
                    },
                    "selectionRange": {
                        "start": {
                            "line": 7,
                            "character": 4
                        },
                        "end": {
                            "line": 7,
                            "character": 13
                        }
                    },
                    "kind": 13,
                    "children": null
                },
                {
                    "name": "f",
                    "detail": "ReadFields.f",
                    "range": {
                        "start": {
                            "line": 9,
                            "character": 8
                        },
                        "end": {
                            "line": 9,
                            "character": 22
                        }
                    },
                    "selectionRange": {
                        "start": {
                            "line": 9,
                            "character": 8
                        },
                        "end": {
                            "line": 9,
                            "character": 9
                        }
                    },
                    "kind": 13,
                    "children": null
                },
                {
                    "name": "closeFile",
                    "detail": "ReadFields.closeFile",
                    "range": {
                        "start": {
                            "line": 10,
                            "character": 8
                        },
                        "end": {
                            "line": 10,
                            "character": 24
                        }
                    },
                    "selectionRange": {
                        "start": {
                            "line": 10,
                            "character": 8
                        },
                        "end": {
                            "line": 10,
                            "character": 17
                        }
                    },
                    "kind": 13,
                    "children": null
                },
                {
                    "name": "l",
                    "detail": "ReadFields.l",
                    "range": {
                        "start": {
                            "line": 14,
                            "character": 8
                        },
                        "end": {
                            "line": 17,
                            "character": 0
                        }
                    },
                    "selectionRange": {
                        "start": {
                            "line": 14,
                            "character": 12
                        },
                        "end": {
                            "line": 14,
                            "character": 13
                        }
                    },
                    "kind": 13,
                    "children": null
                },
...

Python source code for reference

import io
from os import path

def ReadFields(f) :
    '''
    f : io.IOBase or str
    '''
    closeFile = False
    if isinstance(f, str) : 
        f = io.open(f)
        closeFile = True
    elif isinstance(f, io.IOBase) : pass
    else : raise TypeError
    try :
        for l in f :
            l = str(l).strip()
            if len(l) > 0 : yield l.split()
    finally :
        if closeFile : f.close()
...

Unfortunately, I haven't tested it thoroughly in VSCode because I simply couldn't start Extension Development Host with yarn run vscode.

Copy link
Copy Markdown
Member

Thanks for your interest in palantir/python-language-server, @CXuesong! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

... depends on whether LSP client supports hierarchicalDocumentSymbol.

Copy link
Copy Markdown

Has this ever been resolved? It would be a great addition.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL