Skip to content

Commit

Permalink
manifest: Allow to configure directories to ignore while searching fo…
Browse files Browse the repository at this point in the history
…r manifests
  • Loading branch information
zecakeh authored and bilelmoussaoui committed Aug 18, 2024
1 parent 6b90f18 commit b93c769
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [Unreleased]

- manifest: Allow to configure directories to ignore while searching for manifests

## [0.0.37]

- manifest: Automatically set `development` flatpak manifests, suffixed with `Devel` / `.devel` by default
Expand Down
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,20 @@
],
"url": "https://raw.githubusercontent.com/flatpak/flatpak-builder/master/data/flatpak-manifest.schema.json"
}
]
],
"configuration": {
"title": "Flatpak",
"properties": {
"flatpak-vscode.excludeManifestDirs": {
"markdownDescription": "These directories, with `.flatpak` and `_build`, will be ignored when searching for Flatpak manifests. You may also need to add these folders to Code's `files.watcherExclude` for performance.",
"default": ["target", ".vscode", ".flatpak-builder", "flatpak_app", ".github"],
"type": "array",
"items": {
"type": "string"
}
}
}
}
},
"scripts": {
"vscode:prepublish": "yarn run compile",
Expand Down
14 changes: 14 additions & 0 deletions src/manifestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export class ManifestManager implements vscode.Disposable {
manifests.delete(deletedUri)
})

vscode.workspace.onDidChangeConfiguration(async (event) => {
if (event.affectsConfiguration('flatpak-vscode')) {
await this.refreshManifests()
}
})

this.statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left)
this.updateStatusItem()
}
Expand Down Expand Up @@ -143,6 +149,14 @@ export class ManifestManager implements vscode.Disposable {
return this.manifests
}

async refreshManifests(): Promise<void> {
if (this.manifests !== undefined) {
console.log('Refreshing Flatpak manifests')
const newManifests = await findManifests()
this.manifests.update(newManifests)
}
}

/**
* Like `getActiveManifestUnchecked` but throws an error when the active manifest contains error.
*
Expand Down
12 changes: 12 additions & 0 deletions src/manifestMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export class ManifestMap implements Iterable<Manifest> {
return isDeleted
}

update(other: ManifestMap): void {
for (const manifest of this) {
if (!other.inner.has(manifest.uri.fsPath)) {
this.delete(manifest.uri)
}
}

for (const manifest of other) {
this.add(manifest)
}
}

get(uri: vscode.Uri): Manifest | undefined {
return this.inner.get(uri.fsPath)
}
Expand Down
7 changes: 6 additions & 1 deletion src/manifestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ export const MANIFEST_PATH_GLOB_PATTERN = '**/*.{json,yaml,yml}'
* @returns List of Flatpak Manifest
*/
export async function findManifests(): Promise<ManifestMap> {
// Always exclude the directories we generate.
const excludeBaseDirs = ['.flatpak', '_build']
const excludeConfigDirs = workspace.getConfiguration('flatpak-vscode').get<string[]>('excludeManifestDirs')
const excludeDirs = excludeBaseDirs.concat(excludeConfigDirs ?? []).join(',')

const uris: Uri[] = await workspace.findFiles(
MANIFEST_PATH_GLOB_PATTERN,
'**/{target,.vscode,.flatpak-builder,flatpak_app,.flatpak,_build,.github}/*',
`**/{${excludeDirs}}/*`,
1000
)
const manifests = new ManifestMap()
Expand Down
39 changes: 39 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,45 @@ suite('manifestMap', () => {
})
assert.equal(nIter, 2)
})

test('update', () => {
const first_map = new ManifestMap()
assert(first_map.isEmpty())

const second_map = new ManifestMap()
assert(second_map.isEmpty())

const manifestAUri = Uri.file('/home/test/a.a.a.json')
const manifestA = createTestManifest(manifestAUri)

const manifestBUri = Uri.file('/home/test/b.b.b.json')
const manifestB = createTestManifest(manifestBUri)

first_map.add(manifestA)
assert.equal(first_map.size(), 1)
assert.deepStrictEqual(first_map.get(manifestAUri), manifestA)

second_map.add(manifestB)
assert.equal(second_map.size(), 1)
assert.deepStrictEqual(second_map.get(manifestBUri), manifestB)

first_map.update(second_map)
assert.equal(first_map.size(), 1)
assert.deepStrictEqual(first_map.get(manifestBUri), manifestB)

second_map.delete(manifestBUri)
assert(second_map.isEmpty())

first_map.update(second_map)
assert(first_map.isEmpty())

second_map.add(manifestA)
second_map.add(manifestB)
assert.equal(second_map.size(), 2)

first_map.update(second_map)
assert.equal(first_map.size(), 2)
})
})

suite('manifestUtils', () => {
Expand Down

0 comments on commit b93c769

Please sign in to comment.