LSP icon indicating copy to clipboard operation
LSP copied to clipboard

positionEncoding server capability is not taken into account

Open ryuukk opened this issue 2 years ago • 8 comments

Describe the bug

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#serverCapabilities

this server capabilities is properly parsed by Sublime, it exists in the protocol, but it's never taken into account when providing various position, it only ever do it for utf16

Expected behavior If server capabilities only expect utf8, sublime should provide utf8 based positions

Environment (please complete the following information):

  • OS: Windows 10 x64
  • Sublime Text version: 4143
  • LSP version: 1.22.0

ryuukk avatar Mar 06 '23 04:03 ryuukk

It's not implemented yet, because it is relatively new.

Note that servers must support UTF-16, so

If server capabilities only expect utf8

is not possible.

jwortmann avatar Mar 06 '23 06:03 jwortmann

Indeed. And we had a lot of struggle making UTF-16 work, so why bother with additional encodings?

rwols avatar Mar 06 '23 07:03 rwols

Note that servers must support UTF-16

where do you see that?

ryuukk avatar Mar 06 '23 15:03 ryuukk

Indeed. And we had a lot of struggle making UTF-16 work, so why bother with additional encodings?

because what you gonna do if the server says: "i only can understand utf-8"?

ryuukk avatar Mar 06 '23 15:03 ryuukk

Note that servers must support UTF-16

where do you see that?

/**
	 * Character offsets count UTF-16 code units.
	 *
	 * This is the default and must always be supported
	 * by servers
	 */
	export const UTF16: [PositionEncodingKind](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#positionEncodingKind) = 'utf-16';

rchl avatar Mar 06 '23 15:03 rchl

Prior to 3.17 the offsets were always based on a UTF-16 string representation

The client announces it’s supported encoding via the client capability

To stay backwards compatible the only mandatory encoding is UTF-16 represented via the string utf-16.

ok, you are right, looks like i initially misunderstood

But still, giving the choice of utf-8, it would be nice if it was supported to satisfy server needs

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocuments

ryuukk avatar Mar 06 '23 15:03 ryuukk

The only reason I can think where it would be beneficial for the server to support other encoding than utf-16 is when it would give serious performance gains. Otherwise it's just extra work both for the server and the client to support that.

Since we don't know of any servers that would benefit from it (not counting your private one since it's not clear why you'd want utf-8 to be supported), you can probably imagine that the incentive for implementing it is very small.

That said, we have acknowledged it as a feature request.

rchl avatar Mar 06 '23 16:03 rchl

I'm just trying to make my server compliant to the specification

ryuukk avatar Mar 06 '23 21:03 ryuukk