Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textDocument/documentSymbol response only show the range of the name of method/class. #2948

Closed
Instein98 opened this issue Nov 7, 2023 · 2 comments

Comments

@Instein98
Copy link

Hi! I am writing a client in Python to communicate with the jdt ls. I noticed that when my client sent a request of textDocument/documentSymbol, like:

Content-Length: 301

{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "textDocument/documentSymbol",
    "params": {
        "textDocument": {
            "uri": "file:///xxx/tests/org/jfree/chart/renderer/category/junit/AbstractCategoryItemRendererTests.java"
        }
    }
}

The server's response only show the range of the name of method/class, like:

{
    "jsonrpc": "2.0",
    "id": 2,
    "result": [{
        "name": "suite()",
        "kind": 6,
        "location": {
            "uri": "file://xxx/tests/org/jfree/chart/renderer/category/junit/AbstractCategoryItemRendererTests.java",
            "range": {
                "start": {
                    "line": 80,
                    "character": 23
                },
                "end": {
                    "line": 80,
                    "character": 28
                }
            }
        },
        "containerName": "AbstractCategoryItemRendererTests"
    }, {
        "name": "testEquals()",
        "kind": 6,
        "location": {
            "uri": "file://xxx/tests/org/jfree/chart/renderer/category/junit/AbstractCategoryItemRendererTests.java",
            "range": {
                "start": {
                    "line": 87,
                    "character": 16
                },
                "end": {
                    "line": 87,
                    "character": 26
                }
            }
        },
        "containerName": "AbstractCategoryItemRendererTests"
    }, ..., {
        "name": "test2947660()",
        "kind": 6,
        "location": {
            "uri": "file://xxx/tests/org/jfree/chart/renderer/category/junit/AbstractCategoryItemRendererTests.java",
            "range": {
                "start": {
                    "line": 395,
                    "character": 16
                },
                "end": {
                    "line": 395,
                    "character": 27
                }
            }
        },
        "containerName": "AbstractCategoryItemRendererTests"
    }, {
        "name": "AbstractCategoryItemRendererTests",
        "kind": 5,
        "location": {
            "uri": "file://xxx/tests/org/jfree/chart/renderer/category/junit/AbstractCategoryItemRendererTests.java",
            "range": {
                "start": {
                    "line": 73,
                    "character": 13
                },
                "end": {
                    "line": 73,
                    "character": 46
                }
            }
        },
        "containerName": "AbstractCategoryItemRendererTests.java"
    }]
}

I omitted some parts as it is too long. The ranges of method and class are all within one line. And the ranges actually exactly represent the range of the name of the method/class.

But from my understanding, the ranges should be the ranges of the whole method body and the whole class, right? Is there a way that I can make the server generate such full range?

@rgrunber
Copy link
Contributor

rgrunber commented Nov 8, 2023

textDocument/documentSymbols supports both a list of SymbolInformation & DocumentSymbol. DocumentSymbol is the one that includes a range & selectionRange.

It looks like JDT-LS is only returning what appears to be SymbolInformation for you. Is your client setting hierarchicalDocumentSymbolSupport? If you aren't then JDT-LS will continue to return non-hierarchical symbols, which lack the API to specify both ranges :

if (preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()) {
List<DocumentSymbol> symbols = this.getHierarchicalOutline(unit, monitor);
return symbols.stream().map(Either::<SymbolInformation, DocumentSymbol>forRight).collect(toList());
} else {
SymbolInformation[] elements = this.getOutline(unit, monitor);
return Arrays.asList(elements).stream().map(Either::<SymbolInformation, DocumentSymbol>forLeft).collect(toList());
}

Part of the issue is we didn't migrate our non-hierarchical textDocument/documentSymbols implementation to also use DocumentSymbol (it still uses SymbolInformation).

@Instein98
Copy link
Author

Instein98 commented Nov 8, 2023

Hi Roland, thanks so much for your prompt reply, I really appreciate it. After specifying hierarchicalDocumentSymbolSupport to be true, I got what I wanted.

Specifically, in the initialize message, I specified:

"documentSymbol": {
    "dynamicRegistration": false,
    "symbolKind": {
        "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]
    },
    "hierarchicalDocumentSymbolSupport": true,
    "tagSupport": {
        "valueSet": [1]
    },
    "labelSupport": true
    },

Since the issue has been resolved, please feel free to close this issue. Thanks again.

@fbricon fbricon added question and removed debt labels Nov 8, 2023
@fbricon fbricon closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants