Skip to content

Commit 222a0f5

Browse files
authored
fix: contextpath completion off, version template (#674)
1 parent 28a029d commit 222a0f5

File tree

6 files changed

+71
-11
lines changed

6 files changed

+71
-11
lines changed

.changeset/curly-beers-compete.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@ui5-language-assistant/context": patch
3+
"@ui5-language-assistant/fe": patch
4+
"vscode-ui5-language-assistant": patch
5+
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
6+
---
7+
8+
Code completion for context path is disabled, S/4 version placeholder in manifest's minUI5Version property defaults to the latest available version

packages/context/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { FetchResponse } from "@ui5-language-assistant/logic-utils";
88

99
export const DEFAULT_UI5_FRAMEWORK = "SAPUI5";
1010
export const DEFAULT_UI5_VERSION = "1.71.49";
11+
export const UI5_VERSION_S4_PLACEHOLDER = "${sap.ui5.dist.version}";
1112
export const UI5_FRAMEWORK_CDN_BASE_URL = {
1213
OpenUI5: "https://sdk.openui5.org/",
1314
SAPUI5: "https://ui5.sap.com/",

packages/context/src/ui5-model.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Json,
1313
TypeNameFix,
1414
} from "@ui5-language-assistant/semantic-model";
15-
import { Fetcher } from "./types";
15+
import { Fetcher, UI5_VERSION_S4_PLACEHOLDER } from "./types";
1616
import { fetch } from "@ui5-language-assistant/logic-utils";
1717
import {
1818
getLibraryAPIJsonUrl,
@@ -262,12 +262,16 @@ async function getVersionInfo(
262262
let versionInfo = await readFromCache(cacheFilePath);
263263
if (versionInfo === undefined) {
264264
const url = await getVersionInfoUrl(framework, version);
265-
const response = await fetcher(url);
266-
if (response.ok) {
267-
versionInfo = await response.json();
268-
writeToCache(cacheFilePath, versionInfo);
269-
} else {
270-
getLogger().error("Could not read version information", {
265+
try {
266+
const response = await fetcher(url);
267+
if (response.ok) {
268+
versionInfo = await response.json();
269+
writeToCache(cacheFilePath, versionInfo);
270+
} else {
271+
throw new Error(`Version info request has failed (${url})`);
272+
}
273+
} catch (e) {
274+
getLogger().error("Could not read version information. " + e, {
271275
url,
272276
});
273277
}
@@ -361,11 +365,18 @@ export async function negotiateVersionWithFetcher(
361365
// try to negotiate version
362366
let isFallback = false;
363367
let isIncorrectVersion = false;
368+
let useLatestVersion = false;
364369
let versions = versionMap[framework];
365370

366371
let adjustedVersion: string = version || DEFAULT_UI5_VERSION;
367372

368-
if (version && !isVersionSupported(version)) {
373+
if (version === UI5_VERSION_S4_PLACEHOLDER) {
374+
useLatestVersion = true;
375+
adjustedVersion = version;
376+
getLogger().warn(
377+
`The version specified as minUI5Version in your manifest.json is not supported by Language Assistant, the latest available version is used instead`
378+
);
379+
} else if (version && !isVersionSupported(version)) {
369380
// version is out of support in LA, using default version
370381
getLogger().warn(
371382
`The version specified as minUI5Version in your manifest.json is not supported by Language Assistant, the fallback version ${DEFAULT_UI5_VERSION} is used instead`
@@ -388,6 +399,7 @@ export async function negotiateVersionWithFetcher(
388399
isIncorrectVersion = true;
389400
}
390401
} else if (
402+
useLatestVersion ||
391403
!(await getVersionInfo(
392404
versionInfoJsonFetcher,
393405
modelCachePath,
@@ -427,7 +439,7 @@ export async function negotiateVersionWithFetcher(
427439
}
428440
// coerce the version (check for invalid version, which indicates development scenario)
429441
const parsedVersion = semver.coerce(adjustedVersion);
430-
if (parsedVersion) {
442+
if (!useLatestVersion && parsedVersion) {
431443
if (versions[`${parsedVersion.major}.${parsedVersion.minor}`]) {
432444
// lookup for a valid major.minor entry
433445
adjustedVersion =
@@ -453,7 +465,7 @@ export async function negotiateVersionWithFetcher(
453465
isIncorrectVersion = true;
454466
}
455467
} else {
456-
// development scenario => use latest version
468+
// development scenario or version placeholder in manifest found => use latest version
457469
adjustedVersion = versions["latest"].version;
458470
isIncorrectVersion = true;
459471
}

packages/context/test/unit/ui5-model.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe("the UI5 language assistant ui5 model", () => {
4242
const FRAMEWORK = "SAPUI5";
4343
const OPEN_FRAMEWORK = "OpenUI5";
4444
const VERSION = "1.71.49";
45+
const UI5_VERSION_S4_PLACEHOLDER = "${sap.ui5.dist.version}";
4546
const NO_CACHE_FOLDER = undefined;
4647

4748
function assertSemanticModel(ui5Model: UI5SemanticModel): void {
@@ -623,5 +624,22 @@ describe("the UI5 language assistant ui5 model", () => {
623624
expect(objNegotiatedVersionWithFetcher.isFallback).toBeFalse();
624625
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
625626
});
627+
628+
it("resolve unsupported version placeholder - S/4 generator artifact (should be latest)", async () => {
629+
const objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher(
630+
async (): Promise<FetchResponse> => {
631+
return createResponse(true, 200, versionMap[OPEN_FRAMEWORK]);
632+
},
633+
async (): Promise<FetchResponse> => {
634+
return createResponse(false, 404);
635+
},
636+
cachePath,
637+
FRAMEWORK,
638+
UI5_VERSION_S4_PLACEHOLDER
639+
);
640+
expect(objNegotiatedVersionWithFetcher.version).toEqual("1.105.0");
641+
expect(objNegotiatedVersionWithFetcher.isFallback).toBeFalse();
642+
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
643+
});
626644
});
627645
});

packages/fe/src/services/completion/providers/context-path.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ export function contextPathSuggestions({
4747
context.ui5Model
4848
);
4949

50+
// provider is blocked and is used in tests only
51+
// reserved for the future to be reused in binding expressions
52+
if (!(context as unknown as { forTest: boolean }).forTest) {
53+
return [];
54+
}
55+
5056
if (
5157
ui5Property?.library === SAP_FE_MACROS &&
5258
ui5Property.name === "contextPath"

packages/fe/test/unit/services/completion/providers/context-path.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,28 @@ describe("contextPath attribute value completion", () => {
8181
annoFileSegmentsCDS,
8282
annotationSnippetCDS
8383
);
84-
getCompletionResult = getViewCompletionProvider(
84+
85+
const provider = getViewCompletionProvider(
8586
framework,
8687
viewFilePathSegments,
8788
documentPath,
8889
uri,
8990
settings
9091
);
92+
93+
getCompletionResult = (
94+
snippet: string,
95+
contextAdapter?: (context: Context) => Context
96+
) => {
97+
const testAdapter = (context: Context) => {
98+
const result: Context = contextAdapter
99+
? contextAdapter(context)
100+
: context;
101+
return { ...result, forTest: true } as Context;
102+
};
103+
104+
return provider(snippet, testAdapter);
105+
};
91106
}, 5 * 60000);
92107

93108
describe("contextPath completion", () => {

0 commit comments

Comments
 (0)