-
Notifications
You must be signed in to change notification settings - Fork 251
feat(amazonq): implement workspace file messages #5377
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
Changes from 2 commits
686fda2
a5250b5
0efb633
788e833
429f5e9
aababb6
c3d855a
f826372
fad4467
ffa167a
94c25e4
87817ea
d495450
7cff72e
70b7e53
eaa993a
d139dc4
5458f0c
0628cae
3f2a98d
401826d
780395e
8ee75f8
de16193
ec5bfbe
62adbc1
450e416
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.amazonq.lsp.workspace | ||
|
||
import com.intellij.openapi.Disposable | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFileManager | ||
import com.intellij.openapi.vfs.newvfs.BulkFileListener | ||
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent | ||
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent | ||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent | ||
import org.eclipse.lsp4j.CreateFilesParams | ||
import org.eclipse.lsp4j.DeleteFilesParams | ||
import org.eclipse.lsp4j.FileCreate | ||
import org.eclipse.lsp4j.FileDelete | ||
import software.aws.toolkits.jetbrains.services.amazonq.lsp.AmazonQLanguageServer | ||
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread | ||
|
||
class WorkspaceServiceHandler( | ||
private val project: Project, | ||
private val languageServer: AmazonQLanguageServer, | ||
) : Disposable { | ||
|
||
fun startWorkspaceServiceListeners() { | ||
startFileLifecycleListener() | ||
} | ||
samgst-amazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private fun didCreateFiles(events: List<VFileEvent>){ | ||
if (events.isNotEmpty()) { | ||
languageServer.workspaceService.didCreateFiles( | ||
CreateFilesParams().apply { | ||
files = events.map { event -> | ||
FileCreate().apply { | ||
uri = event.file?.toNioPath()?.toUri().toString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets make a util for virtualfile -> URI because we will likely have a lot of edge cases to deal with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if there is no file we should not emit an event There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought this would be handled by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess i meant if the uri is null then we shouldn't emit an event because that doesn't seem useful |
||
} | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun didDeleteFiles(events: List<VFileEvent>) { | ||
if (events.isNotEmpty()) { | ||
languageServer.workspaceService.didDeleteFiles( | ||
DeleteFilesParams().apply { | ||
files = events.map { event -> | ||
FileDelete().apply { | ||
uri = event.file?.toNioPath()?.toUri().toString() | ||
} | ||
} | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun startFileLifecycleListener() { | ||
project.messageBus.connect(this).subscribe( | ||
VirtualFileManager.VFS_CHANGES, | ||
object : BulkFileListener { | ||
override fun after(events: List<VFileEvent>) { | ||
// since we are using synchronous FileListener | ||
pluginAwareExecuteOnPooledThread { | ||
didCreateFiles(events.filterIsInstance<VFileCreateEvent>()) | ||
didDeleteFiles(events.filterIsInstance<VFileDeleteEvent>()) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
// still need to implement | ||
//private fun didChangeWorkspaceFolders() { | ||
// languageServer.workspaceService.didChangeWorkspaceFolders() | ||
//} | ||
|
||
override fun dispose() { | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.