Skip to content

Commit 9d4f971

Browse files
authored
docs(amazonq): Add instructions for debugging flare lsps (#6455)
## Problem It's painful to setup debugging with flare ## Solution Add instructions to make it easy --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b87bd0d commit 9d4f971

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

docs/lsp-debugging.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Language Server Debugging
2+
3+
1. Clone https://github.com/aws/language-servers.git and set it up in the same workspace as this project
4+
5+
e.g.
6+
7+
```
8+
/aws-toolkit-vscode
9+
/toolkit
10+
/core
11+
/amazonq
12+
/language-servers
13+
```
14+
15+
2. Inside of the language-servers project run:
16+
```
17+
npm install
18+
npm run compile
19+
npm run package
20+
```
21+
to get the project setup
22+
3. Uncomment the `AWS_LANGUAGE_SERVER_OVERRIDE` variable in `amazonq/.vscode/launch.json` Extension configuration
23+
4. Use the `Launch LSP with Debugging` configuration and set breakpoints in VSCode or the language server

packages/amazonq/.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"env": {
2020
"SSMDOCUMENT_LANGUAGESERVER_PORT": "6010",
2121
"WEBPACK_DEVELOPER_SERVER": "http://localhost:8080"
22+
// "AWS_LANGUAGE_SERVER_OVERRIDE": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/token-standalone.js",
2223
},
2324
"envFile": "${workspaceFolder}/.local.env",
2425
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"],
@@ -140,6 +141,31 @@
140141
"group": "4_E2ETestCurrentFile",
141142
"order": 2
142143
}
144+
},
145+
{
146+
"name": "Attach to Language Server",
147+
"type": "node",
148+
"request": "attach",
149+
"port": 6080, // Hard defined in core/src/shared/lsp/platform.ts
150+
"outFiles": ["${workspaceFolder}/../../../language-servers/**/out/**/*.js"],
151+
"skipFiles": [
152+
"<node_internals>/**",
153+
"${workspaceFolder}/../../../language-servers/**/node_modules/**/*.js"
154+
],
155+
"restart": {
156+
"maxAttempts": 10,
157+
"delay": 1000
158+
}
159+
}
160+
],
161+
"compounds": [
162+
{
163+
"name": "Launch LSP with Debugging",
164+
"configurations": ["Extension", "Attach to Language Server"],
165+
"presentation": {
166+
"group": "1_Extension",
167+
"order": 5
168+
}
143169
}
144170
]
145171
}

packages/amazonq/src/lsp/client.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import vscode, { env, version } from 'vscode'
77
import * as nls from 'vscode-nls'
88
import * as crypto from 'crypto'
9-
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient'
9+
import { LanguageClient, LanguageClientOptions } from 'vscode-languageclient'
1010
import { registerInlineCompletion } from '../app/inline/completion'
1111
import { AmazonQLspAuth, encryptionKey, notificationTypes } from './auth'
1212
import { AuthUtil } from 'aws-core-vscode/codewhisperer'
@@ -18,32 +18,19 @@ const localize = nls.loadMessageBundle()
1818
export async function startLanguageServer(extensionContext: vscode.ExtensionContext, resourcePaths: ResourcePaths) {
1919
const toDispose = extensionContext.subscriptions
2020

21-
// The debug options for the server
22-
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
23-
const debugOptions = {
21+
const serverModule = resourcePaths.lsp
22+
23+
const serverOptions = createServerOptions({
24+
encryptionKey,
25+
executable: resourcePaths.node,
26+
serverModule,
2427
execArgv: [
2528
'--nolazy',
2629
'--preserve-symlinks',
2730
'--stdio',
2831
'--pre-init-encryption',
2932
'--set-credentials-encryption-key',
3033
],
31-
}
32-
33-
const serverModule = resourcePaths.lsp
34-
35-
// If the extension is launch in debug mode the debug server options are use
36-
// Otherwise the run options are used
37-
let serverOptions: ServerOptions = {
38-
run: { module: serverModule, transport: TransportKind.ipc },
39-
debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions },
40-
}
41-
42-
serverOptions = createServerOptions({
43-
encryptionKey,
44-
executable: resourcePaths.node,
45-
serverModule,
46-
execArgv: debugOptions.execArgv,
4734
})
4835

4936
const documentSelector = [{ scheme: 'file', language: '*' }]

packages/core/src/shared/lsp/utils/platform.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { ToolkitError } from '../../errors'
77
import { ChildProcess } from '../../utilities/processUtils'
8+
import { isDebugInstance } from '../../vscode/env'
89

910
export function getNodeExecutableName(): string {
1011
return process.platform === 'win32' ? 'node.exe' : 'node'
@@ -35,7 +36,8 @@ export function createServerOptions({
3536
execArgv: string[]
3637
}) {
3738
return async () => {
38-
const lspProcess = new ChildProcess(executable, [serverModule, ...execArgv])
39+
const debugArgs = isDebugInstance() ? '--inspect=6080' : ''
40+
const lspProcess = new ChildProcess(executable, [debugArgs, serverModule, ...execArgv])
3941

4042
// this is a long running process, awaiting it will never resolve
4143
void lspProcess.run()

0 commit comments

Comments
 (0)