Skip to content

Commit 062e153

Browse files
committed
check wether file is already opened before opening it
1 parent 50b56b0 commit 062e153

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

aws-toolkit-vscode.code-workspace

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
{
1313
"path": "packages/amazonq",
1414
},
15+
{
16+
"path": "../language-server-runtimes",
17+
},
18+
{
19+
"path": "../language-servers",
20+
},
1521
],
1622
"settings": {
1723
"typescript.tsdk": "node_modules/typescript/lib",

packages/amazonq/.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1414
"env": {
1515
"SSMDOCUMENT_LANGUAGESERVER_PORT": "6010",
16-
"WEBPACK_DEVELOPER_SERVER": "http://localhost:8080"
16+
"WEBPACK_DEVELOPER_SERVER": "http://localhost:8080",
1717
// Below allows for overrides used during development
18-
// "__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js",
19-
// "__AMAZONQLSP_UI": "${workspaceFolder}/../../../language-servers/chat-client/build/amazonq-ui.js"
18+
"__AMAZONQLSP_PATH": "${workspaceFolder}/../../../language-servers/app/aws-lsp-codewhisperer-runtimes/out/agent-standalone.js",
19+
"__AMAZONQLSP_UI": "${workspaceFolder}/../../../language-servers/chat-client/build/amazonq-ui.js"
2020
},
2121
"envFile": "${workspaceFolder}/.local.env",
2222
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"],

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,20 @@ export function registerMessageListeners(
604604
languageClient.onRequest(openWorkspaceFileRequestType.method, async (params: OpenWorkspaceFileParams) => {
605605
try {
606606
const uri = vscode.Uri.file(params.filePath)
607-
const doc = await vscode.workspace.openTextDocument(uri)
608-
await vscode.window.showTextDocument(doc, { preview: false })
607+
608+
// Check if the file is already opened in any visible text editor
609+
const existingEditor = vscode.window.visibleTextEditors.find(
610+
(editor) => editor.document.uri.toString() === uri.toString()
611+
)
612+
613+
let doc: vscode.TextDocument
614+
if (existingEditor) {
615+
// File is already open, use the existing document
616+
doc = existingEditor.document
617+
} else {
618+
// File is not open, open it
619+
doc = await vscode.workspace.openTextDocument(uri)
620+
}
609621
if (params.makeActive) {
610622
await vscode.window.showTextDocument(doc, { preview: false, preserveFocus: false })
611623
}

0 commit comments

Comments
 (0)