vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Imports are not included in the document symbols returned from "getDocumentSymbols" API

Open ShimonBenYair opened this issue 5 years ago • 3 comments

Hi

I am writing a vscode extension and I want to get the symbols of a JAVA file.

Environment Operating System: windows 10 Visual Studio Code version: 1.50.0

Steps To Reproduce If I run this sample code :

`const vscodeCDSExtension = extensions.getExtension("redhat.java"); const javaDocParams : DocumentSymbolParams = { textDocument: { uri: Uri.file(filePath).toString() } };

if (vscodeCDSExtension && vscodeCDSExtension.isActive) { const symbols = await vscodeCDSExtension.exports.getDocumentSymbols(javaDocParams); console.log(symbols.length); }`

Current Result The "imports" of the file are not included in the returned symbols (only "package", classes and methods are returned)

Expected Result The "imports" also should be included in the result

The JAVA file is attached

CatalogServiceHandler.zip

ShimonBenYair avatar Oct 16 '20 02:10 ShimonBenYair

If you look documentSymbol request at the LSP protocol, usually what it asks is the members such as fields, classes, methods. Could you please explain a bit more about your user scenario why "imports" is needed?

testforstephen avatar Oct 16 '20 04:10 testforstephen

@testforstephen I am writing a vscode extension that gives the user an option to generate some methods (according to his selections) and then to add the generated code to a JAVA file. Sometimes those new generated methods require new imports in the JAVA file. So i need to know which imports already exist in the file in order to add the missing ones

ShimonBenYair avatar Oct 16 '20 05:10 ShimonBenYair

You can GoToDefinition on an import's Class part. So you should be able to get that symbol location in this api call.

maxhillaert avatar Mar 03 '25 01:03 maxhillaert