Skip to content

Commit 4559e52

Browse files
committed
feat(amazonq): add diagnostics and editor controlling support for Flare
1 parent ac1e682 commit 4559e52

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

packages/amazonq/src/lsp/chat/messages.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ import {
6666
ShowOpenDialogParams,
6767
openFileDialogRequestType,
6868
OpenFileDialogResult,
69+
CheckDiagnosticsRequestType,
70+
CheckDiagnosticsParams,
71+
openWorkspaceFileRequestType,
72+
OpenWorkspaceFileParams,
6973
} from '@aws/language-server-runtimes/protocol'
7074
import { v4 as uuidv4 } from 'uuid'
7175
import * as vscode from 'vscode'
@@ -559,6 +563,58 @@ export function registerMessageListeners(
559563

560564
registerHandlerWithResponseRouter(openTabRequestType.method)
561565
registerHandlerWithResponseRouter(getSerializedChatRequestType.method)
566+
// Register diagnostic check handler
567+
languageClient.onRequest(CheckDiagnosticsRequestType.method, async (params: CheckDiagnosticsParams) => {
568+
const result: Record<string, any> = {}
569+
570+
for (const [filePath, diagnosticJson] of Object.entries(params.filePaths)) {
571+
try {
572+
const uri = vscode.Uri.file(filePath)
573+
const diagnostics = vscode.languages.getDiagnostics(uri)
574+
575+
if (diagnostics && diagnostics.length > 0) {
576+
// Convert VSCode diagnostics to JSON format
577+
const diagnosticsJson = diagnostics.map((diagnostic) => ({
578+
range: {
579+
start: {
580+
line: diagnostic.range.start.line,
581+
character: diagnostic.range.start.character,
582+
},
583+
end: { line: diagnostic.range.end.line, character: diagnostic.range.end.character },
584+
},
585+
severity: diagnostic.severity,
586+
message: diagnostic.message,
587+
source: diagnostic.source,
588+
code: diagnostic.code,
589+
}))
590+
result[filePath] = diagnosticsJson
591+
} else {
592+
// No diagnostics found, return the original or empty
593+
result[filePath] = diagnosticJson || []
594+
}
595+
} catch (error) {
596+
languageClient.error(`Failed to get diagnostics for ${filePath}: ${error}`)
597+
result[filePath] = diagnosticJson || []
598+
}
599+
}
600+
return { filePaths: result }
601+
})
602+
603+
// Register openWorkspaceFile handler
604+
languageClient.onRequest(openWorkspaceFileRequestType.method, async (params: OpenWorkspaceFileParams) => {
605+
try {
606+
const uri = vscode.Uri.file(params.filePath)
607+
const doc = await vscode.workspace.openTextDocument(uri)
608+
await vscode.window.showTextDocument(doc, { preview: false })
609+
if (params.makeActive) {
610+
await vscode.window.showTextDocument(doc, { preview: false, preserveFocus: false })
611+
}
612+
return { success: true }
613+
} catch (error) {
614+
languageClient.error(`Failed to open workspace file ${params.filePath}: ${error}`)
615+
return { success: false }
616+
}
617+
})
562618

563619
languageClient.onRequest(ShowSaveFileDialogRequestType.method, async (params: ShowSaveFileDialogParams) => {
564620
const filters: Record<string, string[]> = {}

0 commit comments

Comments
 (0)