Skip to content

Commit

Permalink
Map LSPAny to any (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaeumer authored May 5, 2022
1 parent e214ef6 commit b91bcad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
5 changes: 4 additions & 1 deletion client/src/common/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as minimatch from 'minimatch';

import * as proto from 'vscode-languageserver-protocol';
import {
StaticRegistrationOptions, NotebookDocumentFilter, LSPObject, LSPArray, TextDocumentItem, NotebookCellTextDocumentFilter
StaticRegistrationOptions, NotebookDocumentFilter, TextDocumentItem, NotebookCellTextDocumentFilter, LSPAny
} from 'vscode-languageserver-protocol';

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

type LSPObject = { [key: string]: LSPAny };
type LSPArray = LSPAny[];

namespace Converter {
export namespace c2p {
export function asVersionedNotebookDocumentIdentifier(notebookDocument: vscode.NotebookDocument, base: _c2p.Converter): proto.VersionedNotebookDocumentIdentifier {
Expand Down
15 changes: 11 additions & 4 deletions protocol/src/common/protocol.notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* ------------------------------------------------------------------------------------------ */

import {
URI, integer, DocumentUri, uinteger, LSPAny, LSPObject, TextDocumentItem, TextDocumentIdentifier,
URI, integer, DocumentUri, uinteger, LSPAny, TextDocumentItem, TextDocumentIdentifier,
VersionedTextDocumentIdentifier
} from 'vscode-languageserver-types';

Expand Down Expand Up @@ -123,8 +123,10 @@ export type NotebookCell = {

/**
* Additional metadata stored with the cell.
*
* Note: should always be an object literal (e.g. LSPObject)
*/
metadata?: LSPObject;
metadata?: LSPAny;

/**
* Additional execution summary information
Expand Down Expand Up @@ -165,6 +167,7 @@ export namespace NotebookCell {
}

function equalsMetadata(one: LSPAny | undefined, other: LSPAny | undefined): boolean {
type LSPObject = { [key: string]: LSPAny };
if (one === other) {
return true;
}
Expand Down Expand Up @@ -244,8 +247,10 @@ export type NotebookDocument = {
/**
* Additional metadata stored with the notebook
* document.
*
* Note: should always be an object literal (e.g. LSPObject)
*/
metadata?: LSPObject;
metadata?: LSPAny;

/**
* The cells of a notebook.
Expand Down Expand Up @@ -440,8 +445,10 @@ export namespace NotebookCellArrayChange {
export type NotebookDocumentChangeEvent = {
/**
* The changed meta data if any.
*
* Note: should always be an object literal (e.g. LSPObject)
*/
metadata?: LSPObject;
metadata?: LSPAny;

/**
* Changes to cells
Expand Down
8 changes: 5 additions & 3 deletions server/src/common/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
'use strict';

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

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

/**
* The meta data change if any.
*
* Note: old and new should always be an object literal (e.g. LSPObject)
*/
metadata?: { old: LSPObject | undefined; new: LSPObject | undefined };
metadata?: { old: LSPAny | undefined; new: LSPAny | undefined };

/**
* The cell changes if any.
Expand Down
29 changes: 14 additions & 15 deletions types/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,27 @@ export type decimal = number;
/**
* The LSP any type.
*
* In the current implementation we map LSPAny to any. This is due to the fact
* that the TypeScript compilers can't infer string access signatures for
* interface correctly (it can though for types). See the following issue for
* details: https://github.com/microsoft/TypeScript/issues/15300.
*
* When the issue is addressed LSPAny can be defined as follows:
*
* ```ts
* export type LSPAny = LSPObject | LSPArray | string | integer | uinteger | decimal | boolean | null | undefined;
* export type LSPObject = { [key: string]: LSPAny };
* export type LSPArray = LSPAny[];
* ```
*
* Please note that strictly speaking a property with the value `undefined`
* can't be converted into JSON preserving the property name. However for
* convenience it is allowed and assumed that all these properties are
* optional as well.
*
* @since 3.17.0
*/
export type LSPAny = LSPObject | LSPArray | string | integer | uinteger | decimal | boolean | null | undefined;

/**
* LSP object definition.
*
* @since 3.17.0
*/
export type LSPObject = { [key: string]: LSPAny };

/**
* LSP arrays.
*
* @since 3.17.0
*/
export type LSPArray = LSPAny[];
export type LSPAny = any;

/**
* Position in a text document expressed as zero-based line and character
Expand Down

0 comments on commit b91bcad

Please sign in to comment.