Skip to content

Commit dd85690

Browse files
committed
refactor(watchedfiles): rename registeredItems => items
Problem: The name `registeredItems` implies there is some other kind of "item", which is confusing and noisy, and unnecessarily verbose. Solution: Rename to `items`.
1 parent cfeb982 commit dd85690

File tree

17 files changed

+75
-81
lines changed

17 files changed

+75
-81
lines changed

src/lambda/vue/configEditor/samInvokeBackend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class SamInvokeWebview extends VueWebview {
161161
public async getTemplate() {
162162
const items: (vscode.QuickPickItem & { templatePath: string })[] = []
163163
const noTemplate = 'NOTEMPLATEFOUND'
164-
for (const template of (await globals.templateRegistry).registeredItems) {
164+
for (const template of (await globals.templateRegistry).items) {
165165
const resources = template.item.Resources
166166
if (resources) {
167167
for (const resource of Object.keys(resources)) {

src/lambda/wizards/samDeployWizard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ function validateStackName(value: string): string | undefined {
933933
}
934934

935935
async function getTemplateChoices(...workspaceFolders: vscode.Uri[]): Promise<SamTemplateQuickPickItem[]> {
936-
const templateUris = (await globals.templateRegistry).registeredItems.map(o => vscode.Uri.file(o.path))
936+
const templateUris = (await globals.templateRegistry).items.map(o => vscode.Uri.file(o.path))
937937
const uriToLabel: Map<vscode.Uri, string> = new Map<vscode.Uri, string>()
938938
const labelCounts: Map<string, number> = new Map()
939939

src/shared/awsFiletypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function activate(): void {
6767
vscode.workspace.onDidOpenTextDocument(async (doc: vscode.TextDocument) => {
6868
const isAwsFileExt = isAwsFiletype(doc)
6969
const isSchemaHandled = globals.schemaService.isMapped(doc.uri)
70-
const isCfnTemplate = !!(await globals.templateRegistry).registeredItems.find(
70+
const isCfnTemplate = !!(await globals.templateRegistry).items.find(
7171
t => pathutil.normalize(t.path) === pathutil.normalize(doc.fileName)
7272
)
7373
if (!isAwsFileExt && !isSchemaHandled && !isCfnTemplate) {

src/shared/codelens/codeLensUtils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ export async function makeCodeLenses({
6161

6262
try {
6363
const registry = await globals.templateRegistry
64-
const associatedResources = getResourcesForHandler(
65-
handler.filename,
66-
handler.handlerName,
67-
registry.registeredItems
68-
)
64+
const associatedResources = getResourcesForHandler(handler.filename, handler.handlerName, registry.items)
6965
const templateConfigs: AddSamDebugConfigurationInput[] = []
7066

7167
if (associatedResources.length > 0) {

src/shared/fs/watchedFiles.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
148148
this.disposables.push(
149149
vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
150150
if (isUntitledScheme(event.document.uri)) {
151-
this.addItemToRegistry(event.document.uri, true, event.document.getText())
151+
this.addItem(event.document.uri, true, event.document.getText())
152152
}
153153
}),
154154
vscode.workspace.onDidCloseTextDocument((event: vscode.TextDocument) => {
@@ -175,7 +175,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
175175
* Adds an item to registry. Wipes any existing item in its place with new copy of the data
176176
* @param uri vscode.Uri containing the item to load in
177177
*/
178-
public async addItemToRegistry(uri: vscode.Uri, quiet?: boolean, contents?: string): Promise<void> {
178+
public async addItem(uri: vscode.Uri, quiet?: boolean, contents?: string): Promise<void> {
179179
const excluded = this.excludedFilePatterns.find(pattern => uri.fsPath.match(pattern))
180180
if (excluded) {
181181
getLogger().verbose(`${this.name}: excluding path (matches "${excluded}"): ${uri.fsPath}`)
@@ -220,9 +220,9 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
220220
}
221221

222222
/**
223-
* Returns the registry's data as an array of paths to type T objects
223+
* Gets all registry items as an array of paths to type `T` objects.
224224
*/
225-
public get registeredItems(): WatchedItem<T>[] {
225+
public get items(): WatchedItem<T>[] {
226226
const arr: WatchedItem<T>[] = []
227227

228228
for (const itemPath of this.registryData.keys()) {
@@ -273,7 +273,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
273273
try {
274274
const found = await vscode.workspace.findFiles(glob, exclude)
275275
for (const item of found) {
276-
await this.addItemToRegistry(item, true)
276+
await this.addItem(item, true)
277277
}
278278
} catch (e) {
279279
const err = e as Error
@@ -300,11 +300,11 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
300300
watcher,
301301
watcher.onDidChange(async uri => {
302302
getLogger().verbose(`${this.name}: detected change: ${uri.fsPath}`)
303-
await this.addItemToRegistry(uri)
303+
await this.addItem(uri)
304304
}),
305305
watcher.onDidCreate(async uri => {
306306
getLogger().verbose(`${this.name}: detected new file: ${uri.fsPath}`)
307-
await this.addItemToRegistry(uri)
307+
await this.addItem(uri)
308308
}),
309309
watcher.onDidDelete(async uri => {
310310
getLogger().verbose(`${this.name}: detected delete: ${uri.fsPath}`)

src/shared/sam/debugger/awsSamDebugger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class SamDebugConfigProvider implements vscode.DebugConfigurationProvider
254254
const configs: AwsSamDebuggerConfiguration[] = []
255255
if (folder) {
256256
const folderPath = folder.uri.fsPath
257-
const templates = (await globals.templateRegistry).registeredItems
257+
const templates = (await globals.templateRegistry).items
258258

259259
for (const templateDatum of templates) {
260260
if (isInDirectory(folderPath, templateDatum.path)) {

src/shared/sam/sync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ interface TemplateItem {
189189
function createTemplatePrompter(registry: CloudFormationTemplateRegistry) {
190190
const folders = new Set<string>()
191191
const recentTemplatePath = getRecentResponse('global', 'templatePath')
192-
const items = registry.registeredItems.map(({ item, path: filePath }) => {
192+
const items = registry.items.map(({ item, path: filePath }) => {
193193
const uri = vscode.Uri.file(filePath)
194194
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri)
195195
const label = workspaceFolder ? path.relative(workspaceFolder.uri.fsPath, uri.fsPath) : uri.fsPath

src/shared/utilities/workspaceUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function findParentProjectFile(
9898
return undefined
9999
}
100100

101-
const workspaceProjectFiles = globals.codelensRootRegistry.registeredItems
101+
const workspaceProjectFiles = globals.codelensRootRegistry.items
102102
.filter(item => item.item.match(projectFile))
103103
.map(item => item.path)
104104

src/test/lambda/commands/createNewSamApp.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('createNewSamApp', function () {
109109
testutil.toFile(makeSampleSamTemplateYaml(true), tempTemplate.fsPath)
110110

111111
// without runtime
112-
await (await globals.templateRegistry).addItemToRegistry(tempTemplate)
112+
await (await globals.templateRegistry).addItem(tempTemplate)
113113
const launchConfigs = await addInitialLaunchConfiguration(
114114
fakeContext,
115115
fakeWorkspaceFolder,
@@ -145,7 +145,7 @@ describe('createNewSamApp', function () {
145145
testutil.toFile(makeSampleSamTemplateYaml(true), tempTemplate.fsPath)
146146

147147
// without runtime
148-
await (await globals.templateRegistry).addItemToRegistry(tempTemplate)
148+
await (await globals.templateRegistry).addItem(tempTemplate)
149149
const launchConfigs = (await addInitialLaunchConfiguration(
150150
fakeContext,
151151
fakeWorkspaceFolder,
@@ -182,7 +182,7 @@ describe('createNewSamApp', function () {
182182
it('returns a blank array if it does not match any launch configs', async function () {
183183
testutil.toFile(makeSampleSamTemplateYaml(true), tempTemplate.fsPath)
184184

185-
await (await globals.templateRegistry).addItemToRegistry(tempTemplate)
185+
await (await globals.templateRegistry).addItem(tempTemplate)
186186
const launchConfigs = await addInitialLaunchConfiguration(
187187
fakeContext,
188188
fakeWorkspaceFolder,
@@ -198,7 +198,7 @@ describe('createNewSamApp', function () {
198198

199199
testutil.toFile(makeSampleSamTemplateYaml(true), tempTemplate.fsPath)
200200

201-
await (await globals.templateRegistry).addItemToRegistry(tempTemplate)
201+
await (await globals.templateRegistry).addItem(tempTemplate)
202202
const launchConfigs = await addInitialLaunchConfiguration(
203203
fakeContext,
204204
fakeWorkspaceFolder,
@@ -232,9 +232,9 @@ describe('createNewSamApp', function () {
232232
testutil.toFile(makeSampleSamTemplateYaml(true), otherTemplate2.fsPath)
233233
testutil.toFile('target file', path.join(otherFolder1, templateYaml))
234234

235-
await (await globals.templateRegistry).addItemToRegistry(tempTemplate)
236-
await (await globals.templateRegistry).addItemToRegistry(otherTemplate1)
237-
await (await globals.templateRegistry).addItemToRegistry(otherTemplate2)
235+
await (await globals.templateRegistry).addItem(tempTemplate)
236+
await (await globals.templateRegistry).addItem(otherTemplate1)
237+
await (await globals.templateRegistry).addItem(otherTemplate2)
238238

239239
const launchConfigs1 = await addInitialLaunchConfiguration(
240240
fakeContext,

src/test/lambda/config/templates.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ describe('getExistingConfiguration', async function () {
797797
it('returns undefined if the legacy config file is not valid JSON', async function () {
798798
await writeFile(tempTemplateFile.fsPath, makeSampleSamTemplateYaml(true, { handler: matchedHandler }), 'utf8')
799799
await writeFile(tempConfigFile, makeSampleSamTemplateYaml(true, { handler: matchedHandler }), 'utf8')
800-
await (await globals.templateRegistry).addItemToRegistry(tempTemplateFile)
800+
await (await globals.templateRegistry).addItem(tempTemplateFile)
801801
const val = await getExistingConfiguration(fakeWorkspaceFolder, matchedHandler, tempTemplateFile)
802802
assert.strictEqual(val, undefined)
803803
})
@@ -818,7 +818,7 @@ describe('getExistingConfiguration', async function () {
818818
},
819819
}
820820
await writeFile(tempConfigFile, JSON.stringify(configData), 'utf8')
821-
await (await globals.templateRegistry).addItemToRegistry(tempTemplateFile)
821+
await (await globals.templateRegistry).addItem(tempTemplateFile)
822822
const val = await getExistingConfiguration(fakeWorkspaceFolder, matchedHandler, tempTemplateFile)
823823
assert.ok(val)
824824
if (val) {

0 commit comments

Comments
 (0)