Skip to content

fix(amazonq): Use common utility to determine workspaceFolders and fix tests #1353

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 3 commits into from
May 19, 2025

Conversation

shruti0085
Copy link
Contributor

@shruti0085 shruti0085 commented May 16, 2025

Description

This change address a few different things concerning the usage of workspaceFolders across servers.

  • Language server runtime version has been bumped to the latest to pull changes made in feat: support using rootUri for workspaceFolders and handle workspaceChangeEvent language-server-runtimes#509
  • All locations that determine workspaceFolders have been updated to call workspace.getAllWorkspaceFolders() which was introduced in the runtimes PR as a common utility(it respects didChangeWorkspaceFolder event alongwith using rootUri of initializeparams in absence of workspaceFolder)
  • With this update, particularly in the VS client paths associated with tool actions are now correct. Prior to that they were displayed as a relativePath.
  • InitializeUtils has been deleted as the logic has been moved to the runtimes repo

In addition, this change fixes test failures seen locally on Windows devices associated with workspaceUtils.test.ts and fileSearch.test.ts whereever fs.readDir calls were being stubbed out. Error path is undefined was being thrown for tests where getEntryPath was invoked.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@shruti0085 shruti0085 requested a review from a team as a code owner May 16, 2025 22:19
let localProjectContextController: LocalProjectContextController
let amazonQServiceManager: AmazonQTokenServiceManager
let telemetryService: TelemetryService

let localProjectContextEnabled: boolean = false

lsp.addInitializer((params: InitializeParams) => {
const workspaceFolders = getWorkspaceFolders(logging, params)
const workspaceFolders = workspace.getAllWorkspaceFolders() || params.workspaceFolders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ?? I'm a little rusty...

Similarly in workspaceContextServer.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I could find, it seems like it the right hand side would be used as fallback when left-hand side is any falsy value (including false, 0, "", null, undefined, and NaN). That seemed fine to me

@@ -99,12 +99,16 @@ export function formatListing(entry: Dirent): string {
}

export function getEntryPath(entry: Dirent) {
if (!entry.parentPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't typescript satisfy this automatically since parentpath is a non-optional field in Dirent?

The only place where the parentpath was not being set before was in the testing stubs that had custom behaviour and that were doing lots of type casting. Throwing and error here doesn't look really right to me, now with the parentpath changes introduced in the PR do we need to throw this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove the throw and error check in getEntryPath as I was seeing errors locally where parentpath was null with tests. I wasn't sure if this only impacted tests but as long as it does not impact actual logic, I am fine with removing this

@@ -99,12 +99,16 @@ export function formatListing(entry: Dirent): string {
}

export function getEntryPath(entry: Dirent) {
if (!entry.parentPath) {
throw new Error(`Entry is missing parentPath property: ${JSON.stringify(entry)}`)
}
return path.join(entry.parentPath, entry.name)
}

// TODO: port this to runtimes?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this comment as well

@shruti0085 shruti0085 merged commit 483f532 into main May 19, 2025
6 checks passed
@shruti0085 shruti0085 deleted the shruti0085/workspaceFix branch May 19, 2025 20:35
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.

3 participants