Skip to content

Commit

Permalink
fix: formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vadson71 committed Apr 19, 2023
1 parent 639a6af commit 0d40827
Show file tree
Hide file tree
Showing 43 changed files with 331 additions and 421 deletions.
2 changes: 1 addition & 1 deletion packages/context/test/cache-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cache } from "../src/cache";

describe("cache", () => {
it("show singleton instance", async () => {
cache.setApp("key01", ({} as unknown) as App);
cache.setApp("key01", {} as unknown as App);
// importing again - no new instance is generated
const cacheModule = await import("../src/cache");
expect(cache.getAppEntries()).to.deep.equal(
Expand Down
34 changes: 9 additions & 25 deletions packages/context/test/loader-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ describe("loader", () => {
context("getApp", () => {
it("get an app", async () => {
const projectRoot = testFramework.getProjectRoot();
const {
appRoot,
manifest,
manifestDetails,
projectInfo,
} = await getProjectData(projectRoot);
const { appRoot, manifest, manifestDetails, projectInfo } =
await getProjectData(projectRoot);
// for consistency remove cache
cache.deleteApp(appRoot);
const app = await loader.getApp(
Expand Down Expand Up @@ -105,12 +101,8 @@ describe("loader", () => {

it("get cached app", async () => {
const projectRoot = testFramework.getProjectRoot();
const {
appRoot,
manifest,
manifestDetails,
projectInfo,
} = await getProjectData(projectRoot);
const { appRoot, manifest, manifestDetails, projectInfo } =
await getProjectData(projectRoot);
const getAppSpy = spy(cache, "getApp");
const app = await loader.getApp(
projectRoot,
Expand Down Expand Up @@ -144,12 +136,8 @@ describe("loader", () => {
undefined
);
const projectRoot = testFramework.getProjectRoot();
const {
appRoot,
manifestDetails,
manifest,
projectInfo,
} = await getProjectData(projectRoot);
const { appRoot, manifestDetails, manifest, projectInfo } =
await getProjectData(projectRoot);
// for consistency remove cache
cache.deleteApp(appRoot);
const app = await getApp(
Expand Down Expand Up @@ -184,12 +172,8 @@ describe("loader", () => {
});
it("return CAP project for NodeJS", async () => {
const projectRoot = testFramework.getProjectRoot();
const {
appRoot,
manifest,
manifestDetails,
projectInfo,
} = await getProjectData(projectRoot);
const { appRoot, manifest, manifestDetails, projectInfo } =
await getProjectData(projectRoot);
const capProject = await loader.getCAPProject(
projectRoot,
projectInfo,
Expand Down Expand Up @@ -287,7 +271,7 @@ describe("loader", () => {
"stub-manifest-path"
);
const getUI5ManifestStub = stub(manifest, "getUI5Manifest").resolves(
("stub-get-manifest" as unknown) as Manifest
"stub-get-manifest" as unknown as Manifest
);
const getProjectInfoStub = stub(projectUtils, "getProjectInfo").resolves(
undefined
Expand Down
5 changes: 3 additions & 2 deletions packages/fe/src/services/completion/providers/filter-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ function collectFilterBarElements(
for (const child of element.subElements) {
const ui5Class = getUI5ClassByXMLElement(child, model);
if (ui5Class?.name === "FilterBar" && ui5Class.library === SAP_FE_MACROS) {
const id = child.attributes.find((attribute) => attribute.key === "id")
?.value;
const id = child.attributes.find(
(attribute) => attribute.key === "id"
)?.value;
if (id) {
ids.push(id);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/fe/src/services/completion/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const attributeValueProviders: AttributeValueCompletion<
filterBarAttributeSuggestions,
];

export type UI5AttributeValueCompletionOptions = AttributeValueCompletionOptions<Context>;
export type UI5AttributeValueCompletionOptions =
AttributeValueCompletionOptions<Context>;
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ export function validateUnknownAnnotationTarget(
}

const normalizedValue = normalizePath(actualAttributeValue);
const expectedTypesList = (isNotRecommended
? expectedTypesMetaPath
: expectedTypes
const expectedTypesList = (
isNotRecommended ? expectedTypesMetaPath : expectedTypes
)
.map((item) => TypeNameMap[item])
.join(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ function collectFilterBarElements(
for (const child of element.subElements) {
const ui5Class = getUI5ClassByXMLElement(child, model);
if (ui5Class?.name === "FilterBar" && ui5Class.library === SAP_FE_MACROS) {
const id = child.attributes.find((attribute) => attribute.key === "id")
?.value;
const id = child.attributes.find(
(attribute) => attribute.key === "id"
)?.value;
if (id) {
ids.push(id);
}
Expand Down
15 changes: 5 additions & 10 deletions packages/fe/src/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,11 @@ export function getRootElements(
allowedTargets: AllowedTargetType[],
isPropertyPath: boolean
): (EntityContainer | EntitySet | EntityType | Singleton)[] {
const isEntityContainerAllowed = ([
"EntitySet",
"Singleton",
] as AllowedTargetType[]).some((type) => allowedTargets.includes(type));
let result: (
| EntityContainer
| EntitySet
| EntityType
| Singleton
)[] = isEntityContainerAllowed ? [metadata.entityContainer] : [];
const isEntityContainerAllowed = (
["EntitySet", "Singleton"] as AllowedTargetType[]
).some((type) => allowedTargets.includes(type));
let result: (EntityContainer | EntitySet | EntityType | Singleton)[] =
isEntityContainerAllowed ? [metadata.entityContainer] : [];
result.push(
...(allowedTargets.includes("EntitySet") ? metadata.entitySets : [])
);
Expand Down
48 changes: 23 additions & 25 deletions packages/fe/src/utils/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,32 +142,30 @@ const stringTermsToAnnotationTerms = (termNames: string[] | undefined) =>
return fullyQualifiedNameToTerm(fullyQualifiedName);
});

export const specification: Record<
string,
BuildingBlockPathConstraints
> = specs.reduce(
(acc: { [name: string]: BuildingBlockPathConstraints }, spec) => {
acc[spec.name] = {
name: spec.name,
constraints: {
metaPath: {
allowedTargets: spec.metaPath.allowedTargets,
allowedAnnotations: stringTermsToAnnotationTerms(
spec.metaPath.allowedAnnotations
),
export const specification: Record<string, BuildingBlockPathConstraints> =
specs.reduce(
(acc: { [name: string]: BuildingBlockPathConstraints }, spec) => {
acc[spec.name] = {
name: spec.name,
constraints: {
metaPath: {
allowedTargets: spec.metaPath.allowedTargets,
allowedAnnotations: stringTermsToAnnotationTerms(
spec.metaPath.allowedAnnotations
),
},
contextPath: {
allowedTargets: spec.contextPath?.allowedTargets || [],
allowedAnnotations: stringTermsToAnnotationTerms(
spec.contextPath?.allowedAnnotations
),
},
},
contextPath: {
allowedTargets: spec.contextPath?.allowedTargets || [],
allowedAnnotations: stringTermsToAnnotationTerms(
spec.contextPath?.allowedAnnotations
),
},
},
};
return acc;
},
{}
);
};
return acc;
},
{}
);

export function fullyQualifiedNameToTerm(
fullyQualifiedName: string
Expand Down
172 changes: 88 additions & 84 deletions packages/fe/test/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,56 @@ export type ViewCompletionProviderType = (
contextAdapter?: (context: Context) => Context
) => Promise<CompletionItem[]>;

export const getViewCompletionProvider = (
framework: TestFramework,
viewFilePathSegments: string[],
documentPath: string,
uri: string,
settings: Settings
): ViewCompletionProviderType => async (
snippet: string,
that: { timeout: (t: number) => void },
contextAdapter?: (context: Context) => Context
): Promise<CompletionItem[]> => {
const timeout = 60000;
that.timeout(timeout);
let result: CompletionItem[] = [];
try {
const { offset } = await framework.updateFileContent(
viewFilePathSegments,
snippet,
{ insertAfter: "<content>" }
);
const { ast, cst, tokenVector, content } = await framework.readFile(
viewFilePathSegments
);
const { document, textDocumentPosition } = framework.toVscodeTextDocument(
uri,
content,
offset
);
const context = (await getContext(documentPath)) as Context;
export const getViewCompletionProvider =
(
framework: TestFramework,
viewFilePathSegments: string[],
documentPath: string,
uri: string,
settings: Settings
): ViewCompletionProviderType =>
async (
snippet: string,
that: { timeout: (t: number) => void },
contextAdapter?: (context: Context) => Context
): Promise<CompletionItem[]> => {
const timeout = 60000;
that.timeout(timeout);
let result: CompletionItem[] = [];
try {
const { offset } = await framework.updateFileContent(
viewFilePathSegments,
snippet,
{ insertAfter: "<content>" }
);
const { ast, cst, tokenVector, content } = await framework.readFile(
viewFilePathSegments
);
const { document, textDocumentPosition } = framework.toVscodeTextDocument(
uri,
content,
offset
);
const context = (await getContext(documentPath)) as Context;

result = getCompletionItems({
ast,
context: contextAdapter ? contextAdapter(context) : context,
cst,
document,
documentSettings: settings,
textDocumentPosition,
tokenVector,
});
} finally {
// reversal update
await framework.updateFileContent(viewFilePathSegments, "", {
doUpdatesAfter: "<content>",
replaceText: snippet.replace(CURSOR_ANCHOR, ""),
});
}
return result;
};
result = getCompletionItems({
ast,
context: contextAdapter ? contextAdapter(context) : context,
cst,
document,
documentSettings: settings,
textDocumentPosition,
tokenVector,
});
} finally {
// reversal update
await framework.updateFileContent(viewFilePathSegments, "", {
doUpdatesAfter: "<content>",
replaceText: snippet.replace(CURSOR_ANCHOR, ""),
});
}
return result;
};

type AttributeValidator = (
attribute: XMLAttribute,
Expand All @@ -85,43 +87,45 @@ export type ViewValidatorType = (
contextAdapter?: (context: Context) => Context
) => Promise<AnnotationIssue[]>;

export const getViewValidator = (
framework: TestFramework,
viewFilePathSegments: string[],
documentPath: string,
validator: AttributeValidator
): ViewValidatorType => async (
snippet: string,
that: { timeout: (t: number) => void },
contextAdapter?: (context: Context) => Context
): Promise<AnnotationIssue[]> => {
const timeout = 60000;
that.timeout(timeout);
let result: AnnotationIssue[] = [];
try {
await framework.updateFileContent(viewFilePathSegments, snippet, {
insertAfter: "<content>",
});
const { ast } = await framework.readFile(viewFilePathSegments);
const context = (await getContext(documentPath)) as Context;
result = validateXMLView({
validators: {
attribute: [validator],
document: [],
element: [],
},
context: contextAdapter ? contextAdapter(context) : context,
xmlView: ast,
}) as AnnotationIssue[];
} finally {
// reversal update
await framework.updateFileContent(viewFilePathSegments, "", {
doUpdatesAfter: "<content>",
replaceText: snippet.replace(CURSOR_ANCHOR, ""),
});
}
return result;
};
export const getViewValidator =
(
framework: TestFramework,
viewFilePathSegments: string[],
documentPath: string,
validator: AttributeValidator
): ViewValidatorType =>
async (
snippet: string,
that: { timeout: (t: number) => void },
contextAdapter?: (context: Context) => Context
): Promise<AnnotationIssue[]> => {
const timeout = 60000;
that.timeout(timeout);
let result: AnnotationIssue[] = [];
try {
await framework.updateFileContent(viewFilePathSegments, snippet, {
insertAfter: "<content>",
});
const { ast } = await framework.readFile(viewFilePathSegments);
const context = (await getContext(documentPath)) as Context;
result = validateXMLView({
validators: {
attribute: [validator],
document: [],
element: [],
},
context: contextAdapter ? contextAdapter(context) : context,
xmlView: ast,
}) as AnnotationIssue[];
} finally {
// reversal update
await framework.updateFileContent(viewFilePathSegments, "", {
doUpdatesAfter: "<content>",
replaceText: snippet.replace(CURSOR_ANCHOR, ""),
});
}
return result;
};

export const prepareContextAdapter: (
contextPath: string | undefined
Expand Down
Loading

0 comments on commit 0d40827

Please sign in to comment.