Skip to content

Commit d35ac17

Browse files
authored
refactor(watchedfiles): rename registeredItems => items #3945
Problem: - `getRegisteredItem` implies there is some other kind of "item", which is confusing. - The name `registeredItems` implies there is some other kind of "item", which is confusing and noisy, and unnecessarily verbose. Solution: - Rename to `getItem`. - Rename to `items`.
2 parents c97dd4b + dd85690 commit d35ac17

24 files changed

+96
-100
lines changed

src/codecatalyst/devfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class DevfileCodeLensProvider implements vscode.CodeLensProvider {
6666
this.disposables.push(this._onDidChangeCodeLenses)
6767
this.disposables.push(
6868
workspace.onDidSaveTextDocument(async document => {
69-
if (!registry.getRegisteredItem(document.fileName)) {
69+
if (!registry.getItem(document.fileName)) {
7070
return
7171
}
7272

src/lambda/commands/createNewSamApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export async function createNewSamApplication(
271271
// Race condition where SAM app is created but template doesn't register in time.
272272
// Poll for 5 seconds, otherwise direct user to codelens.
273273
const isTemplateRegistered = await waitUntil(
274-
async () => (await globals.templateRegistry).getRegisteredItem(templateUri),
274+
async () => (await globals.templateRegistry).getItem(templateUri),
275275
{
276276
timeout: 5000,
277277
interval: 500,

src/lambda/local/debugConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export async function getTemplate(
193193
}
194194
const templateInvoke = config.invokeTarget as TemplateTargetProperties
195195
const fullPath = tryGetAbsolutePath(folder, templateInvoke.templatePath)
196-
const cfnTemplate = (await globals.templateRegistry).getRegisteredItem(fullPath)?.item
196+
const cfnTemplate = (await globals.templateRegistry).getItem(fullPath)?.item
197197
return cfnTemplate
198198
}
199199

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
211211
}
212212

213213
public async determineIfTemplateHasImages(templatePath: vscode.Uri): Promise<boolean> {
214-
const template = (await globals.templateRegistry).getRegisteredItem(templatePath.fsPath)
214+
const template = (await globals.templateRegistry).getItem(templatePath.fsPath)
215215
const resources = template?.item?.Resources
216216
if (resources === undefined) {
217217
return false
@@ -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/extensionGlobals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ interface ToolkitGlobals {
109109
regionProvider: RegionProvider
110110
sdkClientBuilder: AWSClientBuilder
111111
telemetry: TelemetryService & { logger: TelemetryLogger }
112+
/** template.yaml registry. _Avoid_ calling this until it is actually needed (for SAM features). */
112113
templateRegistry: Promise<CloudFormationTemplateRegistry>
113114
schemaService: SchemaService
114115
codelensRootRegistry: CodelensRootRegistry

src/shared/fs/watchedFiles.ts

Lines changed: 13 additions & 12 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}`)
@@ -200,12 +200,13 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
200200
}
201201

202202
/**
203-
* Get a specific item's data
204-
* Untitled files must be referred to by their URI
203+
* Gets an item by filepath or URI.
204+
*
205+
* Untitled files must be referred to by URI.
206+
*
205207
* @param path Absolute path to item of interest or a vscode.Uri to the item
206208
*/
207-
public getRegisteredItem(path: string | vscode.Uri): WatchedItem<T> | undefined {
208-
// fsPath is needed for Windows, it's equivalent to path on mac/linux
209+
public getItem(path: string | vscode.Uri): WatchedItem<T> | undefined {
209210
const normalizedPath = typeof path === 'string' ? pathutils.normalize(path) : normalizeVSCodeUri(path)
210211
this.assertAbsolute(normalizedPath)
211212
const item = this.registryData.get(normalizedPath)
@@ -219,13 +220,13 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
219220
}
220221

221222
/**
222-
* 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.
223224
*/
224-
public get registeredItems(): WatchedItem<T>[] {
225+
public get items(): WatchedItem<T>[] {
225226
const arr: WatchedItem<T>[] = []
226227

227228
for (const itemPath of this.registryData.keys()) {
228-
const item = this.getRegisteredItem(itemPath)
229+
const item = this.getItem(itemPath)
229230
if (item) {
230231
arr.push(item)
231232
}
@@ -272,7 +273,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
272273
try {
273274
const found = await vscode.workspace.findFiles(glob, exclude)
274275
for (const item of found) {
275-
await this.addItemToRegistry(item, true)
276+
await this.addItem(item, true)
276277
}
277278
} catch (e) {
278279
const err = e as Error
@@ -299,11 +300,11 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
299300
watcher,
300301
watcher.onDidChange(async uri => {
301302
getLogger().verbose(`${this.name}: detected change: ${uri.fsPath}`)
302-
await this.addItemToRegistry(uri)
303+
await this.addItem(uri)
303304
}),
304305
watcher.onDidCreate(async uri => {
305306
getLogger().verbose(`${this.name}: detected new file: ${uri.fsPath}`)
306-
await this.addItemToRegistry(uri)
307+
await this.addItem(uri)
307308
}),
308309
watcher.onDidDelete(async uri => {
309310
getLogger().verbose(`${this.name}: detected delete: ${uri.fsPath}`)

src/shared/sam/debugger/awsSamDebugConfigurationValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class DefaultAwsSamDebugConfigurationValidator implements AwsSamDebugConf
7272
const fullpath = tryGetAbsolutePath(this.workspaceFolder, config.invokeTarget.templatePath)
7373
// Normalize to absolute path for use in the runner.
7474
config.invokeTarget.templatePath = fullpath
75-
cfnTemplate = registry.getRegisteredItem(fullpath)?.item
75+
cfnTemplate = registry.getItem(fullpath)?.item
7676
}
7777
rv = this.validateTemplateConfig(config, config.invokeTarget.templatePath, cfnTemplate)
7878
} else if (config.invokeTarget.target === CODE_TARGET_TYPE) {

0 commit comments

Comments
 (0)