Skip to content

Commit b91bcad

Browse files
authored
Map LSPAny to any (#927)
1 parent e214ef6 commit b91bcad

4 files changed

Lines changed: 34 additions & 23 deletions

File tree

client/src/common/notebook.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as minimatch from 'minimatch';
99

1010
import * as proto from 'vscode-languageserver-protocol';
1111
import {
12-
StaticRegistrationOptions, NotebookDocumentFilter, LSPObject, LSPArray, TextDocumentItem, NotebookCellTextDocumentFilter
12+
StaticRegistrationOptions, NotebookDocumentFilter, TextDocumentItem, NotebookCellTextDocumentFilter, LSPAny
1313
} from 'vscode-languageserver-protocol';
1414

1515
import * as UUID from './utils/uuid';
@@ -27,6 +27,9 @@ function ensure<T, K extends keyof T>(target: T, key: K): T[K] {
2727
return target[key];
2828
}
2929

30+
type LSPObject = { [key: string]: LSPAny };
31+
type LSPArray = LSPAny[];
32+
3033
namespace Converter {
3134
export namespace c2p {
3235
export function asVersionedNotebookDocumentIdentifier(notebookDocument: vscode.NotebookDocument, base: _c2p.Converter): proto.VersionedNotebookDocumentIdentifier {

protocol/src/common/protocol.notebook.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* ------------------------------------------------------------------------------------------ */
55

66
import {
7-
URI, integer, DocumentUri, uinteger, LSPAny, LSPObject, TextDocumentItem, TextDocumentIdentifier,
7+
URI, integer, DocumentUri, uinteger, LSPAny, TextDocumentItem, TextDocumentIdentifier,
88
VersionedTextDocumentIdentifier
99
} from 'vscode-languageserver-types';
1010

@@ -123,8 +123,10 @@ export type NotebookCell = {
123123

124124
/**
125125
* Additional metadata stored with the cell.
126+
*
127+
* Note: should always be an object literal (e.g. LSPObject)
126128
*/
127-
metadata?: LSPObject;
129+
metadata?: LSPAny;
128130

129131
/**
130132
* Additional execution summary information
@@ -165,6 +167,7 @@ export namespace NotebookCell {
165167
}
166168

167169
function equalsMetadata(one: LSPAny | undefined, other: LSPAny | undefined): boolean {
170+
type LSPObject = { [key: string]: LSPAny };
168171
if (one === other) {
169172
return true;
170173
}
@@ -244,8 +247,10 @@ export type NotebookDocument = {
244247
/**
245248
* Additional metadata stored with the notebook
246249
* document.
250+
*
251+
* Note: should always be an object literal (e.g. LSPObject)
247252
*/
248-
metadata?: LSPObject;
253+
metadata?: LSPAny;
249254

250255
/**
251256
* The cells of a notebook.
@@ -440,8 +445,10 @@ export namespace NotebookCellArrayChange {
440445
export type NotebookDocumentChangeEvent = {
441446
/**
442447
* The changed meta data if any.
448+
*
449+
* Note: should always be an object literal (e.g. LSPObject)
443450
*/
444-
metadata?: LSPObject;
451+
metadata?: LSPAny;
445452

446453
/**
447454
* Changes to cells

server/src/common/notebook.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
'use strict';
66

77
import {
8-
NotificationHandler1, Emitter, Event, LSPObject, DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
8+
NotificationHandler1, Emitter, Event, DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
99
NotificationHandler, DocumentUri, URI, Disposable, DidOpenNotebookDocumentParams, DidChangeNotebookDocumentParams, DidSaveNotebookDocumentParams,
1010
DidCloseNotebookDocumentParams, DidOpenNotebookDocumentNotification, DidChangeNotebookDocumentNotification, DidSaveNotebookDocumentNotification,
11-
DidCloseNotebookDocumentNotification, NotebookDocument, NotebookCell
11+
DidCloseNotebookDocumentNotification, NotebookDocument, NotebookCell, LSPAny
1212
} from 'vscode-languageserver-protocol';
1313

1414
import type { Feature, _Notebooks, Connection, } from './server';
@@ -67,8 +67,10 @@ export type NotebookDocumentChangeEvent = {
6767

6868
/**
6969
* The meta data change if any.
70+
*
71+
* Note: old and new should always be an object literal (e.g. LSPObject)
7072
*/
71-
metadata?: { old: LSPObject | undefined; new: LSPObject | undefined };
73+
metadata?: { old: LSPAny | undefined; new: LSPAny | undefined };
7274

7375
/**
7476
* The cell changes if any.

types/src/main.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,27 @@ export type decimal = number;
6767
/**
6868
* The LSP any type.
6969
*
70+
* In the current implementation we map LSPAny to any. This is due to the fact
71+
* that the TypeScript compilers can't infer string access signatures for
72+
* interface correctly (it can though for types). See the following issue for
73+
* details: https://github.com/microsoft/TypeScript/issues/15300.
74+
*
75+
* When the issue is addressed LSPAny can be defined as follows:
76+
*
77+
* ```ts
78+
* export type LSPAny = LSPObject | LSPArray | string | integer | uinteger | decimal | boolean | null | undefined;
79+
* export type LSPObject = { [key: string]: LSPAny };
80+
* export type LSPArray = LSPAny[];
81+
* ```
82+
*
7083
* Please note that strictly speaking a property with the value `undefined`
7184
* can't be converted into JSON preserving the property name. However for
7285
* convenience it is allowed and assumed that all these properties are
7386
* optional as well.
7487
*
7588
* @since 3.17.0
7689
*/
77-
export type LSPAny = LSPObject | LSPArray | string | integer | uinteger | decimal | boolean | null | undefined;
78-
79-
/**
80-
* LSP object definition.
81-
*
82-
* @since 3.17.0
83-
*/
84-
export type LSPObject = { [key: string]: LSPAny };
85-
86-
/**
87-
* LSP arrays.
88-
*
89-
* @since 3.17.0
90-
*/
91-
export type LSPArray = LSPAny[];
90+
export type LSPAny = any;
9291

9392
/**
9493
* Position in a text document expressed as zero-based line and character

0 commit comments

Comments
 (0)