Skip to content

Commit cfeb982

Browse files
committed
refactor(watchedfiles): rename getRegisteredItem => getItem
Problem: getRegisteredItem implies there is some other kind of "item", which is confusing. Solution: Rename to getItem.
1 parent c97dd4b commit cfeb982

File tree

11 files changed

+21
-19
lines changed

11 files changed

+21
-19
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/wizards/samDeployWizard.ts

Lines changed: 1 addition & 1 deletion
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

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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -225,7 +226,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
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
}

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) {

src/shared/sam/debugger/commands/addSamDebugConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function addSamDebugConfiguration(
5757
let preloadedConfig = undefined
5858

5959
if (workspaceFolder) {
60-
const templateDatum = (await globals.templateRegistry).getRegisteredItem(rootUri)
60+
const templateDatum = (await globals.templateRegistry).getItem(rootUri)
6161
if (templateDatum) {
6262
const resource = templateDatum.item.Resources![resourceName]
6363
if (!resource) {

src/test/shared/fs/templateRegistry.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('CloudFormation Template Registry', async function () {
4444

4545
assert.strictEqual(testRegistry.registeredItems.length, 1)
4646

47-
const data = testRegistry.getRegisteredItem(filename.fsPath)
47+
const data = testRegistry.getItem(filename.fsPath)
4848

4949
assertValidTestTemplate(data, filename.fsPath)
5050
})
@@ -71,21 +71,21 @@ describe('CloudFormation Template Registry', async function () {
7171
await strToYamlFile(goodYaml1, filename.fsPath)
7272
await testRegistry.addItemToRegistry(filename)
7373

74-
const data = testRegistry.getRegisteredItem(filename)
74+
const data = testRegistry.getItem(filename)
7575

7676
assertValidTestTemplate(data, filename.fsPath)
7777
})
7878

7979
it('returns undefined if the registry has no registered templates', function () {
80-
assert.strictEqual(testRegistry.getRegisteredItem('/template.yaml'), undefined)
80+
assert.strictEqual(testRegistry.getItem('/template.yaml'), undefined)
8181
})
8282

8383
it('returns undefined if the registry does not contain the template in question', async function () {
8484
const filename = vscode.Uri.file(path.join(tempFolder, 'template.yaml'))
8585
await strToYamlFile(goodYaml1, filename.fsPath)
8686
await testRegistry.addItemToRegistry(vscode.Uri.file(filename.fsPath))
8787

88-
assert.strictEqual(testRegistry.getRegisteredItem('/not-the-template.yaml'), undefined)
88+
assert.strictEqual(testRegistry.getItem('/not-the-template.yaml'), undefined)
8989
})
9090
})
9191

src/test/shared/sam/debugger/awsSamDebugConfigurationValidator.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ describe('DefaultAwsSamDebugConfigurationValidator', function () {
104104
let validator: DefaultAwsSamDebugConfigurationValidator
105105

106106
beforeEach(function () {
107-
when(mockRegistry.getRegisteredItem('/')).thenReturn(templateData)
108-
when(mockRegistry.getRegisteredItem('/image')).thenReturn(imageTemplateData)
107+
when(mockRegistry.getItem('/')).thenReturn(templateData)
108+
when(mockRegistry.getItem('/image')).thenReturn(imageTemplateData)
109109

110110
validator = new DefaultAwsSamDebugConfigurationValidator(instance(mockFolder))
111111
})
@@ -126,7 +126,7 @@ describe('DefaultAwsSamDebugConfigurationValidator', function () {
126126

127127
it("returns invalid when resolving template debug configurations with a template that isn't in the registry", () => {
128128
const mockEmptyRegistry: CloudFormationTemplateRegistry = mock()
129-
when(mockEmptyRegistry.getRegisteredItem('/')).thenReturn(undefined)
129+
when(mockEmptyRegistry.getItem('/')).thenReturn(undefined)
130130

131131
validator = new DefaultAwsSamDebugConfigurationValidator(instance(mockFolder))
132132

0 commit comments

Comments
 (0)