Skip to content

Commit

Permalink
Make PositionEncodingKind a type
Browse files Browse the repository at this point in the history
As discussed here:
f9c85d5#r70968669
  • Loading branch information
michaelpj committed Apr 11, 2022
1 parent df7ab35 commit 58a21b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
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;
}
```
```
41 changes: 37 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,46 @@ 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 server and client and 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.
*/
export const UTF32: PositionEncodingKind = 'utf-32';
}
```

0 comments on commit 58a21b9

Please sign in to comment.