LSP integration only working with diagnostics, not completions or jumping

Answered

Hi. I am developing a TypeScript plugin which adds custom element handling inside of tagged template literals, using the language server protocol. It is currently still in development, but is working well in NeoVim and VSCode.

Since 2023.2 it looks like JetBrains IDEs support LSP too. I have just setup IntelliJ IDEA Ultimate for testing, and out of the box the diagnostics functionality of the LSP is working.

The above image shows that the property binding `:curry` doesn't exist on the custom element `person-avatar`, which is correct. The diagnostics functionality is matching what I am seeing in the other two editors that I am working with.

However, the completions and jump to definitions functionality is not working correctly. When I attempt to create a completion I don't get some of the values from the LSP, and when I checked the logs it seems that IntelliJ isn't requesting the completions function of the plugin (I am not seeing a log which I am for the other two editors). It also seems that the jump to definition, and quick-info functionality I have implemented is not working whatsoever in IntelliJ. 

I did wonder if IntelliJ wasn't using the LSP at all and just has the diagnostics functionality anyway, though it does look in my logs like it is saying IntelliJ is the LSP client and that the diagnostics functions I have written are being called. 

Does anyone have any ideas what the issue could be? Do I need to add some more configuration options to be able to get it working properly? Do I need to follow the plugin configuration steps as explained here even though this is just a typescript project, and is not using gradle/java/scala etc?

0
11 comments
Official comment

Hi. LSP-based code completion and Go To Declaration (Ctrl+B / Cmd+B or Ctlr+click / Cmd+click) should work out of the box as well as code highlighting. (Hover info - not yet.) I can check your logs if you want. Please add #com.intellij.platform.lsp to Help → Diagnostic Tools → Debug Log Settings, reproduce the problem (not working completion and Cmd+click) and attach your logs. Feel free to contact our support team privately if you don't want to share your logs publicly right here.

Hi Alexander. Thanks for the tip, that sounds useful. I have added that line into the setting box you instructed, but I can't see what the logs are supposed to look like. Where am I expecting to see them? 

Is it inline with the logs that the LSP produces which is controlled via the `TSS_LOG` environment variable? I can see still that IntelliJ is the LSP client, but I can't see any logs from the client specifically in that file (that are not the logs that were already there from my plugin code).

EDIT: After looking at this page, is it the `idea.log` file I should be looking at?

0

You can find logs using Help → Show Log (or Help → Open Log or Help → Collect Logs And Diagnostics Data). The file name is idea.log

If you start an IDE from the IDE (this is what you usually do when developing a plugin), make sure you add #com.intellij.platform.lsp to the IDE that you start from sources, not to the ‘working’ IDE.


Related: https://plugins.jetbrains.com/docs/intellij/ide-infrastructure.html#logging

0

Ok, so they are the same logs that I had come across. I can't see any reference to any LSP activity, though perhaps I am just missing something. I do note though that the setting I applied is being picked up as you can see on the line here

2023-08-30 10:17:03,518 [    562]   INFO - #c.i.d.DebugLogManager - Set DEBUG for the following categories: #com.intellij.platform.lsp, com.intellij.platform.lsp

Please see attached the logs for a run where I startup the LSP and then attempt to load a jump to definition with `cmd-b`. I can see a stack trace relating to a “unexpected duplicated roots ” error with node modules, so perhaps that is related? Though as I had shown in my original message, the diagnostics functionality from my LSP plugin is working. So it isn't like the plugin is completely failing to run.

...
2023-08-30 10:17:06,312 [   3356]   INFO - #c.i.o.v.i.p.NewMappings - VCS Root: [Git] - [/Users/matt.walker/genesis/custom-elements-lsp]
...

0

(I truncated the logs)

Looks like these are logs of your ‘working’ IDE. It doesn't contain the plugin that you develop, and doesn't contains any logs from it. You need to add logs to the ‘debugged’ IDE  - the one that starts from sources.

BTW, see here how to get logs from the debugged IDE right in your working IDE: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin-faq.html#how-to-show-log-file-of-sandbox-instance

