Streamline the project metadata context provider (#19384)

GitOrigin-RevId: 0b75635cb9141983827dfd0fa6a58b6182d47f22
This commit is contained in:
Alf Eaton
2024-07-15 09:32:59 +00:00
committed by Copybot
parent 1e1a8c0bb3
commit 2d2746ef24
9 changed files with 88 additions and 295 deletions
@@ -16,13 +16,7 @@ export function buildLabelCompletions(
return
}
const uniqueLabels = new Set(
Object.values(metadata.documents)
.map(doc => doc.labels)
.flat(1)
)
for (const label of uniqueLabels) {
for (const label of metadata.labels) {
completions.labels.push({
type: 'label',
label,
@@ -21,24 +21,24 @@ export function buildPackageCompletions(
return
}
const uniquePackageNames = new Set<string>(packageNames)
// package names and commands from packages in the project
for (const doc of Object.values(metadata.documents)) {
for (const [packageName, commands] of Object.entries(doc.packages)) {
uniquePackageNames.add(packageName)
for (const item of commands) {
completions.commands.push({
type: item.meta,
label: item.caption,
apply: applySnippet(item.snippet),
extend: extendOverUnpairedClosingBrace,
})
}
}
// commands from packages in the project
for (const command of metadata.commands) {
completions.commands.push({
type: command.meta,
label: command.caption,
apply: applySnippet(command.snippet),
extend: extendOverUnpairedClosingBrace,
})
}
const uniquePackageNames = new Set<string>(packageNames)
// package names from packages in the project
for (const packageName of metadata.packageNames) {
uniquePackageNames.add(packageName)
}
// exclude package names that are already in this document
const existingPackageNames = findExistingPackageNames(context)
for (const item of uniquePackageNames) {