-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools/spxls): add implementation
Fixes #1059 Signed-off-by: Aofei Sheng <[email protected]>
- Loading branch information
Showing
10 changed files
with
1,105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/goplus/builder/tools/spxls | ||
|
||
go 1.21.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* A lightweight Go+ language server for spx that runs in the browser using WebAssembly. | ||
*/ | ||
export declare class Spxls { | ||
/** | ||
* Creates a new instance of the spx language server. | ||
* | ||
* @param filesProvider - Function that provides access to the workspace files. This will be called whenever the | ||
* language server needs to access the file system. The returned map should have relative file | ||
* paths as keys and file contents values. | ||
* | ||
* @param messageReplier - Function called when the language server needs to reply to the client. The client should | ||
* handle these messages according to the LSP specification. | ||
*/ | ||
constructor(filesProvider: () => Files, messageReplier: (message: Message) => void) | ||
|
||
/** | ||
* Handles incoming LSP messages from the client. | ||
* | ||
* @param message - The message to process. Any required response will be sent via the messageReplier callback. | ||
*/ | ||
handleMessage(message: Message): void | ||
} | ||
|
||
/** | ||
* A general message as defined by JSON-RPC. The language server protocol always uses “2.0” as the `jsonrpc` version. | ||
* | ||
* See https://microsoft.github.io/language-server-protocol/specifications/base/0.9/specification/#abstractMessage. | ||
*/ | ||
export interface Message { | ||
jsonrpc: string | ||
} | ||
|
||
/** | ||
* A request message to describe a request between the client and the server. Every processed request must send a | ||
* response back to the sender of the request. | ||
* | ||
* See https://microsoft.github.io/language-server-protocol/specifications/base/0.9/specification/#requestMessage. | ||
*/ | ||
export interface RequestMessage extends Message { | ||
/** | ||
* The request id. | ||
*/ | ||
id: number | string | ||
|
||
/** | ||
* The method to be invoked. | ||
*/ | ||
method: string | ||
|
||
/** | ||
* The method's params. | ||
*/ | ||
params?: any[] | object | ||
} | ||
|
||
/** | ||
* A Response Message sent as a result of a request. If a request doesn’t provide a result value the receiver of a | ||
* request still needs to return a response message to conform to the JSON-RPC specification. The result property of the | ||
* ResponseMessage should be set to `null` in this case to signal a successful request. | ||
* | ||
* See https://microsoft.github.io/language-server-protocol/specifications/base/0.9/specification/#responseMessage. | ||
*/ | ||
export interface ResponseMessage extends Message { | ||
/** | ||
* The request id. | ||
*/ | ||
id: number | string | null | ||
|
||
/** | ||
* The result of a request. This member is REQUIRED on success. | ||
* This member MUST NOT exist if there was an error invoking the method. | ||
*/ | ||
result?: string | number | boolean | any[] | object | null | ||
|
||
/** | ||
* The error object in case a request fails. | ||
*/ | ||
error?: ResponseError | ||
} | ||
|
||
export interface ResponseError { | ||
/** | ||
* A number indicating the error type that occurred. | ||
*/ | ||
code: number | ||
|
||
/** | ||
* A string providing a short description of the error. | ||
*/ | ||
message: string | ||
|
||
/** | ||
* A primitive or structured value that contains additional | ||
* information about the error. Can be omitted. | ||
*/ | ||
data?: string | number | boolean | any[] | object | null | ||
} | ||
|
||
/** | ||
* A notification message. A processed notification message must not send a response back. They work like events. | ||
* | ||
* See https://microsoft.github.io/language-server-protocol/specifications/base/0.9/specification/#notificationMessage. | ||
*/ | ||
export interface NotificationMessage extends Message { | ||
/** | ||
* The method to be invoked. | ||
*/ | ||
method: string | ||
|
||
/** | ||
* The notification's params. | ||
*/ | ||
params?: any[] | object | ||
} | ||
|
||
/** | ||
* Map from relative path to file content. | ||
*/ | ||
export type Files = { | ||
[path: string]: Uint8Array | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright 2018 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Package jsonrpc2 is a minimal implementation of the JSON RPC 2 spec. | ||
// https://www.jsonrpc.org/specification | ||
// It is intended to be compatible with other implementations at the wire level. | ||
package jsonrpc2 |
Oops, something went wrong.