BowlerHatLLC / vscode-as3mxml

ActionScript & MXML language extension for Visual Studio Code. Develop apps for Adobe AIR, Adobe Flash Player, or Apache Royale.
https://as3mxml.com/
Apache License 2.0
257 stars 39 forks source link

Help making AS3MXML LSP work in Panic Nova #774

Open AmigaAbattoir opened 1 week ago

AmigaAbattoir commented 1 week ago

Hello, I'm trying to make an extension for Panic's Nova and use this for an LSP. Out of the box, I got some functionality working, like issues, but could not get hovering to work. I noticed that Nova does not send a request textDocument/didOpen like VSCode does. But, when I try manually invoking I get it runs textDocument/publishDiagnostics on the files in the project, and then I get an error:

org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer fireError
SEVERE: Cannot invoke "java.util.concurrent.CompletableFuture.thenAccept(java.util.function.Consumer)" because "future" is null
java.lang.NullPointerException: Cannot invoke "java.util.concurrent.CompletableFuture.thenAccept(java.util.function.Consumer)" because "future" is null
org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:279)
org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
org.eclipse.lsp4j.jsonrpc.TracingMessageConsumer.consume(TracingMessageConsumer.java:114)
org.eclipse.lsp4j.jsonrpc.validation.ReflectiveMessageValidator.consume(ReflectiveMessageValidator.java:68)
org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
java.base/java.lang.Thread.run(Thread.java:833)

I also get this on textDocument/didClose, textDocument/textChange. I was wondering if you had any suggestion on where to start digging into this.

AmigaAbattoir commented 5 days ago

Okay, got a little further. Looks like I was doing a sendRequest instead of sendNotification! Once that was switched, the error no longer appears.

While I do get the issues in Nova, I do not get any of the hovers (which I'm really wanting to get working).

Comparing what happens in VS Code, it looks like this is the chain of events:

  1. sendRequest "initialize"
  2. sendNotification "initialize"
  3. sendNotification "textDocument/didOpen"
  4. sendNotification "workspace/didChangeConfiguration"
  5. sendRequest "workspace/executeCommand" with something like:
    "command": "as3mxml.setRoyalePreferredTarget",
    "arguments": [
        "SWF"
    ]

In Nova, step 1 and 2 happen, but 3 - 5 do not. Are there any other steps I would need to make the hover capability work?

joshtynjala commented 4 days ago

textDocument/didOpen Is a pretty vital notification in the language server protocol. It’s unlikely you’ll get anything to work well if your editor doesn’t send it.

The remaining ones after textDocument/didOpen probably aren’t strictly required, but there’s no way for the language server to track changes to an unsaved file without textDocument/didOpen.

joshtynjala commented 4 days ago

sendNotification "initialize"

I believe that this should be initialized instead.

AmigaAbattoir commented 2 days ago

Turns out Nova does send the notification initialized by itself so without much in the extension I can get it to do:

  1. Sending request initialize
  2. Received response initialize
  3. Sending notification initialized

then it receives a bunch of notifications of textDocument/publishDiagnostics

Looking at VSCode, opening the same folder without opening any files, it ends up doing this:

  1. Sending request initialize
  2. Received response initialize
  3. Sending notification initialized
  4. Sending notification workspace/didChangeConfiguration
  5. Sending request workspace/executeCommand (sending command as3mxml.setRoyalePreferredTarget)
  6. Received request client/registerCapability
  7. Sending response client/registerCapability
  8. Received notification as3mxml/setActionScriptActive

then it receives a bunch of notifications of textDocument/publishDiagnostics

I tried sending the notification of workspace/didChangeConfiguration and the request of workspace/executeCommand, but I do not receive a request for client/registerCapability and no notification of as3mxml/setActionScriptActive. I was wondering if I am missing along the way.

I also added to my extension to signal when an ActionScript or MXML file is opened, it will send notifications that didOpen and didClose. When looking at VSCode, when didOpen happens it is then followed by textDocument/documentSymbol, textDocument/codeAction. I tried calling that and get the results. Still no hovers. :-(

joshtynjala commented 1 day ago

Sending notification workspace/didChangeConfiguration

With this notification, VSCode sends any settings that the language server would be interested in (anything staring with as3mxml., basically). I don't think it's strictly required.

Received request client/registerCapability

This is sent by the as3mxml language server when it receives the initialized notification. It is sent only if the editor supports dynamic registration of capabilities, and is not strictly required.

Received notification as3mxml/setActionScriptActive

This is sent only if a specific field is set on the initialization options. It's used by the VSCode extension to update some GUI items. Other editors generally don't need this, so it's normal that you aren't getting it.

then it receives a bunch of notifications of textDocument/publishDiagnostics

This means that the project has been correctly detected, and it is returning compiler errors/warnings for each file.

As best I can tell, you are starting everything correctly. I don't know why Nova would be deciding not to send hover requests to the language server.