Skip to content

Commit ac4bbd4

Browse files
authored
feat(amazonq): more programming languages for workspace index #5459
1 parent 978b1f8 commit ac4bbd4

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Support more programming languages for workspace index"
4+
}

packages/core/src/amazonq/lsp/lspController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export interface Manifest {
6767
}
6868
const manifestUrl = 'https://aws-toolkit-language-servers.amazonaws.com/q-context/manifest.json'
6969
// this LSP client in Q extension is only going to work with these LSP server versions
70-
const supportedLspServerVersions = ['0.1.3']
70+
const supportedLspServerVersions = ['0.1.4']
7171

7272
const nodeBinName = process.platform === 'win32' ? 'node.exe' : 'node'
7373
/*

packages/core/src/shared/utilities/workspaceUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ export async function collectFilesForIndex(
559559

560560
const isLanguageSupported = (filename: string) => {
561561
const k =
562-
/\.(js|ts|java|py|rb|cpp|tsx|jsx|cc|c|h|html|json|css|md|php|swift|rs|scala|yaml|tf|sql|sh|go|yml|kt|smithy|config|kts|gradle|cfg|xml|vue)$/i
562+
/\.(js|ts|java|py|rb|cpp|tsx|jsx|cc|c|cs|vb|pl|r|m|hs|mts|mjs|h|clj|dart|groovy|lua|rb|jl|ipynb|html|json|css|md|php|swift|rs|scala|yaml|tf|sql|sh|go|yml|kt|smithy|config|kts|gradle|cfg|xml|vue)$/i
563563
return k.test(filename) || filename.endsWith('Config')
564564
}
565565

packages/core/src/testInteg/shared/utilities/workspaceUtils.test.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as vscode from 'vscode'
1010
import * as fs from 'fs'
1111
import {
1212
collectFiles,
13+
collectFilesForIndex,
1314
findParentProjectFile,
1415
getWorkspaceFoldersByPrefixes,
1516
getWorkspaceRelativePath,
@@ -426,3 +427,75 @@ describe('getWorkspaceFoldersByPrefixes', function () {
426427
)
427428
})
428429
})
430+
431+
describe('collectFilesForIndex', function () {
432+
it('returns all files in the workspace not excluded by gitignore and is a supported programming language', async function () {
433+
// these variables are a manual selection of settings for the test in order to test the collectFiles function
434+
const fileAmount = 3
435+
const fileNamePrefix = 'file'
436+
const fileContent = 'test content'
437+
438+
const workspaceFolder = await createTestWorkspace(fileAmount, { fileNamePrefix, fileContent })
439+
440+
const writeFile = (pathParts: string[], fileContent: string) => {
441+
return toFile(fileContent, workspaceFolder.uri.fsPath, ...pathParts)
442+
}
443+
444+
sinon.stub(vscode.workspace, 'workspaceFolders').value([workspaceFolder])
445+
const gitignoreContent = `file2
446+
# different formats of prefixes
447+
/build
448+
node_modules
449+
450+
#some comment
451+
452+
range_file[0-5]
453+
`
454+
await writeFile(['.gitignore'], gitignoreContent)
455+
456+
await writeFile(['build', `ignored1`], fileContent)
457+
await writeFile(['build', `ignored2`], fileContent)
458+
459+
await writeFile(['node_modules', `ignored1`], fileContent)
460+
await writeFile(['node_modules', `ignored2`], fileContent)
461+
462+
await writeFile([`range_file0`], fileContent)
463+
await writeFile([`range_file9`], fileContent)
464+
465+
const gitignore2 = 'folder1\n'
466+
await writeFile(['src', '.gitignore'], gitignore2)
467+
await writeFile(['src', 'folder2', 'a.js'], fileContent)
468+
await writeFile(['src', 'folder2', 'b.cs'], fileContent)
469+
await writeFile(['src', 'folder2', 'c.bin'], fileContent)
470+
await writeFile(['src', 'folder2', 'd.pyc'], fileContent)
471+
472+
const gitignore3 = `negate_test*
473+
!negate_test[0-5]`
474+
await writeFile(['src', 'folder3', '.gitignore'], gitignore3)
475+
await writeFile(['src', 'folder3', 'negate_test1'], fileContent)
476+
await writeFile(['src', 'folder3', 'negate_test6'], fileContent)
477+
478+
const result = (await collectFilesForIndex([workspaceFolder.uri.fsPath], [workspaceFolder], true))
479+
// for some reason, uri created inline differ in subfields, so skipping them from assertion
480+
.map(({ fileUri, ...r }) => ({ ...r }))
481+
482+
result.sort((l, r) => l.relativeFilePath.localeCompare(r.relativeFilePath))
483+
484+
// non-posix filePath check here is important.
485+
assert.deepStrictEqual(
486+
[
487+
{
488+
workspaceFolder,
489+
relativeFilePath: path.join('src', 'folder2', 'a.js'),
490+
fileSizeBytes: 12,
491+
},
492+
{
493+
workspaceFolder,
494+
relativeFilePath: path.join('src', 'folder2', 'b.cs'),
495+
fileSizeBytes: 12,
496+
},
497+
] satisfies typeof result,
498+
result
499+
)
500+
})
501+
})

0 commit comments

Comments
 (0)