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

Refactor project structure #76

Merged
merged 14 commits into from
Mar 26, 2024
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
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ Language Server Runtimes is a JSON-RPC based protocol for interactions between s

Language Server Runtimes supports a number of host environments that each have their own underlying transport mechanisms and environment considerations, which must also support JSON-RPC communication. To see the differences between host environments, see [Runtime Host Environments](README.md#runtime-host-environments).

### Terminology
## Terminology

The server runtime will provide “Features” which refers to the Language Server Runtimes core feature (eg. LSP, Logging, etc). These features will be injected on top of the Server business logic implementation at build time. [Capabilities](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#capabilities) are a set of language features provided by an LSP.

### Server initialization flow and features negotiation

Language Server Runtimes uses LSP abstracts to create a JSON-RPC connection between client and server. We use the `Initialize` LSP lifecycle method to provide initialization options to the server.
## Project structure
The project source code is split into next directories:

Features will be instantiated and configured during execution of the `Initialize` flow of the main connection.

Client will send the `Initialize` LSP request with custom options to configure features in the optional [`InitializeParams.initializationOptions`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initializeParams) property. The configuration passed here will influence implementation details of different capabilities defined below. `initializationOptions` can be processed by the runtime and used to initialize features according to their implementation details. For information on which options are used, please see Initilization sections in each feature.
- `/src`: This directory contains all the source code of the project.
- `/protocol`: JSON-RPC-based Runtime protocol implementation in Typescript, which defines the communication between Runtime and Runtime Clients (e.g. AWS Toolkit extension).
- `/runtimes`: implementation of several runtimes (standalone, webworker) and features, that are exposed to Runtime Servers developed by Server implementors.
- `/server-interface`: defines interfaces of features, that Runtime provides to Runtime Servers implementors.
- `/testing`: testing helper for Server implementors.

## Features

Expand Down Expand Up @@ -137,6 +138,14 @@ TBD

Servers typically run as processes or web workers. Details are provided below on how to initialize each type of server runtime.

### Server initialization flow and features negotiation

Language Server Runtimes uses LSP abstracts to create a JSON-RPC connection between client and server. We use the `Initialize` LSP lifecycle method to provide initialization options to the server.

Features will be instantiated and configured during execution of the `Initialize` flow of the main connection.

Client will send the `Initialize` LSP request with custom options to configure features in the optional [`InitializeParams.initializationOptions`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initializeParams) property. The configuration passed here will influence implementation details of different capabilities defined below. `initializationOptions` can be processed by the runtime and used to initialize features according to their implementation details. For information on which options are used, please see Initilization sections in each feature.

### Standalone Server

Features and modes can be communicated to the server at startup through command line arguments. Implementation detail of the Standalone Server is that it can be started with a special `--set-credentials-encryption-key` argument to enter special flow for accepting encryption options as an argument before starting the main LSP connection.
Expand Down
358 changes: 172 additions & 186 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
"name": "@aws/language-server-runtimes",
"version": "0.1.1",
"description": "Runtimes to host Language Servers for AWS",
"main": "out/runtimes/index.js",
"files": [
"out",
"protocol",
"runtimes",
"server-interface",
"testing"
],
"repository": {
"type": "git",
"url": "https://github.com/aws/language-server-runtimes"
Expand All @@ -13,19 +19,24 @@
"node": ">=18.0.0"
},
"scripts": {
"clean": "rm -rf out",
"compile": "tsc --build",
"prepack": "npm run compile",
"test:unit": "ts-mocha -b 'src/**/*.test.ts'",
"test:prettier": "prettier . --check",
"test": "npm run test:prettier && npm run test:unit",
"fix:prettier": "prettier . --write",
"prepare": "husky install"
"prepare": "husky install",
"prepub:copyFiles": "cp .npmignore CHANGELOG.md LICENSE NOTICE README.md SECURITY.md package.json out/",
"prepub": "npm run clean && npm run test && npm run compile && npm run prepub:copyFiles",
"pub": "cd out && npm publish",
"test:prettier": "prettier . --check",
"test:unit": "ts-mocha -b 'src/**/*.test.ts'",
"test": "npm run test:prettier && npm run test:unit"
},
"dependencies": {
"jose": "^5.2.3",
"rxjs": "^7.8.1",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-textdocument": "^1.0.11"
"vscode-languageserver-protocol": "^3.17.5",
"vscode-languageserver-textdocument": "^1.0.11",
"vscode-languageserver-types": "^3.17.5"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
Expand Down
6 changes: 0 additions & 6 deletions src/features/index.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## AWS Language Servers Runtimes Protocol

Implementation of AWS Language Servers Runtimes Protocol, which defines a protocol for communication between Servers and Clients.
It is modelled after LSP, and provides several custom extensions to enable custom AWS Language Server Runtimes features.

Protocol specification can be found in main [README](https://github.com/aws/language-server-runtimes/blob/main/README.md).
49 changes: 49 additions & 0 deletions src/protocol/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ProtocolRequestType, ProtocolNotificationType0, ProtocolRequestType0 } from './lsp'

export type IamCredentials = {
readonly accessKeyId: string
readonly secretAccessKey: string
readonly sessionToken?: string
}

export type BearerCredentials = {
readonly token: string
}

export interface SsoProfileData {
startUrl?: string
}

export interface ConnectionMetadata {
sso?: SsoProfileData
}

export interface UpdateCredentialsParams {
// Plaintext Credentials (for browser based environments) or encrypted JWT token
data: IamCredentials | BearerCredentials | string
// If the payload is encrypted
// Defaults to false if undefined or null
encrypted?: boolean
}

export const iamCredentialsUpdateRequestType = new ProtocolRequestType<UpdateCredentialsParams, null, void, void, void>(
'aws/credentials/iam/update'
)

export const iamCredentialsDeleteNotificationType = new ProtocolNotificationType0<void>('aws/credentials/iam/delete')

export const bearerCredentialsUpdateRequestType = new ProtocolRequestType<
UpdateCredentialsParams,
null,
void,
void,
void
>('aws/credentials/token/update')

export const bearerCredentialsDeleteNotificationType = new ProtocolNotificationType0<void>(
'aws/credentials/token/delete'
)

export const getConnectionMetadataRequestType = new ProtocolRequestType0<ConnectionMetadata, never, void, void>(
'aws/credentials/getConnectionMetadata'
)
2 changes: 1 addition & 1 deletion src/features/chat/types.ts → src/protocol/chat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProgressToken, ProtocolNotificationType, ProtocolRequestType } from 'vscode-languageserver'
import { ProgressToken, ProtocolNotificationType, ProtocolRequestType } from './lsp'

// Chat Data Model
export interface ChatItemAction {
Expand Down
3 changes: 3 additions & 0 deletions src/protocol/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './lsp'
export * from './auth'
export * from './chat'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
InlineCompletionRegistrationOptions,
ProtocolNotificationType,
ProtocolRequestType,
} from 'vscode-languageserver'
} from './lsp'

export type InlineCompletionWithReferencesParams = InlineCompletionParams & {
// No added parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
InlineCompletionItem,
InlineCompletionList,
InlineCompletionParams,
InlineCompletionRegistrationOptions,
ProtocolRequestType,
} from 'vscode-languageserver'
InlineCompletionRegistrationOptions,
} from './lsp'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there still a copy/paste here from the 3.18 branch of vscode-languageserver?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, 3.18 LSP is not yet published