0

Thanks for the link. Just to confirm with you before I follow the instructions provided, that will create an instance of IntelliJ IDEA which will combine the logs from `idea.log` and the logs I am producing which are saved in the area controlled via the environment variable `TSS_LOG`?

I am only querying because I don't quite see that my current setup aligns with what has been mentioned previously. I am not using a “working” IDE which launches a “debugging” IDE which is developing the plugin, the plugin is just working anyway. I am not creating a new LSP which is a plugin for IntelliJ, I am creating a plugin for typescript (plugin for `tsserver.js`) which I set by pointing to the version in the node modules here.

0

Sorry, there seems to be some misunderstanding from the very beginning. 

This channel is called “IntelliJ IDEA Open API and Plugin Development”, so I assumed you were writing a plugin for IntelliJ-based IDEs, which means writing Java and Kotlin code and using IntelliJ Open API. You mentioned LSP API, so I assumed you were following the instructions from https://jb.gg/lsp

Looks like all my answers were not relevant.

TypeScript support in commercial IntelliJ-based IDEs is indeed partially based on the TypeScript Language Server. This, however, is not anyhow connected with the LSP API for plugin developers, documented in https://jb.gg/lsp

As I understand, you've substituted the standard TypeScript LS with the custom one that includes your plugin, is this correct? TS LS is used only partially for TS support. Most of the features are implemented without using the server. Some features may have both internal and server-based implementation. Unfortunately, JS/TS support is not open-source. So you can't expect your plugin to work 100% out-of-the-box. It's good luck that you've got errors highlighting from your plugin but it might be not easy or possible to get other server-based features working. You say you see the server logs, so you know what the IDE asks for and what the server answers. Unfortunately, you can't see what the IDE is doing with the server results. Server-based code completion, navigation, and hovers may work in some cases but if they don't, you can't debug how to fix that, unfortunately.

0

I see, that answer does make sense with what I am observing. For example:

  1. I observe the diagnostics enhancements which I have built into my pluign. That implies that IntelliJ is using the typescript server to implement that, hence it is getting my plugin improvements.
  2. I observe not getting any quickinfo/jump to definition functionality from my plugin. That implies that IntelliJ is doing its own thing for this functionality.
  3. I observe partial functionality for autocompletion for things like custom element tag names. This was really confusing me but I think I now understand. I am seeing completion for library elements which ship with their own `custom-elements.json` manifest file, but not any of the source code. This implies that IntelliJ is again doing its own thing, and it is based on using the manifest files directly. 

From what I now understand, I think what I need to do is to write a JetBrains IDE plugin with Open API, which basically wraps tsserver with my plugin. Not a quick job, but I think that should be possible. Let me know if you agree/disagree with that assessment. 

Thanks for taking the time to reply for this thread.

0

So, there are 2 ways of solving your task: using the closed-source JavaScript/TypeScript plugin (this is what you are trying at the moment), and writing a separate plugin.

The former way depends on JetBrains a lot, as it is based on the closed-source part. If you go this way, the only thing you can do is filing a YouTrack issue with a detailed description of what you are trying to achieve, and hoping that it will be fixed eventually. TS support is being reworked, so there are chances that it will be done in 2023.3

The custom plugin gives you more control as you are using the official public API. From the architectural point of view, it's not great that two instances of TS server will be running in parallel. That's the price for controlling the functionality. Also, you'll probably need to filter out unneeded info from the server so that only your plugin contributes but not the rest of the TS server.

0

Makes sense to me. I am keen for now to raise a YouTrack issue, where exactly should I raise that? When I search for YouTrack online it just comes up with the product that you offer rather than using it to raise the IntelliJ query. Also, do you recommend I raise this against IntelliJ, or Fleet? 

0

The issue tracker is https://youtrack.jetbrains.com

TypeScript support is the WebStorm team responsibility, so the right project is WebStorm. I assume we were talking about IntelliJ Platform-based IDEs. Fleet is a different story, all my answers were not related to Fleet.

0

Please sign in to leave a comment.