Skip to content

Commit

Permalink
feat(amazonq): implement basic server for standard LSP completion API
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorsaws committed Jan 21, 2025
1 parent 1c38b0c commit 9f447b2
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/aws-lsp-q-dev-completions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Amazon Q Completions and Device SSO Token server

This package provides example configuration to produce Amazon Q server implementation bundled with [Language Server Standalone Runtime](https://github.com/aws/language-server-runtimes).

Language Server contains:
- `SsoAuthServer`: support for Device authentication SSO flow from [`amzn/device-sso-auth-lsp`](../../server/device-sso-auth-lsp/) package.
- `AmazonQCompletionServerToken`: experimental implementation of [Amazon Q Developer Code Completions](../../server/aws-lsp-codewhisperer/src/experimental/README.md) with standard LSP `textDocument/completion` protocol.
- `CodeWhispererServerTokenProxy`: support of Amazon Q `InlineCompletionWithReferences`.
- `QChatServerProxy`: support of Amazon Q Chat server.

## Installation and usage

To create compiled bundle run:
```bash
npm run package
```

This command will compile package and produce bundled Javascript server in `./out/` directory:
- `./out/completions-with-device-sso.js` - Amazon Q server bundled application.

To verify compiled bundle can run, you can start it in your shell with NodeJS:
```bash
node ./out/completions-with-device-sso.js --stdio
```
22 changes: 22 additions & 0 deletions app/aws-lsp-q-dev-completions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@amzn/aws-lsp-q-dev-completions",
"version": "0.0.1",
"description": "Amazon Q Developer Code Completions Language Server",
"main": "out/index.js",
"scripts": {
"clean": "rm -rf out/ bin/ tsconfig.tsbuildinfo",
"compile": "tsc --build",
"package": "npm run compile && npm run webpack",
"webpack": "webpack"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.31",
"@aws/lsp-codewhisperer": "*",
"@amzn/device-sso-auth-lsp": "*"
},
"devDependencies": {
"ts-loader": "^9.4.4",
"webpack": "^5.94.0",
"webpack-cli": "^5.1.4"
}
}
23 changes: 23 additions & 0 deletions app/aws-lsp-q-dev-completions/src/completions-with-device-sso.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { version } from '../package.json'
import { standalone } from '@aws/language-server-runtimes/runtimes'
import { RuntimeProps } from '@aws/language-server-runtimes/runtimes/runtime'
import { AmazonQCompletionServerToken } from '@aws/lsp-codewhisperer/out/experimental/amazonQCompletionServer'
import {
CodeWhispererServerTokenProxy,
QChatServerProxy,
QConfigurationServerTokenProxy,
} from '@aws/lsp-codewhisperer/out/language-server/proxy-server'
import { SsoAuthServer } from '@amzn/device-sso-auth-lsp'

const props: RuntimeProps = {
version,
servers: [
SsoAuthServer,
AmazonQCompletionServerToken,
CodeWhispererServerTokenProxy,
QConfigurationServerTokenProxy,
QChatServerProxy,
],
name: 'Amazon Q Developer Completions with Device SSO Token',
}
standalone(props)
9 changes: 9 additions & 0 deletions app/aws-lsp-q-dev-completions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./out",
"resolveJsonModule": true
},
"include": ["src"]
}
41 changes: 41 additions & 0 deletions app/aws-lsp-q-dev-completions/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var path = require('path')

const baseConfig = {
mode: 'development',
output: {
path: __dirname,
filename: 'build/[name].js',
globalObject: 'this',
library: {
type: 'umd',
},
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
}

const completionsWithDeviceSsoConfig = {
...baseConfig,
experiments: {
asyncWebAssembly: true,
},
entry: {
'amazon-q-completions-and-sso': path.join(__dirname, 'src/completions-with-device-sso.ts'),
},
resolve: {
...baseConfig.resolve,
},
target: 'node',
}

module.exports = [completionsWithDeviceSsoConfig]
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions server/aws-lsp-codewhisperer/src/experimental/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# AmazonQCompletionServer

Simple implementation of Amazon Q code completion through standard LSP `textDocument/completion` protocol.

## Configuration

The server can be configured using the following environment variables:

- `AWS_Q_REGION`: The AWS region for Amazon Q services (default: us-east-1)
- `AWS_Q_ENDPOINT_URL`: The endpoint URL for Amazon Q services

### LSP Configuration Options

`AmazonQCompletionServer` supports several LSP configuration options that can be set through the LSP client's `workspace.getConfiguration` protocol:

1. `aws.q` section:
- `customization`: (string) Sets the customization ARN for Amazon Q. To be used with [`QConfigurationServer`](../language-server/configuration/qConfigurationServer.ts)
- `preselectSuggestionFromQ`: (boolean, default: true) Determines whether suggestions from Amazon Q should be preselected in response from `textDocument/completion`.

2. `aws.codeWhisperer` section:
- `includeSuggestionsWithCodeReferences`: (boolean, default: true) Controls whether suggestions that include code references should be included in the results.
- `shareCodeWhispererContentWithAWS`: (boolean, default: false) Determines whether the content processed by CodeWhisperer should be shared with AWS for service improvement.

### Integration

Example of bundled LSP server available in [`app/aws-lsp-q-dev-completions`](../../../../app/aws-lsp-q-dev-completions/) package.
Loading

0 comments on commit 9f447b2

Please sign in to comment.