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

Find references only working in the current document. Not working. Across the project. #3280

Open
kcpinnaka opened this issue Sep 22, 2024 · 3 comments

Comments

@kcpinnaka
Copy link

I'm using the following command to start the server
` command = [
"x:\jdk-17_windows-x64_bin\jdk-17.0.2\bin\java.exe",
"-Declipse.application=org.eclipse.jdt.ls.core.id1",
"-Dosgi.bundles.defaultStartLevel=4",
"-Declipse.product=org.eclipse.jdt.ls.core.product",
"-Dosgi.checkConfiguration=true",
r"-Dosgi.sharedConfiguration.area=x:\eclipse.jdt.lsNew\org.eclipse.jdt.ls.product\target\repository\config_win",
"-Dosgi.sharedConfiguration.area.readOnly=true",
"-Dosgi.configuration.cascaded=true",
"-noverify",
"-Xms1G",
f"-Djava.util.logging.config.file={log_config}",
"-Dlog.level=ALL",
"-jar",
r"x:\eclipse.jdt.lsNew\org.eclipse.jdt.ls.product\target\repository\plugins\org.eclipse.equinox.launcher_1.6.900.v20240613-2009.jar",
"-configuration",
r"x:\eclipse.jdt.lsNew\org.eclipse.jdt.ls.product\target\repository\config_win",
"-data",
path
]
def initialize(self):
params = {
"processId": None,
"rootUri": self.root_uri,
"capabilities": { "references": { "dynamicRegistration": True } }
}
return self.client.send_request_and_wait_for_response("initialize", params)

def find_references(self, file_uri, line, character):
    params = {
        "textDocument": {"uri": file_uri},
        "position": {"line": line, "character": character},
        "context": {"includeDeclaration": True}
    }
    return self.client.send_request_and_wait_for_response("textDocument/references", params)

`

Find references only working in the current document. Not working. Across the project.

However, when I run the project In Eclipse, PDE debugging mode on jdt.ls.socket-stream.launch,
I am able to see all references across the project.

@rgrunber
Copy link
Contributor

rgrunber commented Sep 24, 2024

Do references from across the project show if you set "classFileContentsSupport": true in extendedClientCapabilities, (should be under the params object sent to initialize) ? See #3166 (comment) .

@kcpinnaka
Copy link
Author

Thank you for responding your response. But I'm still seeing the same issue.

I'm attaching the initialization response If it can provide more insights.

initialization response { 'jsonrpc': '2.0', 'id': 1, 'result': { 'capabilities': { 'textDocumentSync': { 'openClose': True, 'change': 2, 'save': { 'includeText': True } }, 'hoverProvider': True, 'completionProvider': { 'resolveProvider': True, 'triggerCharacters': ['.', '@', '#', '*', ' '] }, 'signatureHelpProvider': { 'triggerCharacters': ['(', ','] }, 'definitionProvider': True, 'typeDefinitionProvider': True, 'implementationProvider': True, 'referencesProvider': True, 'documentHighlightProvider': True, 'documentSymbolProvider': True, 'workspaceSymbolProvider': True, 'codeActionProvider': { 'codeActionKinds': [], 'resolveProvider': False }, 'codeLensProvider': { 'resolveProvider': True }, 'documentFormattingProvider': True, 'documentRangeFormattingProvider': True, 'documentOnTypeFormattingProvider': { 'firstTriggerCharacter': ';', 'moreTriggerCharacter': ['\n', '}'] }, 'renameProvider': { 'prepareProvider': True }, 'foldingRangeProvider': True, 'declarationProvider': True, 'executeCommandProvider': { 'commands': ['java.project.import', 'java.project.changeImportedProjects', 'java.navigate.openTypeHierarchy', 'java.project.resolveStackTraceLocation', 'java.edit.handlePasteEvent', 'java.edit.stringFormatting', 'java.project.getSettings', 'java.project.resolveWorkspaceSymbol', 'java.project.upgradeGradle', 'java.project.createModuleInfo', 'java.vm.getAllInstalls', 'java.edit.organizeImports', 'java.project.refreshDiagnostics', 'java.project.removeFromSourcePath', 'java.project.listSourcePaths', 'java.project.updateSettings', 'java.project.getAll', 'java.reloadBundles', 'java.project.isTestFile', 'java.project.resolveText', 'java.project.getClasspaths', 'java.navigate.resolveTypeHierarchy', 'java.edit.smartSemicolonDetection', 'java.project.updateSourceAttachment', 'java.project.updateClassPaths', 'java.decompile', 'java.protobuf.generateSources', 'java.project.resolveSourceAttachment', 'java.project.updateJdk', 'java.project.addToSourcePath', 'java.completion.onDidSelect'] }, 'workspace': { 'workspaceFolders': { 'supported': True, 'changeNotifications': True } }, 'typeHierarchyProvider': True, 'callHierarchyProvider': True, 'selectionRangeProvider': True, 'semanticTokensProvider': { 'legend': { 'tokenTypes': ['namespace', 'class', 'interface', 'enum', 'enumMember', 'type', 'typeParameter', 'method', 'property', 'variable', 'parameter', 'modifier', 'keyword', 'annotation', 'annotationMember', 'record', 'recordComponent'], 'tokenModifiers': ['abstract', 'static', 'readonly', 'deprecated', 'declaration', 'documentation', 'public', 'private', 'protected', 'native', 'generic', 'typeArgument', 'importDeclaration', 'constructor'] }, 'range': False, 'full': { 'delta': False }, 'documentSelector': [{ 'language': 'java', 'scheme': 'file' }, { 'language': 'java', 'scheme': 'jdt' } ] }, 'inlayHintProvider': True } } }

@rgrunber
Copy link
Contributor

rgrunber commented Oct 1, 2024

I just tried it out and it seems to be working for me.

I used a basic request like :

(formatted for readability)

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
        "initializationOptions": {
            "workspaceFolders": [
                "file:///home/rgrunber/git/lemminx"
            ],
            "settings": {
                "java": {
                    "home": "/usr/lib/jvm/java-17-openjdk-17.0.12.0.7-2.fc40.x86_64/",
                    "autobuild": {
                        "enabled": true
                    }
                }
            },
            "extendedClientCapabilities": {
                "classFileContentsSupport": true
            }
        }
    }
}

for initialization and a request like :

{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "textDocument/references",
    "params": {
        "textDocument": {
            "uri": "file:///home/rgrunber/git/lemminx/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/IOUtils.java"
        },
        "position": {
            "line": 34,
            "character": 27
        },
        "context": {
            "includeDeclaration": true
        }
    }
}

The only other thing I can think of is your offsets. When you pass a position (line/character) to the request, how are those determined ? Do you simply extract the line/character offsets from your client ? Note that the language server has 0-based line/char offsets so if your client reported lines starting from 1, you'd need to adjust that.

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

2 participants