Skip to content

Conversation

@CXuesong
Copy link

@CXuesong CXuesong commented Apr 7, 2019

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.

@palantirtech
Copy link
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.
@xiaoxiae
Copy link

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

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