-
Notifications
You must be signed in to change notification settings - Fork 275
feat(amazonQ): LSP -- Implement Initialize message #5367
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1733ef8
add InitializeParams
samgst-amazon 139af94
workspace folders
samgst-amazon 1670212
lint
samgst-amazon add8d41
add timeout to initialize()
samgst-amazon ee0b589
data class for ExtendedClientMetadata instead of freeform map
samgst-amazon 0819535
comment
samgst-amazon 0d0494e
comment
samgst-amazon 2e3ad80
break out metadata into model
samgst-amazon 30d7c9c
detekt
samgst-amazon ec614b8
detekt
rli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,20 +19,29 @@ import com.intellij.openapi.util.Key | |
| import com.intellij.util.io.await | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.launch | ||
| import org.eclipse.lsp4j.ClientCapabilities | ||
| import org.eclipse.lsp4j.ClientInfo | ||
| import org.eclipse.lsp4j.FileOperationsWorkspaceCapabilities | ||
| import org.eclipse.lsp4j.InitializeParams | ||
| import org.eclipse.lsp4j.InitializedParams | ||
| import org.eclipse.lsp4j.SynchronizationCapabilities | ||
| import org.eclipse.lsp4j.TextDocumentClientCapabilities | ||
| import org.eclipse.lsp4j.WorkspaceClientCapabilities | ||
| import org.eclipse.lsp4j.WorkspaceFolder | ||
| import org.eclipse.lsp4j.jsonrpc.Launcher | ||
| import org.eclipse.lsp4j.launch.LSPLauncher | ||
| import org.slf4j.event.Level | ||
| import software.aws.toolkits.core.utils.getLogger | ||
| import software.aws.toolkits.core.utils.warn | ||
| import software.aws.toolkits.jetbrains.isDeveloperMode | ||
| import software.aws.toolkits.jetbrains.services.telemetry.ClientMetadata | ||
| import java.io.IOException | ||
| import java.io.OutputStreamWriter | ||
| import java.io.PipedInputStream | ||
| import java.io.PipedOutputStream | ||
| import java.io.PrintWriter | ||
| import java.io.StringWriter | ||
| import java.net.URI | ||
| import java.nio.charset.StandardCharsets | ||
| import java.util.concurrent.Future | ||
|
|
||
|
|
@@ -70,7 +79,7 @@ internal class LSPProcessListener : ProcessListener { | |
| } | ||
|
|
||
| @Service(Service.Level.PROJECT) | ||
| class AmazonQLspService(project: Project, private val cs: CoroutineScope) : Disposable { | ||
| class AmazonQLspService(private val project: Project, private val cs: CoroutineScope) : Disposable { | ||
| private val launcher: Launcher<AmazonQLanguageServer> | ||
|
|
||
| private val languageServer: AmazonQLanguageServer | ||
|
|
@@ -80,6 +89,76 @@ class AmazonQLspService(project: Project, private val cs: CoroutineScope) : Disp | |
| private val launcherFuture: Future<Void> | ||
| private val launcherHandler: KillableProcessHandler | ||
|
|
||
| private fun createClientCapabilities(): ClientCapabilities { | ||
| return ClientCapabilities().apply { | ||
| textDocument = TextDocumentClientCapabilities().apply { | ||
| // For didSaveTextDocument, other textDocument/ messages always mandatory | ||
| synchronization = SynchronizationCapabilities().apply { | ||
| didSave = true | ||
| } | ||
| } | ||
|
|
||
| workspace = WorkspaceClientCapabilities().apply { | ||
| applyEdit = false | ||
|
|
||
| // For workspace folder changes | ||
| workspaceFolders = true | ||
|
|
||
| // For file operations (create, delete) | ||
| fileOperations = FileOperationsWorkspaceCapabilities().apply { | ||
| didCreate = true | ||
| didDelete = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun createWorkspaceFolders(): List<WorkspaceFolder> { | ||
| return project.basePath?.let { basePath -> | ||
| listOf( | ||
| WorkspaceFolder( | ||
| URI("file://$basePath").toString(), | ||
| project.name | ||
| ) | ||
| ) | ||
| } ?: emptyList() | ||
| } | ||
|
|
||
| private fun createClientInfo(): ClientInfo { | ||
| val metadata = ClientMetadata.getDefault() | ||
| return ClientInfo().apply { | ||
| name = metadata.awsProduct.toString() | ||
| version = metadata.awsVersion | ||
| } | ||
| } | ||
|
|
||
| private fun getExtendedClientMetadata(): Map<String, Any> { | ||
| val metadata = ClientMetadata.getDefault() | ||
| return mapOf( | ||
| "aws" to mapOf( | ||
| "clientInfo" to mapOf( | ||
| "extension" to mapOf( | ||
| "name" to metadata.awsProduct.toString(), | ||
| "version" to metadata.awsVersion | ||
| ), | ||
| "clientId" to metadata.clientId, | ||
| "version" to metadata.parentProductVersion, | ||
| "name" to metadata.parentProduct | ||
| ) | ||
| ) | ||
| ) | ||
| } | ||
|
||
|
|
||
| private fun createInitializeParams(): InitializeParams { | ||
| return InitializeParams().apply { | ||
| processId = ProcessHandle.current().pid().toInt() | ||
| capabilities = createClientCapabilities() | ||
| clientInfo = createClientInfo() | ||
| workspaceFolders = createWorkspaceFolders() | ||
| initializationOptions = getExtendedClientMetadata() | ||
| } | ||
| } | ||
|
|
||
| init { | ||
| val cmd = GeneralCommandLine("amazon-q-lsp") | ||
|
|
||
|
|
@@ -116,18 +195,7 @@ class AmazonQLspService(project: Project, private val cs: CoroutineScope) : Disp | |
| launcherFuture = launcher.startListening() | ||
|
|
||
| cs.launch { | ||
| val initializeResult = languageServer.initialize( | ||
| InitializeParams().apply { | ||
| // does this work on windows | ||
| processId = ProcessHandle.current().pid().toInt() | ||
| // capabilities | ||
| // client info | ||
| // trace? | ||
| // workspace folders? | ||
| // anything else we need? | ||
| } | ||
| // probably need a timeout | ||
| ).await() | ||
| val initializeResult = languageServer.initialize(createInitializeParams()).await() | ||
|
|
||
| // then if this succeeds then we can allow the client to send requests | ||
| if (initializeResult == null) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a note to handle the case where this is null