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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/aws-lsp-antlr4-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"webpack": "webpack"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-antlr4": "*",
"antlr4-c3": "^3.4.1",
"antlr4ng": "^3.0.4"
Expand Down
2 changes: 1 addition & 1 deletion app/aws-lsp-codewhisperer-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"local-build": "node scripts/local-build.js"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-codewhisperer": "*",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
Expand Down
2 changes: 1 addition & 1 deletion app/aws-lsp-identity-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"compile": "tsc --build"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-identity": "^0.0.1"
}
}
2 changes: 1 addition & 1 deletion app/aws-lsp-json-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"webpack": "webpack"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-json": "*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion app/aws-lsp-notification-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"compile": "tsc --build"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-notification": "^0.0.1"
}
}
2 changes: 1 addition & 1 deletion app/aws-lsp-yaml-json-webworker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"serve:webpack": "NODE_ENV=development webpack serve"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-json": "*",
"@aws/lsp-yaml": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion app/aws-lsp-yaml-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"webpack": "webpack"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-yaml": "*"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion app/hello-world-lsp-runtimes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@aws/hello-world-lsp": "^0.0.1",
"@aws/language-server-runtimes": "^0.2.80"
"@aws/language-server-runtimes": "^0.2.82"
},
"devDependencies": {
"@types/chai": "^4.3.5",
Expand Down
2 changes: 1 addition & 1 deletion client/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@
"@aws-sdk/credential-providers": "^3.731.1",
"@aws-sdk/types": "^3.734.0",
"@aws/chat-client-ui-types": "^0.1.34",
"@aws/language-server-runtimes": "^0.2.81",
"@aws/language-server-runtimes": "^0.2.82",
"@types/uuid": "^9.0.8",
"@types/vscode": "^1.98.0",
"jose": "^5.2.4",
Expand Down
25 changes: 22 additions & 3 deletions core/aws-lsp-core/src/util/workspaceUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,13 @@ describe('workspaceUtils', function () {
tempFolder = await TestFolder.create()
testFeatures = new TestFeatures()
// Taken from https://github.com/aws/language-server-runtimes/blob/674c02696c150838b4bc93543fb0009c5982e7ad/runtimes/runtimes/standalone.ts#L216
testFeatures.workspace.fs.readdir = path => fs.readdir(path, { withFileTypes: true })
testFeatures.workspace.fs.readdir = async dirPath => {
const entries = await fs.readdir(dirPath, { withFileTypes: true })
return entries.map(entry => {
;(entry as any).parentPath = dirPath
return entry
})
}
testFeatures.workspace.fs.exists = path =>
fs.access(path).then(
() => true,
Expand Down Expand Up @@ -130,9 +136,15 @@ describe('workspaceUtils', function () {
it('correctly identifies entry types', async function () {
const file = await tempFolder.write('file1', 'this is a file')
const subdir = await tempFolder.nest('subdir1')
// Only create symlinks on non-Windows platforms
if (process.platform === 'win32') {
const results = (await readDirectoryRecursively(testFeatures, tempFolder.path, undefined)).sort()
assert.deepStrictEqual(results, [`[D] ${subdir.path}`, `[F] ${file}`])
return
}

const linkPath = path.join(tempFolder.path, 'link1')
await fs.symlink(tempFolder.path, linkPath, 'dir')

const results = (await readDirectoryRecursively(testFeatures, tempFolder.path, undefined)).sort()
assert.deepStrictEqual(results, [`[D] ${subdir.path}`, `[F] ${file}`, `[L] ${linkPath}`])
})
Expand Down Expand Up @@ -224,7 +236,14 @@ describe('workspaceUtils', function () {
tempFolder = await TestFolder.create()
testFeatures = new TestFeatures()
// Taken from https://github.com/aws/language-server-runtimes/blob/674c02696c150838b4bc93543fb0009c5982e7ad/runtimes/runtimes/standalone.ts#L216
testFeatures.workspace.fs.readdir = path => fs.readdir(path, { withFileTypes: true })
testFeatures.workspace.fs.readdir = async dirPath => {
const entries = await fs.readdir(dirPath, { withFileTypes: true })
// Add parentPath to each entry
return entries.map(entry => {
;(entry as any).parentPath = dirPath
return entry
})
}
testFeatures.workspace.fs.exists = path =>
fs.access(path).then(
() => true,
Expand Down
8 changes: 6 additions & 2 deletions core/aws-lsp-core/src/util/workspaceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

export function getWorkspaceFolderPaths(lsp: Features['lsp']): string[] {
return lsp.getClientInitializeParams()?.workspaceFolders?.map(({ uri }) => URI.parse(uri).fsPath) ?? []
export function getWorkspaceFolderPaths(workspace: Features['workspace']): string[] {
const workspaceFolders = workspace.getAllWorkspaceFolders()
return workspaceFolders?.map(({ uri }) => URI.parse(uri).fsPath) ?? []
}

export function isParentFolder(parentPath: string, childPath: string): boolean {
Expand Down
44 changes: 22 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/aws-lsp-antlr4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"clean": "rm -rf node_modules"
},
"dependencies": {
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-core": "^0.0.8"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion server/aws-lsp-codewhisperer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@aws-sdk/util-arn-parser": "^3.723.0",
"@aws-sdk/util-retry": "^3.374.0",
"@aws/chat-client-ui-types": "^0.1.33",
"@aws/language-server-runtimes": "^0.2.80",
"@aws/language-server-runtimes": "^0.2.82",
"@aws/lsp-core": "^0.0.8",
"@modelcontextprotocol/sdk": "^1.9.0",
"@smithy/node-http-handler": "^2.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Will be deleted or merged.
*/

import * as crypto from 'crypto'

Check warning on line 6 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "crypto"

Check warning on line 6 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "crypto"
import * as path from 'path'

Check warning on line 7 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "path"

Check warning on line 7 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "path"
import {
ChatTriggerType,
CodeWhispererStreamingServiceException,
Expand Down Expand Up @@ -183,7 +183,7 @@
this.#serviceManager = serviceManager
this.#chatHistoryDb = new ChatDatabase(features)
this.#tabBarController = new TabBarController(features, this.#chatHistoryDb, telemetryService)
this.#additionalContextProvider = new AdditionalContextProvider(features.workspace, features.lsp)
this.#additionalContextProvider = new AdditionalContextProvider(features.workspace)
this.#contextCommandsProvider = new ContextCommandsProvider(
this.#features.logging,
this.#features.chat,
Expand Down Expand Up @@ -2132,7 +2132,7 @@

async #resolveAbsolutePath(relativePath: string): Promise<string | undefined> {
try {
const workspaceFolders = workspaceUtils.getWorkspaceFolderPaths(this.#features.lsp)
const workspaceFolders = workspaceUtils.getWorkspaceFolderPaths(this.#features.workspace)
for (const workspaceRoot of workspaceFolders) {
const candidatePath = path.join(workspaceRoot, relativePath)
if (await this.#features.workspace.fs.exists(candidatePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('AdditionalContextProvider', () => {
testFeatures.workspace.fs.exists = fsExistsStub
testFeatures.workspace.fs.readdir = fsReadDirStub
getContextCommandPromptStub = sinon.stub()
provider = new AdditionalContextProvider(testFeatures.workspace, testFeatures.lsp)
provider = new AdditionalContextProvider(testFeatures.workspace)
localProjectContextControllerInstanceStub = sinon.stub(LocalProjectContextController, 'getInstance').resolves({
getContextCommandPrompt: getContextCommandPromptStub,
} as unknown as LocalProjectContextController)
Expand Down
Loading
Loading