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

Make PositionEncodingKind a type #1442

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions _specifications/lsp/3.17/general/initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,6 @@ interface ClientCapabilities {
*
* If omitted it defaults to ['utf-16'].
*
* For the following standard Unicode encodings these values should be
* used:
*
* UTF-8: 'utf-8'
* UTF-16: 'utf-16'
* UTF-32: 'utf-32'
*
* Implementation considerations: since the conversion from one encoding
* into another requires the content of the file / line the conversion
* is best done where the file is read which is usually on the server
Expand All @@ -525,7 +518,7 @@ interface ClientCapabilities {
* @since 3.17.0
* @proposed
*/
positionEncodings?: ('utf-16' | 'utf-8' | 'utf-32' | string)[];
positionEncodings?: PositionEncodingKind[];
};

/**
Expand Down Expand Up @@ -621,7 +614,7 @@ interface ServerCapabilities {
* @since 3.17.0
* @proposed
*/
positionEncoding?: 'utf-16' | 'utf-8' | 'utf-32' | string;
positionEncoding?: PositionEncodingKind;

/**
* Defines how text documents are synced. Is either a detailed structure
Expand Down Expand Up @@ -873,4 +866,4 @@ interface ServerCapabilities {
*/
experimental?: LSPAny;
}
```
```
46 changes: 42 additions & 4 deletions _specifications/lsp/3.17/types/position.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,51 @@ interface Position {
line: uinteger;

/**
* Character offset on a line in a document (zero-based). Assuming that
* the line is represented as a string, the `character` value represents
* the gap between the `character` and `character + 1`.
* Character offset on a line in a document (zero-based). The meaning of this
* offset is determined by the negotiated `PositionEncodingKind`.
*
* If the character value is greater than the line length it defaults back
* to the line length.
*/
character: uinteger;
}
```
```

When describing positions the protocol needs to specify how offsets (specifically character offsets) should be interpreted.
The corresponding `PostionEncodingKind` is negotiated between the client and the server during initialization.

```typscript
/**
* A type indicating how positions are encoded,
* specifically what column offsets mean.
*/
export type PositionEncodingKind = string;

/**
* A set of predefined position encoding kinds.
*/
export namespace PositionEncodingKind {

/**
* Character offsets count UTF-8 code units.
*/
export const UTF8: PositionEncodingKind = 'utf-8';

/**
* Character offsets count UTF-16 code units.
*
* This is the default and must always be supported
* by servers
*/
export const UTF16: PositionEncodingKind = 'utf-16';

/**
* Character offsets count UTF-32 code units.
*
* Implementation note: these are the same as Unicode code points,
* so this `PositionEncodingKind` may also be used for an
* encoding-agnostic representation of character offsets.
*/
export const UTF32: PositionEncodingKind = 'utf-32';
}
```