Skip to content
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 language id for java to match the allowlist in the lsp server #54

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

dingfeli
Copy link
Contributor

@dingfeli dingfeli commented Oct 4, 2024

Issue #, if available:
https://issues.amazon.com/issues/ECLIPSE-220

Description of changes:
This PR is to enable cross file context. And it looks like for the most part cross file context is already working.
The commit for the LSP side to support this was just recently shipped: aws/language-servers@813978f

The only thing we needed to change on the toolkit's side is to change the languageid to match the list of supported language: https://github.com/aws/language-servers/blob/a419c76ad82d5568b44d793bac6e5dc8c9b00dfc/server/aws-lsp-codewhisperer/src/language-server/utilities/supplementalContextUtil/crossFileContextUtil.ts#L20-L38

Test

After having made this change, I was able to see all the files from the workspace via printing it here:

+++ b/server/aws-lsp-codewhisperer/src/language-server/utilities/supplementalContextUtil/crossFileContextUtil.ts
@@ -16,6 +16,7 @@ import {
     Range,
 } from '@aws/language-server-runtimes/server-interface'
 import { CancellationError } from './supplementalContextUtil'
+import * as fs from "fs"

 type CrossFileSupportedLanguage =
     | 'java'
@@ -55,6 +56,19 @@ export async function fetchSupplementalContextForSrc(
     cancellationToken: CancellationToken
 ): Promise<Pick<CodeWhispererSupplementalContext, 'supplementalContextItems' | 'strategy'> | undefined> {
     const shouldProceed = shouldFetchCrossFileContext(document.languageId)
+    const documents = await workspace.getAllTextDocuments();
+    fs.appendFile("/Users/dingfeli/output.txt", `should proceed: ${shouldProceed}\ndocument length: ${documents.length}\nlanguageid: ${document.languageId}\n`, (err) => {
+        if (err) {
+            console.log("Error writing to file");
+        }
+    });
+    for (let doc of documents) {
+        fs.appendFile("/Users/dingfeli/output.txt", `document name: ${doc.uri}\n`, (err) => {
+            if (err) {
+                console.log("Error writing to file");
+            }
+        });
+    }

Output.txt:

should proceed: true
document length: 2
languageid: java
document name: file:///Users/dingfeli/eclipse-workspace/toy/src/toy/Helper.java
document name: file:///Users/dingfeli/eclipse-workspace/toy/src/toy/Main.java

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dingfeli dingfeli requested a review from breedloj October 4, 2024 17:22
@breedloj breedloj merged commit 68d772e into main Oct 4, 2024
1 check passed
@breedloj breedloj deleted the cross-file-context branch October 4, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants