Sublime Forum

Having trouble getting the LSP plugin to connect to a server through TCP

#1

I am fairly new to the topic of SublimeText plugins, so I might be missing some of the basics here.

I’m trying to develop an LSP implementation for a language I am developing, and I want to have the SublimeText LSP client connect to it when I open a source file.

My LSP server is running from the terminal, and listening on localhost port 5555.

Based on the documentation, I have set up my LSP.sublime-settings configuration like so:

{
	"clients":
	{
		"rust-analyzer":
		{
			"enabled": true
		},
		"mylang-lsp":
		{
			"enabled": true,
			"tcp_port": 5555,
			"tcp_host":"localhost",
			"languages":[{
				"languageId": "mylang",
				"scopes": [
					"source.mylang"
				],
			}]
		}
	}
}

My assumption would be that based on this configuration, the LSP client would attempt to connect to my server when I open a .mylang file, but there is no connection attempt to this socket as far as I can tell. I have tried the LSP: Restart Servers command as well, and there is still no connection. Nothing is happening on the SublimeText console either, so I am a bit at a loss for how to debug this.

How can I get the LSP plugin to try to connect to my server?

0 Likes

#2

This is not supported. You cannot run a process independently of LSP. LSP owns the process (it starts it and stops it).

You can make it work by specifying a startup command:

		"mylang-lsp":
		{
			"enabled": true,
			"tcp_port": 5555,
			"command": ["/path/to/mylang-lsp-binary"],
			"languages":[{
				"languageId": "mylang",
				"scopes": [
					"source.mylang"
				],
			}]
		}

Furthermore, your languages seems out of place. If you’re using ST3 don’t forget to add a "syntaxes": ["Packages/MyLang/MyLang.sublime-syntax"] as well. If you’re using ST4, you can instead omit "scopes".

ST3 languages:

[
    {
        "languageId": "mylang",
        "scopes": ["source.mylang"],
        "syntaxes": ["Packages/MyLang/MyLang.sublime-syntax"]
    }
]

ST4 languages:

[
    {
        "languageId": "mylang"  // will match source.mylang
    }
]
0 Likes

#3

Also set log_stderr to true in Packages/User/LSP.sublime-settings. That way you can print debug messages to stderr and they’ll end up in the log panel (LSP: Toggle Log Panel from the command palette).

0 Likes

#4

Does it require a “syntaxes” field? I don’t have a sublime-syntax since the language is under development

0 Likes

#5

You need to tell LSP to what kind of views it should attach your langservers. So probably the first step for your language integration is to have a super basic .sublime-syntax. Or, you can tell LSP to attach to plaintext files if you want.

0 Likes

#6

Ok so now I have done the following:

  1. Created a syntax, located at Packages/User/mylang.sublime-syntax

  2. Updated my Packages/User/LSP.sublime-settings to look like this:

{
	"log_stderr":true,
	"log_debug":true,
  	"log_payloads": true,
	"clients":
	{
		"rust-analyzer":
		{
			"enabled": false
		},
		"mylang-lsp":
		{
			"enabled": true,
			"tcp_port": 8543,
			"command":["/Users/myuser/⁩Projects⁩/mylang/⁩lsp⁩/target/⁩debug⁩"],
			"languages":[{
				"languageId": "mylang",
				"scopes": [
					"source.mylang"
				],
				"syntaxes": ["Packages/User/mylang.sublime-syntax"]
			}]
		}
	}
}

I still don’t see anything in the console when I open my .mylang file. Is there something else I am missing?

edit:

Never mind, it was an issue with my command path, it seems to be working now. But I am not seeing the stderr output from my LSP implementation in the SublimeText console - is there any way to achieve this?

0 Likes