/**
* inlineCompletionRequestType defines the custom method that the language client
Expand Down
12 changes: 12 additions & 0 deletions src/protocol/lsp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export { TextDocument, Position } from 'vscode-languageserver-textdocument'

// LSP protocol is a core dependency for LSP feature provided by runtimes.
// Since we aim to provide whole range of LSP specification for Clients and Capabilities,
// we re-exporting whole LSP protocol for usage.
// Scoping it down is not practical due to large surface of protocol and types relationship.
// It will be limiting implementors, if they choose to type their code with more specific types from LSP.
export * from 'vscode-languageserver-protocol'

// Custom Runtimes LSP extensions
export * from './inlineCompletions'
export * from './inlineCompletionWithReferences'
15 changes: 15 additions & 0 deletions src/runtimes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## AWS Language Server Runtimes Implementation

Implementation of AWS Language Server runtimes and Runtimes features.

Each runtime implements a LSP server and opens communication channel with client over LSP connection. Runtime initialised all registered Capabilities.

Runtime sets up message passing, that translates Runtimes Protocol messages to a function calls to Capabilities features, defined in Server and server features interfaces.

Runtime implementation acts as a intermediate layer between Runtime Client and a Runtime Servers, injected into runtime at build time.
The runtime implements message passing between Client application and injected Servers, and interface with both by predefined APIs:
* **Runtime Protocol**: a protocol to define communication between Runtime and Client application (e.g. Runtime<->AWS Toolkit extension). It uses LSP (and JSON-RPC) connection as a transport.
* **Runtime Server Interface**: defines an interface of the Server and features exposed to Runtime Server developers (e.g. Runtime<->AWS CodeWhisperer server).


See main project [README](https://github.com/aws/language-server-runtimes/blob/main/README.md) for more detailed explanation of the architecture.
Loading