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

Wait for jdtls ServiceReady to call the custom method after #711 #712

Closed

Conversation

JavaHello
Copy link
Contributor

Copy link
Owner

@mfussenegger mfussenegger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works like this.

  • Users could override the handler. nvim-jdtls prefers the user-configured one over its own to allow disabling the cmdline messages. See

    config.handlers['language/status'] = config.handlers['language/status'] or status_callback

  • The state is global, so it won't work for multiple clients or will trip up if one is restarted.

I'm also not sure why this would need the coroutine handling. Can you understand a bit more on the use-case?

@JavaHello
Copy link
Contributor Author

JavaHello commented Nov 1, 2024

  • use-case

                jdtls                                                  sonarlint.nvim
     ┌─────────────────────────────┐                           ┌─────────────────────────────┐
     │                             │     sonarline on_init     │                             │
     │ java.project.getClasspaths  │◄──────────────────────────│ sonarlint/getJavaConfig     │
     │                             │──────────────────────────►│                             │
     │                             │    classpathUpdated       │                             │
     │ language/eventNotification  │──────────────────────────►│ sonarlint/didClasspathUpdate│
     │                             │                           │                             │
     └─────────────────────────────┘                           └─────────────────────────────┘
     function M.install_classpath_listener()
        if M._classpath_change_listener then
           return
        end
        M._classpath_change_listener = true
        get_jdtls_client().config.handlers["language/eventNotification"] = function(_, msg)
           if msg.eventType == "classpathUpdated" then
              get_sonarlint_client().notify("sonarlint/didClasspathUpdate", {
                 projectUri = msg.data,
              })
           end
        end
     end
     sonarlint.config.on_init = function()
        sonarlint.config.handlers["sonarlint/getJavaConfig"] = function(err, file_uri)
           local params = {
              file_uri = file_uri,
           }
           return wait_jdtls_server_ready(function()
              install_classpath_listener()
              return get_jdtls_client().request_sync("java.project.getClasspaths", params)
           end)
        end
     end
  • opening a java file starts jdtls, sonarlint.nvim at the same time. if jdtls is not available, sonarlint.nvim will not work properly

  • Reason for using coroutine: I checked that sonarlint-vscode uses await extension?.activate(); but I don't know how to do that in nvim. so I use coroutine to make sure that jdtls is available after sonarlint.nvim has been started

@JavaHello
Copy link
Contributor Author

Yes, it may be easier to override the nvim-jdtls configuration. Add the configuration in jdtls.on_init

@JavaHello JavaHello closed this Nov 5, 2024
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.

2 participants